mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-25 03:34:22 +01:00
switch back to didUpdate instead of closing and opening file
This commit is contained in:
@@ -2,6 +2,7 @@ import { LSP } from "../../../lsp"
|
|||||||
import { bootstrap } from "../../bootstrap"
|
import { bootstrap } from "../../bootstrap"
|
||||||
import { cmd } from "../cmd"
|
import { cmd } from "../cmd"
|
||||||
import { Log } from "../../../util/log"
|
import { Log } from "../../../util/log"
|
||||||
|
import { appendFile } from "fs/promises"
|
||||||
|
|
||||||
export const LSPCommand = cmd({
|
export const LSPCommand = cmd({
|
||||||
command: "lsp",
|
command: "lsp",
|
||||||
@@ -17,6 +18,9 @@ const DiagnosticsCommand = cmd({
|
|||||||
await bootstrap({ cwd: process.cwd() }, async () => {
|
await bootstrap({ cwd: process.cwd() }, async () => {
|
||||||
await LSP.touchFile(args.file, true)
|
await LSP.touchFile(args.file, true)
|
||||||
console.log(await LSP.diagnostics())
|
console.log(await LSP.diagnostics())
|
||||||
|
await appendFile(args.file, `\nconst x: number = "foo"`)
|
||||||
|
await LSP.touchFile(args.file, true)
|
||||||
|
console.log(await LSP.diagnostics())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -126,19 +126,26 @@ export namespace LSPClient {
|
|||||||
input.path = path.isAbsolute(input.path) ? input.path : path.resolve(app.path.cwd, input.path)
|
input.path = path.isAbsolute(input.path) ? input.path : path.resolve(app.path.cwd, input.path)
|
||||||
const file = Bun.file(input.path)
|
const file = Bun.file(input.path)
|
||||||
const text = await file.text()
|
const text = await file.text()
|
||||||
const version = files[input.path]
|
|
||||||
if (version !== undefined) {
|
|
||||||
diagnostics.delete(input.path)
|
|
||||||
await connection.sendNotification("textDocument/didClose", {
|
|
||||||
textDocument: {
|
|
||||||
uri: `file://` + input.path,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
log.info("textDocument/didOpen", input)
|
|
||||||
diagnostics.delete(input.path)
|
|
||||||
const extension = path.extname(input.path)
|
const extension = path.extname(input.path)
|
||||||
const languageId = LANGUAGE_EXTENSIONS[extension] ?? "plaintext"
|
const languageId = LANGUAGE_EXTENSIONS[extension] ?? "plaintext"
|
||||||
|
|
||||||
|
const version = files[input.path]
|
||||||
|
if (version !== undefined) {
|
||||||
|
const next = version + 1
|
||||||
|
files[input.path] = next
|
||||||
|
log.info("textDocument/didChange", { path: input.path, version: next })
|
||||||
|
await connection.sendNotification("textDocument/didChange", {
|
||||||
|
textDocument: {
|
||||||
|
uri: `file://` + input.path,
|
||||||
|
version: next,
|
||||||
|
},
|
||||||
|
contentChanges: [{ text }],
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("textDocument/didOpen", input)
|
||||||
|
diagnostics.delete(input.path)
|
||||||
await connection.sendNotification("textDocument/didOpen", {
|
await connection.sendNotification("textDocument/didOpen", {
|
||||||
textDocument: {
|
textDocument: {
|
||||||
uri: `file://` + input.path,
|
uri: `file://` + input.path,
|
||||||
|
|||||||
Reference in New Issue
Block a user