chad-code 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -6
- package/package.json +36 -98
- package/AGENTS.md +0 -27
- package/Dockerfile +0 -18
- package/README.npm.md +0 -64
- package/bunfig.toml +0 -7
- package/eslint.config.js +0 -29
- package/parsers-config.ts +0 -253
- package/script/build.ts +0 -167
- package/script/publish-registries.ts +0 -187
- package/script/publish.ts +0 -93
- package/script/schema.ts +0 -47
- package/src/acp/README.md +0 -164
- package/src/acp/agent.ts +0 -1086
- package/src/acp/session.ts +0 -101
- package/src/acp/types.ts +0 -22
- package/src/agent/agent.ts +0 -253
- package/src/agent/generate.txt +0 -75
- package/src/agent/prompt/compaction.txt +0 -12
- package/src/agent/prompt/explore.txt +0 -18
- package/src/agent/prompt/summary.txt +0 -11
- package/src/agent/prompt/title.txt +0 -36
- package/src/auth/index.ts +0 -70
- package/src/bun/index.ts +0 -130
- package/src/bus/bus-event.ts +0 -43
- package/src/bus/global.ts +0 -10
- package/src/bus/index.ts +0 -105
- package/src/cli/bootstrap.ts +0 -17
- package/src/cli/cmd/acp.ts +0 -69
- package/src/cli/cmd/agent.ts +0 -257
- package/src/cli/cmd/auth.ts +0 -132
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/debug/agent.ts +0 -28
- package/src/cli/cmd/debug/config.ts +0 -15
- package/src/cli/cmd/debug/file.ts +0 -91
- package/src/cli/cmd/debug/index.ts +0 -45
- package/src/cli/cmd/debug/lsp.ts +0 -48
- package/src/cli/cmd/debug/ripgrep.ts +0 -83
- package/src/cli/cmd/debug/scrap.ts +0 -15
- package/src/cli/cmd/debug/skill.ts +0 -15
- package/src/cli/cmd/debug/snapshot.ts +0 -48
- package/src/cli/cmd/export.ts +0 -88
- package/src/cli/cmd/generate.ts +0 -38
- package/src/cli/cmd/github.ts +0 -32
- package/src/cli/cmd/import.ts +0 -98
- package/src/cli/cmd/mcp.ts +0 -670
- package/src/cli/cmd/models.ts +0 -42
- package/src/cli/cmd/pr.ts +0 -112
- package/src/cli/cmd/run.ts +0 -374
- package/src/cli/cmd/serve.ts +0 -16
- package/src/cli/cmd/session.ts +0 -135
- package/src/cli/cmd/stats.ts +0 -402
- package/src/cli/cmd/tui/app.tsx +0 -705
- package/src/cli/cmd/tui/attach.ts +0 -32
- package/src/cli/cmd/tui/component/border.tsx +0 -21
- package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-command.tsx +0 -124
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +0 -232
- package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -228
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -115
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-status.tsx +0 -162
- package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
- package/src/cli/cmd/tui/component/did-you-know.tsx +0 -85
- package/src/cli/cmd/tui/component/logo.tsx +0 -43
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -654
- package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
- package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1078
- package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
- package/src/cli/cmd/tui/component/tips.ts +0 -92
- package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
- package/src/cli/cmd/tui/context/args.tsx +0 -14
- package/src/cli/cmd/tui/context/directory.ts +0 -13
- package/src/cli/cmd/tui/context/exit.tsx +0 -23
- package/src/cli/cmd/tui/context/helper.tsx +0 -25
- package/src/cli/cmd/tui/context/keybind.tsx +0 -101
- package/src/cli/cmd/tui/context/kv.tsx +0 -49
- package/src/cli/cmd/tui/context/local.tsx +0 -392
- package/src/cli/cmd/tui/context/prompt.tsx +0 -18
- package/src/cli/cmd/tui/context/route.tsx +0 -46
- package/src/cli/cmd/tui/context/sdk.tsx +0 -75
- package/src/cli/cmd/tui/context/sync.tsx +0 -384
- package/src/cli/cmd/tui/context/theme/aura.json +0 -69
- package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
- package/src/cli/cmd/tui/context/theme/chad.json +0 -245
- package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
- package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
- package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
- package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
- package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
- package/src/cli/cmd/tui/context/theme/github.json +0 -233
- package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
- package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -227
- package/src/cli/cmd/tui/context/theme/material.json +0 -235
- package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
- package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
- package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
- package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
- package/src/cli/cmd/tui/context/theme/nord.json +0 -223
- package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
- package/src/cli/cmd/tui/context/theme/orng.json +0 -245
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
- package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
- package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
- package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
- package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
- package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
- package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
- package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
- package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
- package/src/cli/cmd/tui/context/theme.tsx +0 -1137
- package/src/cli/cmd/tui/event.ts +0 -46
- package/src/cli/cmd/tui/routes/home.tsx +0 -138
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
- package/src/cli/cmd/tui/routes/session/footer.tsx +0 -88
- package/src/cli/cmd/tui/routes/session/header.tsx +0 -125
- package/src/cli/cmd/tui/routes/session/index.tsx +0 -1814
- package/src/cli/cmd/tui/routes/session/permission.tsx +0 -416
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -318
- package/src/cli/cmd/tui/spawn.ts +0 -48
- package/src/cli/cmd/tui/thread.ts +0 -111
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
- package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
- package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -345
- package/src/cli/cmd/tui/ui/dialog.tsx +0 -171
- package/src/cli/cmd/tui/ui/link.tsx +0 -28
- package/src/cli/cmd/tui/ui/spinner.ts +0 -368
- package/src/cli/cmd/tui/ui/toast.tsx +0 -100
- package/src/cli/cmd/tui/util/clipboard.ts +0 -127
- package/src/cli/cmd/tui/util/editor.ts +0 -32
- package/src/cli/cmd/tui/util/signal.ts +0 -7
- package/src/cli/cmd/tui/util/terminal.ts +0 -114
- package/src/cli/cmd/tui/util/transcript.ts +0 -98
- package/src/cli/cmd/tui/worker.ts +0 -68
- package/src/cli/cmd/uninstall.ts +0 -344
- package/src/cli/cmd/upgrade.ts +0 -67
- package/src/cli/cmd/web.ts +0 -73
- package/src/cli/error.ts +0 -56
- package/src/cli/network.ts +0 -53
- package/src/cli/ui.ts +0 -87
- package/src/cli/upgrade.ts +0 -25
- package/src/command/index.ts +0 -131
- package/src/command/template/initialize.txt +0 -10
- package/src/command/template/review.txt +0 -97
- package/src/config/config.ts +0 -1124
- package/src/config/markdown.ts +0 -41
- package/src/env/index.ts +0 -26
- package/src/file/ignore.ts +0 -83
- package/src/file/index.ts +0 -411
- package/src/file/ripgrep.ts +0 -402
- package/src/file/time.ts +0 -64
- package/src/file/watcher.ts +0 -117
- package/src/flag/flag.ts +0 -52
- package/src/format/formatter.ts +0 -359
- package/src/format/index.ts +0 -137
- package/src/global/index.ts +0 -55
- package/src/id/id.ts +0 -73
- package/src/ide/index.ts +0 -77
- package/src/index.ts +0 -159
- package/src/installation/index.ts +0 -198
- package/src/lsp/client.ts +0 -252
- package/src/lsp/index.ts +0 -485
- package/src/lsp/language.ts +0 -119
- package/src/lsp/server.ts +0 -2023
- package/src/mcp/auth.ts +0 -135
- package/src/mcp/index.ts +0 -874
- package/src/mcp/oauth-callback.ts +0 -200
- package/src/mcp/oauth-provider.ts +0 -154
- package/src/patch/index.ts +0 -622
- package/src/permission/arity.ts +0 -163
- package/src/permission/index.ts +0 -210
- package/src/permission/next.ts +0 -268
- package/src/plugin/index.ts +0 -106
- package/src/project/bootstrap.ts +0 -31
- package/src/project/instance.ts +0 -78
- package/src/project/project.ts +0 -263
- package/src/project/state.ts +0 -65
- package/src/project/vcs.ts +0 -76
- package/src/provider/auth.ts +0 -143
- package/src/provider/models-macro.ts +0 -4
- package/src/provider/models.ts +0 -77
- package/src/provider/provider.ts +0 -516
- package/src/provider/transform.ts +0 -114
- package/src/pty/index.ts +0 -212
- package/src/server/error.ts +0 -36
- package/src/server/mdns.ts +0 -57
- package/src/server/project.ts +0 -79
- package/src/server/server.ts +0 -2866
- package/src/server/tui.ts +0 -71
- package/src/session/compaction.ts +0 -225
- package/src/session/index.ts +0 -469
- package/src/session/llm.ts +0 -213
- package/src/session/message-v2.ts +0 -742
- package/src/session/message.ts +0 -189
- package/src/session/processor.ts +0 -402
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/anthropic_spoof.txt +0 -1
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex.txt +0 -318
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/qwen.txt +0 -109
- package/src/session/prompt.ts +0 -1621
- package/src/session/retry.ts +0 -90
- package/src/session/revert.ts +0 -108
- package/src/session/status.ts +0 -76
- package/src/session/summary.ts +0 -194
- package/src/session/system.ts +0 -108
- package/src/session/todo.ts +0 -37
- package/src/share/share-next.ts +0 -194
- package/src/share/share.ts +0 -23
- package/src/shell/shell.ts +0 -67
- package/src/skill/index.ts +0 -1
- package/src/skill/skill.ts +0 -124
- package/src/snapshot/index.ts +0 -197
- package/src/storage/storage.ts +0 -226
- package/src/tool/bash.ts +0 -262
- package/src/tool/bash.txt +0 -116
- package/src/tool/batch.ts +0 -175
- package/src/tool/batch.txt +0 -24
- package/src/tool/codesearch.ts +0 -132
- package/src/tool/codesearch.txt +0 -12
- package/src/tool/edit.ts +0 -655
- package/src/tool/edit.txt +0 -10
- package/src/tool/glob.ts +0 -75
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -132
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -17
- package/src/tool/ls.ts +0 -119
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp.ts +0 -94
- package/src/tool/lsp.txt +0 -19
- package/src/tool/multiedit.ts +0 -46
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/patch.ts +0 -210
- package/src/tool/patch.txt +0 -1
- package/src/tool/read.ts +0 -191
- package/src/tool/read.txt +0 -12
- package/src/tool/registry.ts +0 -137
- package/src/tool/skill.ts +0 -77
- package/src/tool/task.ts +0 -167
- package/src/tool/task.txt +0 -60
- package/src/tool/todo.ts +0 -53
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/tool.ts +0 -73
- package/src/tool/webfetch.ts +0 -182
- package/src/tool/webfetch.txt +0 -13
- package/src/tool/websearch.ts +0 -144
- package/src/tool/websearch.txt +0 -11
- package/src/tool/write.ts +0 -84
- package/src/tool/write.txt +0 -8
- package/src/util/archive.ts +0 -16
- package/src/util/color.ts +0 -19
- package/src/util/context.ts +0 -25
- package/src/util/defer.ts +0 -12
- package/src/util/eventloop.ts +0 -20
- package/src/util/filesystem.ts +0 -83
- package/src/util/fn.ts +0 -11
- package/src/util/iife.ts +0 -3
- package/src/util/keybind.ts +0 -102
- package/src/util/lazy.ts +0 -18
- package/src/util/locale.ts +0 -81
- package/src/util/lock.ts +0 -98
- package/src/util/log.ts +0 -180
- package/src/util/queue.ts +0 -32
- package/src/util/rpc.ts +0 -42
- package/src/util/scrap.ts +0 -10
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -14
- package/src/util/token.ts +0 -7
- package/src/util/wildcard.ts +0 -54
- package/src/worktree/index.ts +0 -217
- package/sst-env.d.ts +0 -9
- package/test/agent/agent.test.ts +0 -448
- package/test/bun.test.ts +0 -53
- package/test/cli/github-action.test.ts +0 -129
- package/test/cli/github-remote.test.ts +0 -80
- package/test/cli/tui/transcript.test.ts +0 -297
- package/test/config/agent-color.test.ts +0 -66
- package/test/config/config.test.ts +0 -870
- package/test/config/markdown.test.ts +0 -89
- package/test/file/ignore.test.ts +0 -10
- package/test/file/path-traversal.test.ts +0 -115
- package/test/fixture/fixture.ts +0 -45
- package/test/fixture/lsp/fake-lsp-server.js +0 -77
- package/test/ide/ide.test.ts +0 -82
- package/test/keybind.test.ts +0 -421
- package/test/lsp/client.test.ts +0 -95
- package/test/mcp/headers.test.ts +0 -153
- package/test/patch/patch.test.ts +0 -348
- package/test/permission/arity.test.ts +0 -33
- package/test/permission/next.test.ts +0 -652
- package/test/preload.ts +0 -63
- package/test/project/project.test.ts +0 -120
- package/test/provider/amazon-bedrock.test.ts +0 -236
- package/test/provider/provider.test.ts +0 -2127
- package/test/provider/transform.test.ts +0 -980
- package/test/server/session-select.test.ts +0 -78
- package/test/session/compaction.test.ts +0 -251
- package/test/session/message-v2.test.ts +0 -570
- package/test/session/retry.test.ts +0 -131
- package/test/session/revert-compact.test.ts +0 -285
- package/test/session/session.test.ts +0 -71
- package/test/skill/skill.test.ts +0 -185
- package/test/snapshot/snapshot.test.ts +0 -939
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/bash.test.ts +0 -232
- package/test/tool/grep.test.ts +0 -109
- package/test/tool/patch.test.ts +0 -261
- package/test/tool/read.test.ts +0 -167
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -55
- package/tsconfig.json +0 -16
- /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
package/src/lsp/index.ts
DELETED
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
import { BusEvent } from "@/bus/bus-event"
|
|
2
|
-
import { Bus } from "@/bus"
|
|
3
|
-
import { Log } from "../util/log"
|
|
4
|
-
import { LSPClient } from "./client"
|
|
5
|
-
import path from "path"
|
|
6
|
-
import { pathToFileURL } from "url"
|
|
7
|
-
import { LSPServer } from "./server"
|
|
8
|
-
import z from "zod"
|
|
9
|
-
import { Config } from "../config/config"
|
|
10
|
-
import { spawn } from "child_process"
|
|
11
|
-
import { Instance } from "../project/instance"
|
|
12
|
-
import { Flag } from "@/flag/flag"
|
|
13
|
-
|
|
14
|
-
export namespace LSP {
|
|
15
|
-
const log = Log.create({ service: "lsp" })
|
|
16
|
-
|
|
17
|
-
export const Event = {
|
|
18
|
-
Updated: BusEvent.define("lsp.updated", z.object({})),
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const Range = z
|
|
22
|
-
.object({
|
|
23
|
-
start: z.object({
|
|
24
|
-
line: z.number(),
|
|
25
|
-
character: z.number(),
|
|
26
|
-
}),
|
|
27
|
-
end: z.object({
|
|
28
|
-
line: z.number(),
|
|
29
|
-
character: z.number(),
|
|
30
|
-
}),
|
|
31
|
-
})
|
|
32
|
-
.meta({
|
|
33
|
-
ref: "Range",
|
|
34
|
-
})
|
|
35
|
-
export type Range = z.infer<typeof Range>
|
|
36
|
-
|
|
37
|
-
export const Symbol = z
|
|
38
|
-
.object({
|
|
39
|
-
name: z.string(),
|
|
40
|
-
kind: z.number(),
|
|
41
|
-
location: z.object({
|
|
42
|
-
uri: z.string(),
|
|
43
|
-
range: Range,
|
|
44
|
-
}),
|
|
45
|
-
})
|
|
46
|
-
.meta({
|
|
47
|
-
ref: "Symbol",
|
|
48
|
-
})
|
|
49
|
-
export type Symbol = z.infer<typeof Symbol>
|
|
50
|
-
|
|
51
|
-
export const DocumentSymbol = z
|
|
52
|
-
.object({
|
|
53
|
-
name: z.string(),
|
|
54
|
-
detail: z.string().optional(),
|
|
55
|
-
kind: z.number(),
|
|
56
|
-
range: Range,
|
|
57
|
-
selectionRange: Range,
|
|
58
|
-
})
|
|
59
|
-
.meta({
|
|
60
|
-
ref: "DocumentSymbol",
|
|
61
|
-
})
|
|
62
|
-
export type DocumentSymbol = z.infer<typeof DocumentSymbol>
|
|
63
|
-
|
|
64
|
-
const filterExperimentalServers = (servers: Record<string, LSPServer.Info>) => {
|
|
65
|
-
if (Flag.OPENCODE_EXPERIMENTAL_LSP_TY) {
|
|
66
|
-
// If experimental flag is enabled, disable pyright
|
|
67
|
-
if (servers["pyright"]) {
|
|
68
|
-
log.info("LSP server pyright is disabled because OPENCODE_EXPERIMENTAL_LSP_TY is enabled")
|
|
69
|
-
delete servers["pyright"]
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
// If experimental flag is disabled, disable ty
|
|
73
|
-
if (servers["ty"]) {
|
|
74
|
-
delete servers["ty"]
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const state = Instance.state(
|
|
80
|
-
async () => {
|
|
81
|
-
const clients: LSPClient.Info[] = []
|
|
82
|
-
const servers: Record<string, LSPServer.Info> = {}
|
|
83
|
-
const cfg = await Config.get()
|
|
84
|
-
|
|
85
|
-
if (cfg.lsp === false) {
|
|
86
|
-
log.info("all LSPs are disabled")
|
|
87
|
-
return {
|
|
88
|
-
broken: new Set<string>(),
|
|
89
|
-
servers,
|
|
90
|
-
clients,
|
|
91
|
-
spawning: new Map<string, Promise<LSPClient.Info | undefined>>(),
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
for (const server of Object.values(LSPServer)) {
|
|
96
|
-
servers[server.id] = server
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
filterExperimentalServers(servers)
|
|
100
|
-
|
|
101
|
-
for (const [name, item] of Object.entries(cfg.lsp ?? {})) {
|
|
102
|
-
const existing = servers[name]
|
|
103
|
-
if (item.disabled) {
|
|
104
|
-
log.info(`LSP server ${name} is disabled`)
|
|
105
|
-
delete servers[name]
|
|
106
|
-
continue
|
|
107
|
-
}
|
|
108
|
-
servers[name] = {
|
|
109
|
-
...existing,
|
|
110
|
-
id: name,
|
|
111
|
-
root: existing?.root ?? (async () => Instance.directory),
|
|
112
|
-
extensions: item.extensions ?? existing?.extensions ?? [],
|
|
113
|
-
spawn: async (root) => {
|
|
114
|
-
return {
|
|
115
|
-
process: spawn(item.command[0], item.command.slice(1), {
|
|
116
|
-
cwd: root,
|
|
117
|
-
env: {
|
|
118
|
-
...process.env,
|
|
119
|
-
...item.env,
|
|
120
|
-
},
|
|
121
|
-
}),
|
|
122
|
-
initialization: item.initialization,
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
log.info("enabled LSP servers", {
|
|
129
|
-
serverIds: Object.values(servers)
|
|
130
|
-
.map((server) => server.id)
|
|
131
|
-
.join(", "),
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
broken: new Set<string>(),
|
|
136
|
-
servers,
|
|
137
|
-
clients,
|
|
138
|
-
spawning: new Map<string, Promise<LSPClient.Info | undefined>>(),
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
async (state) => {
|
|
142
|
-
await Promise.all(state.clients.map((client) => client.shutdown()))
|
|
143
|
-
},
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
export async function init() {
|
|
147
|
-
return state()
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export const Status = z
|
|
151
|
-
.object({
|
|
152
|
-
id: z.string(),
|
|
153
|
-
name: z.string(),
|
|
154
|
-
root: z.string(),
|
|
155
|
-
status: z.union([z.literal("connected"), z.literal("error")]),
|
|
156
|
-
})
|
|
157
|
-
.meta({
|
|
158
|
-
ref: "LSPStatus",
|
|
159
|
-
})
|
|
160
|
-
export type Status = z.infer<typeof Status>
|
|
161
|
-
|
|
162
|
-
export async function status() {
|
|
163
|
-
return state().then((x) => {
|
|
164
|
-
const result: Status[] = []
|
|
165
|
-
for (const client of x.clients) {
|
|
166
|
-
result.push({
|
|
167
|
-
id: client.serverID,
|
|
168
|
-
name: x.servers[client.serverID].id,
|
|
169
|
-
root: path.relative(Instance.directory, client.root),
|
|
170
|
-
status: "connected",
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
return result
|
|
174
|
-
})
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function getClients(file: string) {
|
|
178
|
-
const s = await state()
|
|
179
|
-
const extension = path.parse(file).ext || file
|
|
180
|
-
const result: LSPClient.Info[] = []
|
|
181
|
-
|
|
182
|
-
async function schedule(server: LSPServer.Info, root: string, key: string) {
|
|
183
|
-
const handle = await server
|
|
184
|
-
.spawn(root)
|
|
185
|
-
.then((value) => {
|
|
186
|
-
if (!value) s.broken.add(key)
|
|
187
|
-
return value
|
|
188
|
-
})
|
|
189
|
-
.catch((err) => {
|
|
190
|
-
s.broken.add(key)
|
|
191
|
-
log.error(`Failed to spawn LSP server ${server.id}`, { error: err })
|
|
192
|
-
return undefined
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
if (!handle) return undefined
|
|
196
|
-
log.info("spawned lsp server", { serverID: server.id })
|
|
197
|
-
|
|
198
|
-
const client = await LSPClient.create({
|
|
199
|
-
serverID: server.id,
|
|
200
|
-
server: handle,
|
|
201
|
-
root,
|
|
202
|
-
}).catch((err) => {
|
|
203
|
-
s.broken.add(key)
|
|
204
|
-
handle.process.kill()
|
|
205
|
-
log.error(`Failed to initialize LSP client ${server.id}`, { error: err })
|
|
206
|
-
return undefined
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
if (!client) {
|
|
210
|
-
handle.process.kill()
|
|
211
|
-
return undefined
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const existing = s.clients.find((x) => x.root === root && x.serverID === server.id)
|
|
215
|
-
if (existing) {
|
|
216
|
-
handle.process.kill()
|
|
217
|
-
return existing
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
s.clients.push(client)
|
|
221
|
-
return client
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
for (const server of Object.values(s.servers)) {
|
|
225
|
-
if (server.extensions.length && !server.extensions.includes(extension)) continue
|
|
226
|
-
|
|
227
|
-
const root = await server.root(file)
|
|
228
|
-
if (!root) continue
|
|
229
|
-
if (s.broken.has(root + server.id)) continue
|
|
230
|
-
|
|
231
|
-
const match = s.clients.find((x) => x.root === root && x.serverID === server.id)
|
|
232
|
-
if (match) {
|
|
233
|
-
result.push(match)
|
|
234
|
-
continue
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const inflight = s.spawning.get(root + server.id)
|
|
238
|
-
if (inflight) {
|
|
239
|
-
const client = await inflight
|
|
240
|
-
if (!client) continue
|
|
241
|
-
result.push(client)
|
|
242
|
-
continue
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const task = schedule(server, root, root + server.id)
|
|
246
|
-
s.spawning.set(root + server.id, task)
|
|
247
|
-
|
|
248
|
-
task.finally(() => {
|
|
249
|
-
if (s.spawning.get(root + server.id) === task) {
|
|
250
|
-
s.spawning.delete(root + server.id)
|
|
251
|
-
}
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
const client = await task
|
|
255
|
-
if (!client) continue
|
|
256
|
-
|
|
257
|
-
result.push(client)
|
|
258
|
-
Bus.publish(Event.Updated, {})
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return result
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export async function hasClients(file: string) {
|
|
265
|
-
const s = await state()
|
|
266
|
-
const extension = path.parse(file).ext || file
|
|
267
|
-
for (const server of Object.values(s.servers)) {
|
|
268
|
-
if (server.extensions.length && !server.extensions.includes(extension)) continue
|
|
269
|
-
const root = await server.root(file)
|
|
270
|
-
if (!root) continue
|
|
271
|
-
if (s.broken.has(root + server.id)) continue
|
|
272
|
-
return true
|
|
273
|
-
}
|
|
274
|
-
return false
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export async function touchFile(input: string, waitForDiagnostics?: boolean) {
|
|
278
|
-
log.info("touching file", { file: input })
|
|
279
|
-
const clients = await getClients(input)
|
|
280
|
-
await Promise.all(
|
|
281
|
-
clients.map(async (client) => {
|
|
282
|
-
const wait = waitForDiagnostics ? client.waitForDiagnostics({ path: input }) : Promise.resolve()
|
|
283
|
-
await client.notify.open({ path: input })
|
|
284
|
-
return wait
|
|
285
|
-
}),
|
|
286
|
-
).catch((err) => {
|
|
287
|
-
log.error("failed to touch file", { err, file: input })
|
|
288
|
-
})
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export async function diagnostics() {
|
|
292
|
-
const results: Record<string, LSPClient.Diagnostic[]> = {}
|
|
293
|
-
for (const result of await runAll(async (client) => client.diagnostics)) {
|
|
294
|
-
for (const [path, diagnostics] of result.entries()) {
|
|
295
|
-
const arr = results[path] || []
|
|
296
|
-
arr.push(...diagnostics)
|
|
297
|
-
results[path] = arr
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return results
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export async function hover(input: { file: string; line: number; character: number }) {
|
|
304
|
-
return run(input.file, (client) => {
|
|
305
|
-
return client.connection
|
|
306
|
-
.sendRequest("textDocument/hover", {
|
|
307
|
-
textDocument: {
|
|
308
|
-
uri: pathToFileURL(input.file).href,
|
|
309
|
-
},
|
|
310
|
-
position: {
|
|
311
|
-
line: input.line,
|
|
312
|
-
character: input.character,
|
|
313
|
-
},
|
|
314
|
-
})
|
|
315
|
-
.catch(() => null)
|
|
316
|
-
})
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
enum SymbolKind {
|
|
320
|
-
File = 1,
|
|
321
|
-
Module = 2,
|
|
322
|
-
Namespace = 3,
|
|
323
|
-
Package = 4,
|
|
324
|
-
Class = 5,
|
|
325
|
-
Method = 6,
|
|
326
|
-
Property = 7,
|
|
327
|
-
Field = 8,
|
|
328
|
-
Constructor = 9,
|
|
329
|
-
Enum = 10,
|
|
330
|
-
Interface = 11,
|
|
331
|
-
Function = 12,
|
|
332
|
-
Variable = 13,
|
|
333
|
-
Constant = 14,
|
|
334
|
-
String = 15,
|
|
335
|
-
Number = 16,
|
|
336
|
-
Boolean = 17,
|
|
337
|
-
Array = 18,
|
|
338
|
-
Object = 19,
|
|
339
|
-
Key = 20,
|
|
340
|
-
Null = 21,
|
|
341
|
-
EnumMember = 22,
|
|
342
|
-
Struct = 23,
|
|
343
|
-
Event = 24,
|
|
344
|
-
Operator = 25,
|
|
345
|
-
TypeParameter = 26,
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const kinds = [
|
|
349
|
-
SymbolKind.Class,
|
|
350
|
-
SymbolKind.Function,
|
|
351
|
-
SymbolKind.Method,
|
|
352
|
-
SymbolKind.Interface,
|
|
353
|
-
SymbolKind.Variable,
|
|
354
|
-
SymbolKind.Constant,
|
|
355
|
-
SymbolKind.Struct,
|
|
356
|
-
SymbolKind.Enum,
|
|
357
|
-
]
|
|
358
|
-
|
|
359
|
-
export async function workspaceSymbol(query: string) {
|
|
360
|
-
return runAll((client) =>
|
|
361
|
-
client.connection
|
|
362
|
-
.sendRequest("workspace/symbol", {
|
|
363
|
-
query,
|
|
364
|
-
})
|
|
365
|
-
.then((result: any) => result.filter((x: LSP.Symbol) => kinds.includes(x.kind)))
|
|
366
|
-
.then((result: any) => result.slice(0, 10))
|
|
367
|
-
.catch(() => []),
|
|
368
|
-
).then((result) => result.flat() as LSP.Symbol[])
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export async function documentSymbol(uri: string) {
|
|
372
|
-
const file = new URL(uri).pathname
|
|
373
|
-
return run(file, (client) =>
|
|
374
|
-
client.connection
|
|
375
|
-
.sendRequest("textDocument/documentSymbol", {
|
|
376
|
-
textDocument: {
|
|
377
|
-
uri,
|
|
378
|
-
},
|
|
379
|
-
})
|
|
380
|
-
.catch(() => []),
|
|
381
|
-
)
|
|
382
|
-
.then((result) => result.flat() as (LSP.DocumentSymbol | LSP.Symbol)[])
|
|
383
|
-
.then((result) => result.filter(Boolean))
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export async function definition(input: { file: string; line: number; character: number }) {
|
|
387
|
-
return run(input.file, (client) =>
|
|
388
|
-
client.connection
|
|
389
|
-
.sendRequest("textDocument/definition", {
|
|
390
|
-
textDocument: { uri: pathToFileURL(input.file).href },
|
|
391
|
-
position: { line: input.line, character: input.character },
|
|
392
|
-
})
|
|
393
|
-
.catch(() => null),
|
|
394
|
-
).then((result) => result.flat().filter(Boolean))
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
export async function references(input: { file: string; line: number; character: number }) {
|
|
398
|
-
return run(input.file, (client) =>
|
|
399
|
-
client.connection
|
|
400
|
-
.sendRequest("textDocument/references", {
|
|
401
|
-
textDocument: { uri: pathToFileURL(input.file).href },
|
|
402
|
-
position: { line: input.line, character: input.character },
|
|
403
|
-
context: { includeDeclaration: true },
|
|
404
|
-
})
|
|
405
|
-
.catch(() => []),
|
|
406
|
-
).then((result) => result.flat().filter(Boolean))
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export async function implementation(input: { file: string; line: number; character: number }) {
|
|
410
|
-
return run(input.file, (client) =>
|
|
411
|
-
client.connection
|
|
412
|
-
.sendRequest("textDocument/implementation", {
|
|
413
|
-
textDocument: { uri: pathToFileURL(input.file).href },
|
|
414
|
-
position: { line: input.line, character: input.character },
|
|
415
|
-
})
|
|
416
|
-
.catch(() => null),
|
|
417
|
-
).then((result) => result.flat().filter(Boolean))
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
export async function prepareCallHierarchy(input: { file: string; line: number; character: number }) {
|
|
421
|
-
return run(input.file, (client) =>
|
|
422
|
-
client.connection
|
|
423
|
-
.sendRequest("textDocument/prepareCallHierarchy", {
|
|
424
|
-
textDocument: { uri: pathToFileURL(input.file).href },
|
|
425
|
-
position: { line: input.line, character: input.character },
|
|
426
|
-
})
|
|
427
|
-
.catch(() => []),
|
|
428
|
-
).then((result) => result.flat().filter(Boolean))
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export async function incomingCalls(input: { file: string; line: number; character: number }) {
|
|
432
|
-
return run(input.file, async (client) => {
|
|
433
|
-
const items = (await client.connection
|
|
434
|
-
.sendRequest("textDocument/prepareCallHierarchy", {
|
|
435
|
-
textDocument: { uri: pathToFileURL(input.file).href },
|
|
436
|
-
position: { line: input.line, character: input.character },
|
|
437
|
-
})
|
|
438
|
-
.catch(() => [])) as any[]
|
|
439
|
-
if (!items?.length) return []
|
|
440
|
-
return client.connection.sendRequest("callHierarchy/incomingCalls", { item: items[0] }).catch(() => [])
|
|
441
|
-
}).then((result) => result.flat().filter(Boolean))
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export async function outgoingCalls(input: { file: string; line: number; character: number }) {
|
|
445
|
-
return run(input.file, async (client) => {
|
|
446
|
-
const items = (await client.connection
|
|
447
|
-
.sendRequest("textDocument/prepareCallHierarchy", {
|
|
448
|
-
textDocument: { uri: pathToFileURL(input.file).href },
|
|
449
|
-
position: { line: input.line, character: input.character },
|
|
450
|
-
})
|
|
451
|
-
.catch(() => [])) as any[]
|
|
452
|
-
if (!items?.length) return []
|
|
453
|
-
return client.connection.sendRequest("callHierarchy/outgoingCalls", { item: items[0] }).catch(() => [])
|
|
454
|
-
}).then((result) => result.flat().filter(Boolean))
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
async function runAll<T>(input: (client: LSPClient.Info) => Promise<T>): Promise<T[]> {
|
|
458
|
-
const clients = await state().then((x) => x.clients)
|
|
459
|
-
const tasks = clients.map((x) => input(x))
|
|
460
|
-
return Promise.all(tasks)
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
async function run<T>(file: string, input: (client: LSPClient.Info) => Promise<T>): Promise<T[]> {
|
|
464
|
-
const clients = await getClients(file)
|
|
465
|
-
const tasks = clients.map((x) => input(x))
|
|
466
|
-
return Promise.all(tasks)
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
export namespace Diagnostic {
|
|
470
|
-
export function pretty(diagnostic: LSPClient.Diagnostic) {
|
|
471
|
-
const severityMap = {
|
|
472
|
-
1: "ERROR",
|
|
473
|
-
2: "WARN",
|
|
474
|
-
3: "INFO",
|
|
475
|
-
4: "HINT",
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
const severity = severityMap[diagnostic.severity || 1]
|
|
479
|
-
const line = diagnostic.range.start.line + 1
|
|
480
|
-
const col = diagnostic.range.start.character + 1
|
|
481
|
-
|
|
482
|
-
return `${severity} [${line}:${col}] ${diagnostic.message}`
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
package/src/lsp/language.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
export const LANGUAGE_EXTENSIONS: Record<string, string> = {
|
|
2
|
-
".abap": "abap",
|
|
3
|
-
".bat": "bat",
|
|
4
|
-
".bib": "bibtex",
|
|
5
|
-
".bibtex": "bibtex",
|
|
6
|
-
".clj": "clojure",
|
|
7
|
-
".cljs": "clojure",
|
|
8
|
-
".cljc": "clojure",
|
|
9
|
-
".edn": "clojure",
|
|
10
|
-
".coffee": "coffeescript",
|
|
11
|
-
".c": "c",
|
|
12
|
-
".cpp": "cpp",
|
|
13
|
-
".cxx": "cpp",
|
|
14
|
-
".cc": "cpp",
|
|
15
|
-
".c++": "cpp",
|
|
16
|
-
".cs": "csharp",
|
|
17
|
-
".css": "css",
|
|
18
|
-
".d": "d",
|
|
19
|
-
".pas": "pascal",
|
|
20
|
-
".pascal": "pascal",
|
|
21
|
-
".diff": "diff",
|
|
22
|
-
".patch": "diff",
|
|
23
|
-
".dart": "dart",
|
|
24
|
-
".dockerfile": "dockerfile",
|
|
25
|
-
".ex": "elixir",
|
|
26
|
-
".exs": "elixir",
|
|
27
|
-
".erl": "erlang",
|
|
28
|
-
".ets": "typescript",
|
|
29
|
-
".hrl": "erlang",
|
|
30
|
-
".fs": "fsharp",
|
|
31
|
-
".fsi": "fsharp",
|
|
32
|
-
".fsx": "fsharp",
|
|
33
|
-
".fsscript": "fsharp",
|
|
34
|
-
".gitcommit": "git-commit",
|
|
35
|
-
".gitrebase": "git-rebase",
|
|
36
|
-
".go": "go",
|
|
37
|
-
".groovy": "groovy",
|
|
38
|
-
".gleam": "gleam",
|
|
39
|
-
".hbs": "handlebars",
|
|
40
|
-
".handlebars": "handlebars",
|
|
41
|
-
".hs": "haskell",
|
|
42
|
-
".lhs": "haskell",
|
|
43
|
-
".html": "html",
|
|
44
|
-
".htm": "html",
|
|
45
|
-
".ini": "ini",
|
|
46
|
-
".java": "java",
|
|
47
|
-
".js": "javascript",
|
|
48
|
-
".kt": "kotlin",
|
|
49
|
-
".kts": "kotlin",
|
|
50
|
-
".jsx": "javascriptreact",
|
|
51
|
-
".json": "json",
|
|
52
|
-
".tex": "latex",
|
|
53
|
-
".latex": "latex",
|
|
54
|
-
".less": "less",
|
|
55
|
-
".lua": "lua",
|
|
56
|
-
".makefile": "makefile",
|
|
57
|
-
makefile: "makefile",
|
|
58
|
-
".md": "markdown",
|
|
59
|
-
".markdown": "markdown",
|
|
60
|
-
".m": "objective-c",
|
|
61
|
-
".mm": "objective-cpp",
|
|
62
|
-
".pl": "perl",
|
|
63
|
-
".pm": "perl",
|
|
64
|
-
".pm6": "perl6",
|
|
65
|
-
".php": "php",
|
|
66
|
-
".ps1": "powershell",
|
|
67
|
-
".psm1": "powershell",
|
|
68
|
-
".pug": "jade",
|
|
69
|
-
".jade": "jade",
|
|
70
|
-
".py": "python",
|
|
71
|
-
".r": "r",
|
|
72
|
-
".cshtml": "razor",
|
|
73
|
-
".razor": "razor",
|
|
74
|
-
".rb": "ruby",
|
|
75
|
-
".rake": "ruby",
|
|
76
|
-
".gemspec": "ruby",
|
|
77
|
-
".ru": "ruby",
|
|
78
|
-
".erb": "erb",
|
|
79
|
-
".html.erb": "erb",
|
|
80
|
-
".js.erb": "erb",
|
|
81
|
-
".css.erb": "erb",
|
|
82
|
-
".json.erb": "erb",
|
|
83
|
-
".rs": "rust",
|
|
84
|
-
".scss": "scss",
|
|
85
|
-
".sass": "sass",
|
|
86
|
-
".scala": "scala",
|
|
87
|
-
".shader": "shaderlab",
|
|
88
|
-
".sh": "shellscript",
|
|
89
|
-
".bash": "shellscript",
|
|
90
|
-
".zsh": "shellscript",
|
|
91
|
-
".ksh": "shellscript",
|
|
92
|
-
".sql": "sql",
|
|
93
|
-
".svelte": "svelte",
|
|
94
|
-
".swift": "swift",
|
|
95
|
-
".ts": "typescript",
|
|
96
|
-
".tsx": "typescriptreact",
|
|
97
|
-
".mts": "typescript",
|
|
98
|
-
".cts": "typescript",
|
|
99
|
-
".mtsx": "typescriptreact",
|
|
100
|
-
".ctsx": "typescriptreact",
|
|
101
|
-
".xml": "xml",
|
|
102
|
-
".xsl": "xsl",
|
|
103
|
-
".yaml": "yaml",
|
|
104
|
-
".yml": "yaml",
|
|
105
|
-
".mjs": "javascript",
|
|
106
|
-
".cjs": "javascript",
|
|
107
|
-
".vue": "vue",
|
|
108
|
-
".zig": "zig",
|
|
109
|
-
".zon": "zig",
|
|
110
|
-
".astro": "astro",
|
|
111
|
-
".ml": "ocaml",
|
|
112
|
-
".mli": "ocaml",
|
|
113
|
-
".tf": "terraform",
|
|
114
|
-
".tfvars": "terraform-vars",
|
|
115
|
-
".hcl": "hcl",
|
|
116
|
-
".nix": "nix",
|
|
117
|
-
".typ": "typst",
|
|
118
|
-
".typc": "typst",
|
|
119
|
-
} as const
|