lsp-hover.ts 986 B

1234567891011121314151617181920212223242526272829303132
  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("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 app = App.info()
  16. const file = path.isAbsolute(args.file) ? args.file : path.join(app.path.cwd, args.file)
  17. await LSP.touchFile(file, true)
  18. const result = await LSP.hover({
  19. ...args,
  20. file,
  21. })
  22. return {
  23. title: path.relative(app.path.root, file) + ":" + args.line + ":" + args.character,
  24. metadata: {
  25. result,
  26. },
  27. output: JSON.stringify(result, null, 2),
  28. }
  29. },
  30. })