lsp-diagnostics.ts 943 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-diagnostics.txt"
  7. export const LspDiagnosticTool = Tool.define({
  8. id: "opencode.lsp_diagnostics",
  9. description: DESCRIPTION,
  10. parameters: z.object({
  11. path: z.string().describe("The path to the file to get diagnostics."),
  12. }),
  13. execute: async (args) => {
  14. const app = App.info()
  15. const normalized = path.isAbsolute(args.path)
  16. ? args.path
  17. : path.join(app.path.cwd, args.path)
  18. await LSP.touchFile(normalized, true)
  19. const diagnostics = await LSP.diagnostics()
  20. const file = diagnostics[normalized]
  21. return {
  22. metadata: {
  23. diagnostics,
  24. title: path.relative(app.path.root, normalized),
  25. },
  26. output: file?.length
  27. ? file.map(LSP.Diagnostic.pretty).join("\n")
  28. : "No errors found",
  29. }
  30. },
  31. })