@@ -6,7 +6,8 @@ import { Filesystem } from "@/util/filesystem"
66import type { EditorSelection } from "./editor"
77
88const ZedEditorRowSchema = z . object ( {
9- editor_id : z . number ( ) ,
9+ item_kind : z . string ( ) ,
10+ editor_id : z . number ( ) . nullable ( ) ,
1011 workspace_id : z . number ( ) ,
1112 workspace_paths : z . string ( ) . nullable ( ) ,
1213 timestamp : z . string ( ) ,
@@ -20,6 +21,7 @@ const ZedEditorContentsSchema = z.object({
2021} )
2122
2223type ZedEditorRow = z . infer < typeof ZedEditorRowSchema >
24+ type ZedActiveEditorRow = ZedEditorRow & { item_kind : "Editor" ; editor_id : number }
2325
2426export type ZedSelectionResult =
2527 | { type : "selection" ; selection : EditorSelection }
@@ -64,8 +66,9 @@ function queryZedActiveEditor(dbPath: string, cwd: string) {
6466 const raw = db
6567 . query (
6668 `select
69+ i.kind as item_kind,
6770 e.item_id as editor_id,
68- e .workspace_id as workspace_id,
71+ i .workspace_id as workspace_id,
6972 w.paths as workspace_paths,
7073 w.timestamp as timestamp,
7174 e.buffer_path as buffer_path,
@@ -74,9 +77,9 @@ function queryZedActiveEditor(dbPath: string, cwd: string) {
7477 from items i
7578 join panes p on p.pane_id = i.pane_id and p.workspace_id = i.workspace_id
7679 join workspaces w on w.workspace_id = i.workspace_id
77- join editors e on e.item_id = i.item_id and e.workspace_id = i.workspace_id
80+ left join editors e on e.item_id = i.item_id and e.workspace_id = i.workspace_id
7881 left join editor_selections s on s.editor_id = e.item_id and s.workspace_id = e.workspace_id
79- where i.active = 1 and p.active = 1 and i.kind = 'Editor' and e.buffer_path is not null
82+ where i.active = 1 and p.active = 1
8083 order by w.timestamp desc` ,
8184 )
8285 . all ( )
@@ -93,6 +96,8 @@ function queryZedActiveEditor(dbPath: string, cwd: string) {
9396 . filter ( ( entry ) => entry . score > 0 )
9497 . sort ( ( left , right ) => right . score - left . score || right . row . timestamp . localeCompare ( left . row . timestamp ) ) [ 0 ] ?. row
9598 if ( ! row ) return { type : "empty" as const }
99+ if ( row . item_kind !== "Editor" ) return { type : "unavailable" as const }
100+ if ( ! isZedActiveEditorRow ( row ) ) return { type : "empty" as const }
96101 return { type : "row" as const , row }
97102 } catch {
98103 return { type : "unavailable" as const }
@@ -101,7 +106,7 @@ function queryZedActiveEditor(dbPath: string, cwd: string) {
101106 }
102107}
103108
104- function queryZedEditorContents ( dbPath : string , row : ZedEditorRow ) {
109+ function queryZedEditorContents ( dbPath : string , row : ZedActiveEditorRow ) {
105110 let db : Database | undefined
106111 try {
107112 db = new Database ( dbPath , { readonly : true } )
@@ -123,6 +128,10 @@ function queryZedEditorContents(dbPath: string, row: ZedEditorRow) {
123128 }
124129}
125130
131+ function isZedActiveEditorRow ( row : ZedEditorRow ) : row is ZedActiveEditorRow {
132+ return row . item_kind === "Editor" && row . editor_id != null
133+ }
134+
126135export function resolveZedDbPath ( ) {
127136 const candidates = [
128137 process . env . OPENCODE_ZED_DB ,
0 commit comments