summaryrefslogtreecommitdiffhomepage
path: root/js/src/tool
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/tool
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/tool')
-rw-r--r--js/src/tool/index.ts3
-rw-r--r--js/src/tool/lsp-diagnostics.ts (renamed from js/src/tool/diagnostics.ts)2
-rw-r--r--js/src/tool/lsp-hover.ts38
3 files changed, 41 insertions, 2 deletions
diff --git a/js/src/tool/index.ts b/js/src/tool/index.ts
index b18f85012..3930c87c4 100644
--- a/js/src/tool/index.ts
+++ b/js/src/tool/index.ts
@@ -5,4 +5,5 @@ export * from "./glob";
export * from "./grep";
export * from "./view";
export * from "./ls";
-export * from "./diagnostics";
+export * from "./lsp-diagnostics";
+export * from "./lsp-hover";
diff --git a/js/src/tool/diagnostics.ts b/js/src/tool/lsp-diagnostics.ts
index 3610c7781..41c33f822 100644
--- a/js/src/tool/diagnostics.ts
+++ b/js/src/tool/lsp-diagnostics.ts
@@ -4,7 +4,7 @@ import path from "node:path";
import { LSP } from "../lsp";
import { App } from "../app";
-export const DiagnosticsTool = Tool.define({
+export const LspDiagnosticTool = Tool.define({
name: "diagnostics",
description: `Get diagnostics for a file and/or project.
diff --git a/js/src/tool/lsp-hover.ts b/js/src/tool/lsp-hover.ts
new file mode 100644
index 000000000..9957920a2
--- /dev/null
+++ b/js/src/tool/lsp-hover.ts
@@ -0,0 +1,38 @@
+import { z } from "zod";
+import { Tool } from "./tool";
+import path from "node:path";
+import { LSP } from "../lsp";
+import { App } from "../app";
+
+export const LspHoverTool = Tool.define({
+ name: "lsp.hover",
+ description: `
+ Looks up hover information for a given position in a source file using the Language Server Protocol (LSP).
+ This includes type information, documentation, or symbol details at the specified line and character.
+ Useful for providing code insights, explanations, or context-aware assistance based on the user's current cursor location.
+ `,
+ parameters: z.object({
+ file: z.string().describe("The path to the file to get diagnostics."),
+ line: z.number().describe("The line number to get diagnostics."),
+ character: z.number().describe("The character number to get diagnostics."),
+ }),
+ execute: async (args) => {
+ console.log(args);
+ const app = await App.use();
+ const file = path.isAbsolute(args.file)
+ ? args.file
+ : path.join(app.root, args.file);
+ await LSP.file(file);
+ const result = await LSP.hover({
+ ...args,
+ file,
+ });
+ console.log(result);
+ return {
+ metadata: {
+ result,
+ },
+ output: JSON.stringify(result, null, 2),
+ };
+ },
+});