lsp-hover.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { z } from "zod"
  2. import { Tool } from "./tool"
  3. import path from "path"
  4. import { LSP } from "../lsp"
  5. import { App } from "../app/app"
  6. import DESCRIPTION from "./lsp-hover.txt"
  7. export const LspHoverTool = Tool.define({
  8. id: "lsp_hover",
  9. description: DESCRIPTION,
  10. parameters: z.object({
  11. file: z.string().describe("The path to the file to get diagnostics."),
  12. line: z.number().describe("The line number to get diagnostics."),
  13. character: z.number().describe("The character number to get diagnostics."),
  14. }),
  15. execute: async (args) => {
  16. const app = App.info()
  17. const file = path.isAbsolute(args.file)
  18. ? args.file
  19. : path.join(app.path.cwd, args.file)
  20. await LSP.touchFile(file, true)
  21. const result = await LSP.hover({
  22. ...args,
  23. file,
  24. })
  25. return {
  26. metadata: {
  27. result,
  28. title:
  29. path.relative(app.path.root, file) +
  30. ":" +
  31. args.line +
  32. ":" +
  33. args.character,
  34. },
  35. output: JSON.stringify(result, null, 2),
  36. }
  37. },
  38. })