Skip to content

Commit f03fae0

Browse files
committed
switch back to didUpdate instead of closing and opening file
1 parent bb14a95 commit f03fae0

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎packages/opencode/src/cli/cmd/debug/lsp.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LSP } from "../../../lsp"
22
import { bootstrap } from "../../bootstrap"
33
import { cmd } from "../cmd"
44
import { Log } from "../../../util/log"
5+
import { appendFile } from "fs/promises"
56

67
export const LSPCommand = cmd({
78
command: "lsp",
@@ -17,6 +18,9 @@ const DiagnosticsCommand = cmd({
1718
await bootstrap({ cwd: process.cwd() }, async () => {
1819
await LSP.touchFile(args.file, true)
1920
console.log(await LSP.diagnostics())
21+
await appendFile(args.file, `\nconst x: number = "foo"`)
22+
await LSP.touchFile(args.file, true)
23+
console.log(await LSP.diagnostics())
2024
})
2125
},
2226
})

‎packages/opencode/src/lsp/client.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,26 @@ export namespace LSPClient {
126126
input.path = path.isAbsolute(input.path) ? input.path : path.resolve(app.path.cwd, input.path)
127127
const file = Bun.file(input.path)
128128
const text = await file.text()
129+
const extension = path.extname(input.path)
130+
const languageId = LANGUAGE_EXTENSIONS[extension] ?? "plaintext"
131+
129132
const version = files[input.path]
130133
if (version !== undefined) {
131-
diagnostics.delete(input.path)
132-
await connection.sendNotification("textDocument/didClose", {
134+
const next = version + 1
135+
files[input.path] = next
136+
log.info("textDocument/didChange", { path: input.path, version: next })
137+
await connection.sendNotification("textDocument/didChange", {
133138
textDocument: {
134139
uri: `file://` + input.path,
140+
version: next,
135141
},
142+
contentChanges: [{ text }],
136143
})
144+
return
137145
}
146+
138147
log.info("textDocument/didOpen", input)
139148
diagnostics.delete(input.path)
140-
const extension = path.extname(input.path)
141-
const languageId = LANGUAGE_EXTENSIONS[extension] ?? "plaintext"
142149
await connection.sendNotification("textDocument/didOpen", {
143150
textDocument: {
144151
uri: `file://` + input.path,

0 commit comments

Comments
 (0)