optimistically boot lsp servers

This commit is contained in:
Dax Raad
2025-06-30 16:45:13 -04:00
parent c573270e66
commit 9ad1687f04
4 changed files with 85 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import { App } from "../app/app"
import { ConfigHooks } from "../config/hooks"
import { Format } from "../format"
import { LSP } from "../lsp"
import { Share } from "../share/share"
export async function bootstrap<T>(
@@ -11,6 +12,7 @@ export async function bootstrap<T>(
Share.init()
Format.init()
ConfigHooks.init()
LSP.init()
return cb(app)
})

View File

@@ -1,12 +1,18 @@
import { App } from "../../app/app"
import { Ripgrep } from "../../file/ripgrep"
import { LSP } from "../../lsp"
import { bootstrap } from "../bootstrap"
import { cmd } from "./cmd"
export const DebugCommand = cmd({
command: "debug",
builder: (yargs) =>
yargs.command(DiagnosticsCommand).command(TreeCommand).demandCommand(),
yargs
.command(DiagnosticsCommand)
.command(TreeCommand)
.command(SymbolsCommand)
.command(FilesCommand)
.demandCommand(),
async handler() {},
})
@@ -15,7 +21,7 @@ const DiagnosticsCommand = cmd({
builder: (yargs) =>
yargs.positional("file", { type: "string", demandOption: true }),
async handler(args) {
await App.provide({ cwd: process.cwd() }, async () => {
await bootstrap({ cwd: process.cwd() }, async () => {
await LSP.touchFile(args.file, true)
console.log(await LSP.diagnostics())
})
@@ -29,9 +35,53 @@ const TreeCommand = cmd({
type: "number",
}),
async handler(args) {
await App.provide({ cwd: process.cwd() }, async () => {
await bootstrap({ cwd: process.cwd() }, async () => {
const app = App.info()
console.log(await Ripgrep.tree({ cwd: app.path.cwd, limit: args.limit }))
})
},
})
const SymbolsCommand = cmd({
command: "symbols <query>",
builder: (yargs) =>
yargs.positional("query", { type: "string", demandOption: true }),
async handler(args) {
await bootstrap({ cwd: process.cwd() }, async () => {
await LSP.touchFile("./src/index.ts", true)
await new Promise((resolve) => setTimeout(resolve, 3000))
const results = await LSP.workspaceSymbol(args.query)
console.log(JSON.stringify(results, null, 2))
})
},
})
const FilesCommand = cmd({
command: "files",
builder: (yargs) =>
yargs
.option("query", {
type: "string",
description: "Filter files by query",
})
.option("glob", {
type: "string",
description: "Glob pattern to match files",
})
.option("limit", {
type: "number",
description: "Limit number of results",
}),
async handler(args) {
await bootstrap({ cwd: process.cwd() }, async () => {
const app = App.info()
const files = await Ripgrep.files({
cwd: app.path.cwd,
query: args.query,
glob: args.glob,
limit: args.limit,
})
console.log(files.join("\n"))
})
},
})