lsp-hover.ts 982 B

12345678910111213141516171819202122232425262728293031
  1. import z from "zod/v4"
  2. import { Tool } from "./tool"
  3. import path from "path"
  4. import { LSP } from "../lsp"
  5. import DESCRIPTION from "./lsp-hover.txt"
  6. import { Instance } from "../project/instance"
  7. export const LspHoverTool = Tool.define("lsp_hover", {
  8. description: DESCRIPTION,
  9. parameters: z.object({
  10. file: z.string().describe("The path to the file to get diagnostics."),
  11. line: z.number().describe("The line number to get diagnostics."),
  12. character: z.number().describe("The character number to get diagnostics."),
  13. }),
  14. execute: async (args) => {
  15. const file = path.isAbsolute(args.file) ? args.file : path.join(Instance.directory, args.file)
  16. await LSP.touchFile(file, true)
  17. const result = await LSP.hover({
  18. ...args,
  19. file,
  20. })
  21. return {
  22. title: path.relative(Instance.worktree, file) + ":" + args.line + ":" + args.character,
  23. metadata: {
  24. result,
  25. },
  26. output: JSON.stringify(result, null, 2),
  27. }
  28. },
  29. })