summaryrefslogtreecommitdiffhomepage
path: root/js/src/lsp
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-27 02:17:35 -0400
committerDax Raad <[email protected]>2025-05-27 02:17:35 -0400
commitc040baae118787cd0573e5b674a2a225f36d898c (patch)
tree04c4ff3d08f1243e170397fed9f5a31b0ea082cc /js/src/lsp
parent754cc667411cc1d652acd0a811c530dcc35f5927 (diff)
downloadopencode-c040baae118787cd0573e5b674a2a225f36d898c.tar.gz
opencode-c040baae118787cd0573e5b674a2a225f36d898c.zip
Refactor LSP tools and add hover functionality
- Split diagnostics tool into separate lsp-diagnostics.ts file - Add new lsp-hover.ts tool for LSP hover information - Update tool exports and session integration - Remove old diagnostics.ts file 🤖 Generated with opencode Co-Authored-By: opencode <[email protected]>
Diffstat (limited to 'js/src/lsp')
-rw-r--r--js/src/lsp/client.ts7
-rw-r--r--js/src/lsp/index.ts18
2 files changed, 22 insertions, 3 deletions
diff --git a/js/src/lsp/client.ts b/js/src/lsp/client.ts
index e8e7d694e..1de187a94 100644
--- a/js/src/lsp/client.ts
+++ b/js/src/lsp/client.ts
@@ -144,7 +144,7 @@ export namespace LSPClient {
textDocument: {
uri: `file://` + input.path,
languageId,
- version: ++version,
+ version: Date.now(),
text,
},
});
@@ -157,7 +157,7 @@ export namespace LSPClient {
await connection.sendNotification("textDocument/didChange", {
textDocument: {
uri: `file://` + input.path,
- version: ++version,
+ version: Date.now(),
},
contentChanges: [
{
@@ -181,7 +181,7 @@ export namespace LSPClient {
event.properties.path === input.path &&
event.properties.serverID === result.clientID
) {
- log.info("refreshed diagnostics", input);
+ log.info("got diagnostics", input);
clearTimeout(timeout);
unsub?.();
resolve();
@@ -190,6 +190,7 @@ export namespace LSPClient {
}),
new Promise<void>((resolve) => {
timeout = setTimeout(() => {
+ log.info("timed out refreshing diagnostics", input);
unsub?.();
resolve();
}, 5000);
diff --git a/js/src/lsp/index.ts b/js/src/lsp/index.ts
index f9d48e7bf..2294d439f 100644
--- a/js/src/lsp/index.ts
+++ b/js/src/lsp/index.ts
@@ -54,6 +54,24 @@ export namespace LSP {
return results;
}
+ export async function hover(input: {
+ file: string;
+ line: number;
+ character: number;
+ }) {
+ return run((client) => {
+ return client.connection.sendRequest("textDocument/hover", {
+ textDocument: {
+ uri: `file://${input.file}`,
+ },
+ position: {
+ line: input.line,
+ character: input.character,
+ },
+ });
+ });
+ }
+
async function run<T>(
input: (client: LSPClient.Info) => Promise<T>,
): Promise<T[]> {