lsp.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { LSP } from "../../../lsp"
  2. import { bootstrap } from "../../bootstrap"
  3. import { cmd } from "../cmd"
  4. import { Log } from "../../../util/log"
  5. import { EOL } from "os"
  6. export const LSPCommand = cmd({
  7. command: "lsp",
  8. builder: (yargs) =>
  9. yargs.command(DiagnosticsCommand).command(SymbolsCommand).command(DocumentSymbolsCommand).demandCommand(),
  10. async handler() {},
  11. })
  12. const DiagnosticsCommand = cmd({
  13. command: "diagnostics <file>",
  14. builder: (yargs) => yargs.positional("file", { type: "string", demandOption: true }),
  15. async handler(args) {
  16. await bootstrap(process.cwd(), async () => {
  17. await LSP.touchFile(args.file, true)
  18. process.stdout.write(JSON.stringify(await LSP.diagnostics(), null, 2) + EOL)
  19. })
  20. },
  21. })
  22. export const SymbolsCommand = cmd({
  23. command: "symbols <query>",
  24. builder: (yargs) => yargs.positional("query", { type: "string", demandOption: true }),
  25. async handler(args) {
  26. await bootstrap(process.cwd(), async () => {
  27. using _ = Log.Default.time("symbols")
  28. const results = await LSP.workspaceSymbol(args.query)
  29. process.stdout.write(JSON.stringify(results, null, 2) + EOL)
  30. })
  31. },
  32. })
  33. export const DocumentSymbolsCommand = cmd({
  34. command: "document-symbols <uri>",
  35. builder: (yargs) => yargs.positional("uri", { type: "string", demandOption: true }),
  36. async handler(args) {
  37. await bootstrap(process.cwd(), async () => {
  38. using _ = Log.Default.time("document-symbols")
  39. const results = await LSP.documentSymbol(args.uri)
  40. process.stdout.write(JSON.stringify(results, null, 2) + EOL)
  41. })
  42. },
  43. })