lsp-diagnostics.ts 894 B

1234567891011121314151617181920212223242526
  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-diagnostics.txt"
  6. import { Instance } from "../project/instance"
  7. export const LspDiagnosticTool = Tool.define("lsp_diagnostics", {
  8. description: DESCRIPTION,
  9. parameters: z.object({
  10. path: z.string().describe("The path to the file to get diagnostics."),
  11. }),
  12. execute: async (args) => {
  13. const normalized = path.isAbsolute(args.path) ? args.path : path.join(Instance.directory, args.path)
  14. await LSP.touchFile(normalized, true)
  15. const diagnostics = await LSP.diagnostics()
  16. const file = diagnostics[normalized]
  17. return {
  18. title: path.relative(Instance.worktree, normalized),
  19. metadata: {
  20. diagnostics,
  21. },
  22. output: file?.length ? file.map(LSP.Diagnostic.pretty).join("\n") : "No errors found",
  23. }
  24. },
  25. })