mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-05 00:23:10 +00:00
make lsp better
This commit is contained in:
@@ -117,6 +117,7 @@ export namespace LSPClient {
|
||||
textDocument: {
|
||||
synchronization: {
|
||||
didOpen: true,
|
||||
didChange: true,
|
||||
},
|
||||
publishDiagnostics: {
|
||||
versionSupport: true,
|
||||
@@ -127,7 +128,9 @@ export namespace LSPClient {
|
||||
await connection.sendNotification("initialized", {})
|
||||
log.info("initialized")
|
||||
|
||||
const files = new Set<string>()
|
||||
const files: {
|
||||
[path: string]: number
|
||||
} = {}
|
||||
|
||||
const result = {
|
||||
get clientID() {
|
||||
@@ -143,8 +146,8 @@ export namespace LSPClient {
|
||||
: path.resolve(app.path.cwd, input.path)
|
||||
const file = Bun.file(input.path)
|
||||
const text = await file.text()
|
||||
const opened = files.has(input.path)
|
||||
if (!opened) {
|
||||
const version = files[input.path]
|
||||
if (version === undefined) {
|
||||
log.info("textDocument/didOpen", input)
|
||||
diagnostics.delete(input.path)
|
||||
const extension = path.extname(input.path)
|
||||
@@ -153,11 +156,11 @@ export namespace LSPClient {
|
||||
textDocument: {
|
||||
uri: `file://` + input.path,
|
||||
languageId,
|
||||
version: Date.now(),
|
||||
version: 0,
|
||||
text,
|
||||
},
|
||||
})
|
||||
files.add(input.path)
|
||||
files[input.path] = 0
|
||||
return
|
||||
}
|
||||
|
||||
@@ -166,7 +169,7 @@ export namespace LSPClient {
|
||||
await connection.sendNotification("textDocument/didChange", {
|
||||
textDocument: {
|
||||
uri: `file://` + input.path,
|
||||
version: Date.now(),
|
||||
version: ++files[input.path],
|
||||
},
|
||||
contentChanges: [
|
||||
{
|
||||
@@ -213,6 +216,7 @@ export namespace LSPClient {
|
||||
log.info("shutting down")
|
||||
connection.end()
|
||||
connection.dispose()
|
||||
server.kill()
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export namespace LSP {
|
||||
},
|
||||
)
|
||||
|
||||
export async function file(input: string) {
|
||||
export async function touchFile(input: string, waitForDiagnostics?: boolean) {
|
||||
const extension = path.parse(input).ext
|
||||
const s = await state()
|
||||
const matches = AUTO.filter((x) => x.extensions.includes(extension))
|
||||
@@ -40,11 +40,13 @@ export namespace LSP {
|
||||
})
|
||||
s.clients.set(match.id, client)
|
||||
}
|
||||
await run(async (client) => {
|
||||
const wait = client.waitForDiagnostics({ path: input })
|
||||
await client.notify.open({ path: input })
|
||||
return wait
|
||||
})
|
||||
if (waitForDiagnostics) {
|
||||
await run(async (client) => {
|
||||
const wait = client.waitForDiagnostics({ path: input })
|
||||
await client.notify.open({ path: input })
|
||||
return wait
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function diagnostics() {
|
||||
|
||||
Reference in New Issue
Block a user