TIL VS Code has a sqlite database of recents, so I built this!

Open open-recent-vs-code-project in Script Kit

// Name: Recent VS Code Project
// Cache: true
// Group: Favorite
// Keyword: vs
import "@johnlindquist/kit"
import { URL, fileURLToPath } from "url"
// /Users/johnlindquist/Library/Application Support/Code/User/globalStorage/state.vscdb
let filename = home("Library", "Application Support", "Code", "User", "globalStorage", "state.vscdb")
// windows path not tested, just guessing
if (isWin) filename = home("AppData", "Roaming", "Code", "User", "globalStorage", "state.vscdb")
let { default: sqlite3 } = await import("sqlite3")
let { open } = await import("sqlite")
let db = await open({
filename,
driver: sqlite3.Database,
})
let key = `history.recentlyOpenedPathsList`
let table = `ItemTable`
let result = await db.get(`SELECT * FROM ${table} WHERE key = '${key}'`)
let recentPaths = JSON.parse(result.value)
let recentFilePaths = []
for (let entry of recentPaths.entries) {
if (entry?.folderUri && entry.folderUri.startsWith("file://")) {
try {
let path = fileURLToPath(new URL(entry.folderUri))
recentFilePaths.push(path)
} catch (error) {
console.error(`Failed to parse ${entry.folderUri}. Error: ${error}`)
}
}
}
let recentPath = await arg("Open a recent path", recentFilePaths)
hide()
await exec(`code ${recentPath}`)