oh-my-opencode 5.1.82 → 5.1.83
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/dist/cli/index.js +15 -15
- package/dist/cli-node/index.js +15 -15
- package/dist/index.js +13 -13
- package/dist/skills/browser/runtime/omowright/manifest.json +1 -1
- package/dist/tui.js +13 -13
- package/package.json +13 -13
- package/packages/lsp-core/src/lsp/client-key.ts +14 -0
- package/packages/lsp-core/src/lsp/client-startup.ts +139 -0
- package/packages/lsp-core/src/lsp/client-wrapper.ts +4 -4
- package/packages/lsp-core/src/lsp/config-loader.ts +15 -0
- package/packages/lsp-core/src/lsp/directory-diagnostics-group-scan.test.ts +388 -0
- package/packages/lsp-core/src/lsp/directory-diagnostics-mixed-typescript.test.ts +124 -0
- package/packages/lsp-core/src/lsp/directory-diagnostics.test.ts +4 -4
- package/packages/lsp-core/src/lsp/directory-diagnostics.ts +38 -41
- package/packages/lsp-core/src/lsp/directory-group-scan.ts +124 -0
- package/packages/lsp-core/src/lsp/directory-server-groups.ts +84 -0
- package/packages/lsp-core/src/lsp/manager-acquisition.test.ts +115 -0
- package/packages/lsp-core/src/lsp/manager-lifecycle.test.ts +9 -9
- package/packages/lsp-core/src/lsp/manager-max-clients.test.ts +41 -16
- package/packages/lsp-core/src/lsp/manager-reaping.test.ts +119 -0
- package/packages/lsp-core/src/lsp/manager-test-support.ts +108 -0
- package/packages/lsp-core/src/lsp/manager.ts +80 -249
- package/packages/lsp-core/src/lsp/native-typescript.ts +88 -0
- package/packages/lsp-core/src/lsp/server-installation.ts +15 -7
- package/packages/lsp-core/src/lsp/server-resolution-typescript-native.test.ts +327 -0
- package/packages/lsp-core/src/lsp/server-resolution.ts +28 -2
- package/packages/lsp-core/src/lsp/timer-provider.ts +17 -0
- package/packages/lsp-core/src/lsp/typescript-project-test-support.ts +52 -0
- package/packages/lsp-daemon/dist/cli.js +486 -310
- package/packages/lsp-daemon/dist/client.js +472 -296
- package/packages/lsp-daemon/dist/index.js +476 -300
- package/packages/lsp-tools-mcp/dist/cli.js +467 -291
- package/packages/lsp-tools-mcp/dist/lsp/manager.js +160 -193
- package/packages/lsp-tools-mcp/dist/mcp.js +467 -291
- package/packages/lsp-tools-mcp/dist/tools.js +467 -291
- package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
- package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
- package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +3 -3
- package/packages/omo-codex/plugin/components/lsp/dist/cli.js +478 -313
- package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
- package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/rules/package.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-execute-continuation/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +5 -5
- package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-recording-spawn-admission.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
- package/packages/omo-codex/plugin/hooks/stop-checking-ulw-execute-continuation.json +1 -1
- package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
- package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
- package/packages/omo-codex/plugin/package-lock.json +12 -12
- package/packages/omo-codex/plugin/package.json +1 -1
- package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
- package/packages/omo-codex/scripts/install-dist/install-local.mjs +2 -2
- package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +1 -1
|
@@ -13,11 +13,19 @@ interface LocalBinRule {
|
|
|
13
13
|
readonly binDirs: readonly string[]
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/** The Node rule: a marked project's `node_modules/.bin`. */
|
|
17
|
+
export const NODE_PROJECT_MARKERS: readonly string[] = [
|
|
18
|
+
"package.json",
|
|
19
|
+
"bun.lock",
|
|
20
|
+
"bun.lockb",
|
|
21
|
+
"package-lock.json",
|
|
22
|
+
"yarn.lock",
|
|
23
|
+
"pnpm-lock.yaml",
|
|
24
|
+
]
|
|
25
|
+
export const NODE_LOCAL_BIN_DIR = join("node_modules", ".bin")
|
|
26
|
+
|
|
16
27
|
const LOCAL_BIN_RULES: readonly LocalBinRule[] = [
|
|
17
|
-
{
|
|
18
|
-
markers: ["package.json", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"],
|
|
19
|
-
binDirs: [join("node_modules", ".bin")],
|
|
20
|
-
},
|
|
28
|
+
{ markers: NODE_PROJECT_MARKERS, binDirs: [NODE_LOCAL_BIN_DIR] },
|
|
21
29
|
{
|
|
22
30
|
markers: [
|
|
23
31
|
"pyproject.toml",
|
|
@@ -74,12 +82,12 @@ export function __serverBinaryProbeCountForTests(): number {
|
|
|
74
82
|
return probeCount
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
function probe(path: string): boolean {
|
|
85
|
+
export function probe(path: string): boolean {
|
|
78
86
|
probeCount += 1
|
|
79
87
|
return existsSync(path)
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
function executableSuffixes(platform: NodeJS.Platform, pathExt: string | undefined): readonly string[] {
|
|
90
|
+
export function executableSuffixes(platform: NodeJS.Platform, pathExt: string | undefined): readonly string[] {
|
|
83
91
|
if (platform !== "win32") return [""]
|
|
84
92
|
const configured = pathExt ?? process.env["PATHEXT"] ?? ""
|
|
85
93
|
// PATHEXT is conventionally uppercase, but the on-disk shims npm/bun write are lowercase.
|
|
@@ -92,7 +100,7 @@ function executableSuffixes(platform: NodeJS.Platform, pathExt: string | undefin
|
|
|
92
100
|
return [...new Set(["", ...systemExts, ".exe", ".cmd", ".bat", ".ps1"])]
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
function probeWithSuffixes(directory: string, command: string, suffixes: readonly string[]): string | null {
|
|
103
|
+
export function probeWithSuffixes(directory: string, command: string, suffixes: readonly string[]): string | null {
|
|
96
104
|
for (const suffix of suffixes) {
|
|
97
105
|
const candidate = join(directory, command + suffix)
|
|
98
106
|
if (probe(candidate)) return candidate
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { mkdirSync, symlinkSync, writeFileSync } from "node:fs"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
|
|
4
|
+
|
|
5
|
+
import { runWithRequestContext } from "../request-context.js"
|
|
6
|
+
import { __resetServerBinaryResolutionCacheForTests } from "./server-installation.js"
|
|
7
|
+
import { findServerForExtension, getAllServers } from "./server-resolution.js"
|
|
8
|
+
import {
|
|
9
|
+
contextFor,
|
|
10
|
+
createTypescriptProjects,
|
|
11
|
+
installTypescript,
|
|
12
|
+
writeExecutable,
|
|
13
|
+
} from "./typescript-project-test-support.js"
|
|
14
|
+
|
|
15
|
+
const projects = createTypescriptProjects("lsp-ts-native-")
|
|
16
|
+
const makeProject = projects.makeProject
|
|
17
|
+
let previousPath: string | undefined
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
previousPath = process.env["PATH"]
|
|
21
|
+
__resetServerBinaryResolutionCacheForTests()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
if (previousPath === undefined) delete process.env["PATH"]
|
|
26
|
+
else process.env["PATH"] = previousPath
|
|
27
|
+
projects.cleanup()
|
|
28
|
+
__resetServerBinaryResolutionCacheForTests()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe("TypeScript server selection from the project's TypeScript", () => {
|
|
32
|
+
test("#given a project on TypeScript 7 #when looking up a typescript file #then its own tsc serves LSP without tsserver options", () => {
|
|
33
|
+
// given: typescript-language-server is installed too, but it cannot start without lib/tsserver.js
|
|
34
|
+
const root = makeProject()
|
|
35
|
+
const tsc = installTypescript(join(root, "node_modules"), 7)
|
|
36
|
+
writeExecutable(join(root, "node_modules", ".bin", "typescript-language-server"))
|
|
37
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
38
|
+
|
|
39
|
+
// when
|
|
40
|
+
const result = runWithRequestContext(contextFor(root), () => findServerForExtension(".ts"))
|
|
41
|
+
|
|
42
|
+
// then
|
|
43
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
44
|
+
expect(result.server.id).toBe("typescript")
|
|
45
|
+
expect(result.server.command).toEqual([tsc, "--lsp", "--stdio"])
|
|
46
|
+
expect(result.server.initialization).toBeUndefined()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("#given a project on TypeScript 5 #when looking up a typescript file #then typescript-language-server still serves it", () => {
|
|
50
|
+
// given
|
|
51
|
+
const root = makeProject()
|
|
52
|
+
installTypescript(join(root, "node_modules"), 5)
|
|
53
|
+
const languageServer = writeExecutable(join(root, "node_modules", ".bin", "typescript-language-server"))
|
|
54
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
55
|
+
|
|
56
|
+
// when
|
|
57
|
+
const result = runWithRequestContext(contextFor(root), () => findServerForExtension(".ts"))
|
|
58
|
+
|
|
59
|
+
// then
|
|
60
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
61
|
+
expect(result.server.command).toEqual([languageServer, "--stdio"])
|
|
62
|
+
expect(result.server.initialization).toBeDefined()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("#given TypeScript 7 only on PATH #when looking up #then the project-less compiler does not replace the builtin server", () => {
|
|
66
|
+
// given
|
|
67
|
+
const root = makeProject()
|
|
68
|
+
const globalPrefix = makeProject()
|
|
69
|
+
installTypescript(join(globalPrefix, "node_modules"), 7)
|
|
70
|
+
process.env["PATH"] = join(globalPrefix, "node_modules", ".bin")
|
|
71
|
+
|
|
72
|
+
// when
|
|
73
|
+
const result = runWithRequestContext(contextFor(root), () => findServerForExtension(".ts"))
|
|
74
|
+
|
|
75
|
+
// then
|
|
76
|
+
if (result.status !== "not_installed") throw new Error(`expected not_installed, got ${result.status}`)
|
|
77
|
+
expect(result.server.id).toBe("typescript")
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test("#given a user typescript server with its own command #when the project is on TypeScript 7 #then the configured command wins", () => {
|
|
81
|
+
// given
|
|
82
|
+
const root = makeProject()
|
|
83
|
+
installTypescript(join(root, "node_modules"), 7)
|
|
84
|
+
const custom = writeExecutable(join(root, "node_modules", ".bin", "custom-ts-ls"))
|
|
85
|
+
mkdirSync(join(root, "home-config"), { recursive: true })
|
|
86
|
+
writeFileSync(
|
|
87
|
+
contextFor(root).userConfigPath,
|
|
88
|
+
JSON.stringify({ lsp: { typescript: { command: ["custom-ts-ls", "--stdio"], extensions: [".ts"] } } }),
|
|
89
|
+
)
|
|
90
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
91
|
+
|
|
92
|
+
// when
|
|
93
|
+
const result = runWithRequestContext(contextFor(root), () => findServerForExtension(".ts"))
|
|
94
|
+
|
|
95
|
+
// then
|
|
96
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
97
|
+
expect(result.server.command).toEqual([custom, "--stdio"])
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test("#given a project on TypeScript 7 alone #when listing servers #then typescript reports installed", () => {
|
|
101
|
+
// given
|
|
102
|
+
const root = makeProject()
|
|
103
|
+
installTypescript(join(root, "node_modules"), 7)
|
|
104
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
105
|
+
|
|
106
|
+
// when
|
|
107
|
+
const servers = runWithRequestContext(contextFor(root), () => getAllServers())
|
|
108
|
+
|
|
109
|
+
// then
|
|
110
|
+
expect(servers.find((server) => server.id === "typescript")?.installed).toBe(true)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test("#given a monorepo session root without TypeScript 7 #when looking up a file per package #then each package's own TypeScript decides", () => {
|
|
114
|
+
// given: the root has typescript-language-server only; packages/x is on TypeScript 7, packages/y on TypeScript 5
|
|
115
|
+
const root = makeProject()
|
|
116
|
+
mkdirSync(join(root, ".git"))
|
|
117
|
+
const languageServer = writeExecutable(join(root, "node_modules", ".bin", "typescript-language-server"))
|
|
118
|
+
const packageX = join(root, "packages", "x")
|
|
119
|
+
const packageY = join(root, "packages", "y")
|
|
120
|
+
mkdirSync(join(packageX, "src"), { recursive: true })
|
|
121
|
+
mkdirSync(join(packageY, "src"), { recursive: true })
|
|
122
|
+
writeFileSync(join(packageX, "package.json"), "{}\n")
|
|
123
|
+
writeFileSync(join(packageY, "package.json"), "{}\n")
|
|
124
|
+
const tscX = installTypescript(join(packageX, "node_modules"), 7)
|
|
125
|
+
installTypescript(join(packageY, "node_modules"), 5)
|
|
126
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
127
|
+
|
|
128
|
+
// when
|
|
129
|
+
const [inX, inY] = runWithRequestContext(contextFor(root), () => [
|
|
130
|
+
findServerForExtension(".ts", join(packageX, "src", "broken.ts")),
|
|
131
|
+
findServerForExtension(".ts", join(packageY, "src", "fine.ts")),
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
// then
|
|
135
|
+
if (inX?.status !== "found" || inY?.status !== "found") throw new Error("expected found servers for both packages")
|
|
136
|
+
expect(inX.server.command).toEqual([tscX, "--lsp", "--stdio"])
|
|
137
|
+
expect(inY.server.command).toEqual([languageServer, "--stdio"])
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test("#given a user typescript command equal to the default #when the project is on TypeScript 7 #then the command and its initialization are kept", () => {
|
|
141
|
+
// given
|
|
142
|
+
const root = makeProject()
|
|
143
|
+
installTypescript(join(root, "node_modules"), 7)
|
|
144
|
+
const languageServer = writeExecutable(join(root, "node_modules", ".bin", "typescript-language-server"))
|
|
145
|
+
const initialization = { preferences: { quotePreference: "double" } }
|
|
146
|
+
mkdirSync(join(root, "home-config"), { recursive: true })
|
|
147
|
+
writeFileSync(
|
|
148
|
+
contextFor(root).userConfigPath,
|
|
149
|
+
JSON.stringify({ lsp: { typescript: { command: ["typescript-language-server", "--stdio"], initialization } } }),
|
|
150
|
+
)
|
|
151
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
152
|
+
|
|
153
|
+
// when
|
|
154
|
+
const result = runWithRequestContext(contextFor(root), () => findServerForExtension(".ts"))
|
|
155
|
+
|
|
156
|
+
// then
|
|
157
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
158
|
+
expect(result.server.command).toEqual([languageServer, "--stdio"])
|
|
159
|
+
expect(result.server.initialization).toEqual(initialization)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test("#given user initialization on the inherited typescript command #when the project is on TypeScript 7 #then tsc receives only that initialization", () => {
|
|
163
|
+
// given
|
|
164
|
+
const root = makeProject()
|
|
165
|
+
const tsc = installTypescript(join(root, "node_modules"), 7)
|
|
166
|
+
const initialization = { locale: "en" }
|
|
167
|
+
mkdirSync(join(root, "home-config"), { recursive: true })
|
|
168
|
+
writeFileSync(contextFor(root).userConfigPath, JSON.stringify({ lsp: { typescript: { initialization } } }))
|
|
169
|
+
process.env["PATH"] = join(root, "definitely-empty")
|
|
170
|
+
|
|
171
|
+
// when
|
|
172
|
+
const result = runWithRequestContext(contextFor(root), () => findServerForExtension(".ts"))
|
|
173
|
+
|
|
174
|
+
// then
|
|
175
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
176
|
+
expect(result.server.command).toEqual([tsc, "--lsp", "--stdio"])
|
|
177
|
+
expect(result.server.initialization).toEqual(initialization)
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
describe("TypeScript server selection judged by real location", () => {
|
|
182
|
+
function sessionWithLanguageServer(): { readonly session: string; readonly languageServer: string } {
|
|
183
|
+
const session = makeProject()
|
|
184
|
+
mkdirSync(join(session, ".git"))
|
|
185
|
+
const languageServer = writeExecutable(join(session, "node_modules", ".bin", "typescript-language-server"))
|
|
186
|
+
process.env["PATH"] = join(session, "definitely-empty")
|
|
187
|
+
return { session, languageServer }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
test("#given an in-session directory linked to an external TypeScript 7 project #when looking up a file through the link #then the session keeps typescript-language-server", () => {
|
|
191
|
+
// given
|
|
192
|
+
const { session, languageServer } = sessionWithLanguageServer()
|
|
193
|
+
const external = makeProject()
|
|
194
|
+
installTypescript(join(external, "node_modules"), 7)
|
|
195
|
+
mkdirSync(join(external, "src"))
|
|
196
|
+
symlinkSync(external, join(session, "linked"), "dir")
|
|
197
|
+
|
|
198
|
+
// when
|
|
199
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
200
|
+
findServerForExtension(".ts", join(session, "linked", "src", "a.ts")),
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
// then
|
|
204
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
205
|
+
expect(result.server.command).toEqual([languageServer, "--stdio"])
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
test("#given a session reached through a symlinked root #when looking up a file of its TypeScript 7 package by the linked path #then that package's tsc serves it", () => {
|
|
209
|
+
// given
|
|
210
|
+
const { session } = sessionWithLanguageServer()
|
|
211
|
+
const packageX = join(session, "packages", "x")
|
|
212
|
+
mkdirSync(join(packageX, "src"), { recursive: true })
|
|
213
|
+
writeFileSync(join(packageX, "package.json"), "{}\n")
|
|
214
|
+
const tscX = installTypescript(join(packageX, "node_modules"), 7)
|
|
215
|
+
const alias = join(makeProject(), "session-alias")
|
|
216
|
+
symlinkSync(session, alias, "dir")
|
|
217
|
+
|
|
218
|
+
// when
|
|
219
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
220
|
+
findServerForExtension(".ts", join(alias, "packages", "x", "src", "a.ts")),
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
// then
|
|
224
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
225
|
+
expect(result.server.command).toEqual([tscX, "--lsp", "--stdio"])
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test("#given a pnpm layout whose typescript entry links into an external store #when looking up #then the project's tsc shim serves LSP", () => {
|
|
229
|
+
// given: node_modules and .bin are real directories; only the typescript entry is a link
|
|
230
|
+
const { session } = sessionWithLanguageServer()
|
|
231
|
+
const store = makeProject()
|
|
232
|
+
const storedTypescript = join(store, "typescript@7.0.0", "node_modules")
|
|
233
|
+
installTypescript(storedTypescript, 7)
|
|
234
|
+
mkdirSync(join(session, "node_modules"), { recursive: true })
|
|
235
|
+
symlinkSync(join(storedTypescript, "typescript"), join(session, "node_modules", "typescript"), "dir")
|
|
236
|
+
const tsc = writeExecutable(join(session, "node_modules", ".bin", "tsc"))
|
|
237
|
+
|
|
238
|
+
// when
|
|
239
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
240
|
+
findServerForExtension(".ts", join(session, "a.ts")),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
// then
|
|
244
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
245
|
+
expect(result.server.command).toEqual([tsc, "--lsp", "--stdio"])
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
test("#given a nearer bin/tsc in a Go package and a hoisted TypeScript 7 #when looking up a file of that package #then the hoisted compiler serves it", () => {
|
|
249
|
+
// given: packages/svc is marked only by go.mod and carries an unrelated bin/tsc
|
|
250
|
+
const { session } = sessionWithLanguageServer()
|
|
251
|
+
const hoisted = installTypescript(join(session, "node_modules"), 7)
|
|
252
|
+
const goPackage = join(session, "packages", "svc")
|
|
253
|
+
mkdirSync(goPackage, { recursive: true })
|
|
254
|
+
writeFileSync(join(goPackage, "go.mod"), "module svc\n")
|
|
255
|
+
const unrelated = writeExecutable(join(goPackage, "bin", "tsc"))
|
|
256
|
+
|
|
257
|
+
// when
|
|
258
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
259
|
+
findServerForExtension(".ts", join(goPackage, "a.ts")),
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
// then
|
|
263
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
264
|
+
expect(result.server.command).toEqual([hoisted, "--lsp", "--stdio"])
|
|
265
|
+
expect(result.server.command).not.toContain(unrelated)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
test("#given a nearer node_modules/.bin/tsc without a typescript package beside it and a hoisted TypeScript 7 #when looking up a file of that package #then the hoisted compiler serves it", () => {
|
|
269
|
+
// given: packages/x keeps a stale tsc shim whose typescript package is gone
|
|
270
|
+
const { session } = sessionWithLanguageServer()
|
|
271
|
+
const hoisted = installTypescript(join(session, "node_modules"), 7)
|
|
272
|
+
const packageX = join(session, "packages", "x")
|
|
273
|
+
mkdirSync(packageX, { recursive: true })
|
|
274
|
+
writeFileSync(join(packageX, "package.json"), "{}\n")
|
|
275
|
+
const stale = writeExecutable(join(packageX, "node_modules", ".bin", "tsc"))
|
|
276
|
+
|
|
277
|
+
// when
|
|
278
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
279
|
+
findServerForExtension(".ts", join(packageX, "a.ts")),
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
// then
|
|
283
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
284
|
+
expect(result.server.command).toEqual([hoisted, "--lsp", "--stdio"])
|
|
285
|
+
expect(result.server.command).not.toContain(stale)
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
test("#given a nearer package on TypeScript 5 below a hoisted TypeScript 7 #when looking up a file of that package #then typescript-language-server keeps serving it", () => {
|
|
289
|
+
// given
|
|
290
|
+
const { session, languageServer } = sessionWithLanguageServer()
|
|
291
|
+
installTypescript(join(session, "node_modules"), 7)
|
|
292
|
+
const packageY = join(session, "packages", "y")
|
|
293
|
+
mkdirSync(packageY, { recursive: true })
|
|
294
|
+
writeFileSync(join(packageY, "package.json"), "{}\n")
|
|
295
|
+
installTypescript(join(packageY, "node_modules"), 5)
|
|
296
|
+
|
|
297
|
+
// when
|
|
298
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
299
|
+
findServerForExtension(".ts", join(packageY, "a.ts")),
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
// then
|
|
303
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
304
|
+
expect(result.server.command).toEqual([languageServer, "--stdio"])
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
test("#given node_modules/.bin itself linked to an external TypeScript 7 project #when looking up #then the external tsc is not used", () => {
|
|
308
|
+
// given
|
|
309
|
+
const { session, languageServer } = sessionWithLanguageServer()
|
|
310
|
+
const packageX = join(session, "packages", "x")
|
|
311
|
+
mkdirSync(join(packageX, "node_modules"), { recursive: true })
|
|
312
|
+
writeFileSync(join(packageX, "package.json"), "{}\n")
|
|
313
|
+
const external = makeProject()
|
|
314
|
+
installTypescript(join(external, "node_modules"), 7)
|
|
315
|
+
symlinkSync(join(external, "node_modules", "typescript"), join(packageX, "node_modules", "typescript"), "dir")
|
|
316
|
+
symlinkSync(join(external, "node_modules", ".bin"), join(packageX, "node_modules", ".bin"), "dir")
|
|
317
|
+
|
|
318
|
+
// when
|
|
319
|
+
const result = runWithRequestContext(contextFor(session), () =>
|
|
320
|
+
findServerForExtension(".ts", join(packageX, "a.ts")),
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
// then
|
|
324
|
+
if (result.status !== "found") throw new Error(`expected a found server, got ${result.status}`)
|
|
325
|
+
expect(result.server.command).toEqual([languageServer, "--stdio"])
|
|
326
|
+
})
|
|
327
|
+
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { contextCwd } from "../request-context.js"
|
|
2
2
|
import { getDisabledServerIds, getMergedServers } from "./config-loader.js"
|
|
3
3
|
import { withHostJsRuntime } from "./host-js-runtime.js"
|
|
4
|
+
import { nativeTypescriptCommand, nativeTypescriptSearchDirectory } from "./native-typescript.js"
|
|
4
5
|
import { BUILTIN_SERVERS, LSP_INSTALL_HINTS } from "./server-definitions.js"
|
|
5
6
|
import { isServerInstalled, resolveServerBinary } from "./server-installation.js"
|
|
6
7
|
import type { ServerLookupResult } from "./types.js"
|
|
@@ -22,12 +23,34 @@ function usesBuiltinCommand(id: string, command: string[]): boolean {
|
|
|
22
23
|
)
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Picks the server for `ext`. `targetPath` is the file or directory being served; when given, a
|
|
28
|
+
* TypeScript 7 compiler is looked up from that target's project instead of the request cwd, so a
|
|
29
|
+
* monorepo package on TypeScript 7 is served by its own `tsc` while the session sits at the root.
|
|
30
|
+
*/
|
|
31
|
+
export function findServerForExtension(ext: string, targetPath?: string): ServerLookupResult {
|
|
26
32
|
const servers = getMergedServers()
|
|
27
33
|
const workingDirectory = contextCwd()
|
|
34
|
+
const searchDirectory = nativeTypescriptSearchDirectory(targetPath, workingDirectory)
|
|
28
35
|
|
|
29
36
|
for (const server of servers) {
|
|
30
37
|
if (!server.extensions.includes(ext)) continue
|
|
38
|
+
const nativeTypescript = nativeTypescriptCommand(server, searchDirectory)
|
|
39
|
+
if (nativeTypescript !== null) {
|
|
40
|
+
// The builtin initialization is typescript-language-server's option set; tsc gets only
|
|
41
|
+
// what a config file supplied.
|
|
42
|
+
return {
|
|
43
|
+
status: "found",
|
|
44
|
+
server: {
|
|
45
|
+
id: server.id,
|
|
46
|
+
command: withHostJsRuntime(server.id, nativeTypescript),
|
|
47
|
+
extensions: server.extensions,
|
|
48
|
+
priority: server.priority,
|
|
49
|
+
...(server.env === undefined ? {} : { env: server.env }),
|
|
50
|
+
...(server.configuredInitialization === undefined ? {} : { initialization: server.configuredInitialization }),
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
31
54
|
const binaryPath = resolveServerBinary(server.command, workingDirectory)
|
|
32
55
|
if (binaryPath !== null) {
|
|
33
56
|
const resolvedServer = {
|
|
@@ -94,6 +117,7 @@ export function getAllServers(): ServerStatus[] {
|
|
|
94
117
|
const servers = getMergedServers()
|
|
95
118
|
const disabled = getDisabledServerIds()
|
|
96
119
|
const workingDirectory = contextCwd()
|
|
120
|
+
const nativeSearchDirectory = nativeTypescriptSearchDirectory(undefined, workingDirectory)
|
|
97
121
|
|
|
98
122
|
const result: ServerStatus[] = []
|
|
99
123
|
const seen = new Set<string>()
|
|
@@ -102,7 +126,9 @@ export function getAllServers(): ServerStatus[] {
|
|
|
102
126
|
if (seen.has(server.id)) continue
|
|
103
127
|
result.push({
|
|
104
128
|
id: server.id,
|
|
105
|
-
installed:
|
|
129
|
+
installed:
|
|
130
|
+
isServerInstalled(server.command, workingDirectory) ||
|
|
131
|
+
nativeTypescriptCommand(server, nativeSearchDirectory) !== null,
|
|
106
132
|
extensions: server.extensions,
|
|
107
133
|
disabled: false,
|
|
108
134
|
source: server.source,
|
|
@@ -11,3 +11,20 @@ export const realTimerProvider: TimerProvider = {
|
|
|
11
11
|
setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
|
|
12
12
|
clearTimeout: (handle) => clearTimeout(handle),
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
/** Runs `tick` every `intervalMs` without keeping the process alive; the returned function stops it. */
|
|
16
|
+
export function repeatEvery(timers: TimerProvider, intervalMs: number, tick: () => void): () => void {
|
|
17
|
+
let handle: TimerHandle | null = null
|
|
18
|
+
const arm = () => {
|
|
19
|
+
handle = timers.setTimeout(() => {
|
|
20
|
+
tick()
|
|
21
|
+
if (handle !== null) arm()
|
|
22
|
+
}, intervalMs)
|
|
23
|
+
if (typeof handle.unref === "function") handle.unref()
|
|
24
|
+
}
|
|
25
|
+
arm()
|
|
26
|
+
return () => {
|
|
27
|
+
if (handle !== null) timers.clearTimeout(handle)
|
|
28
|
+
handle = null
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs"
|
|
2
|
+
import { tmpdir } from "node:os"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
|
|
5
|
+
import type { LspRequestContext } from "../request-context.js"
|
|
6
|
+
|
|
7
|
+
export interface TypescriptProjects {
|
|
8
|
+
/** A fresh directory with a package.json, as a real path (tmpdir itself may be a symlink). */
|
|
9
|
+
makeProject(): string
|
|
10
|
+
cleanup(): void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createTypescriptProjects(prefix: string): TypescriptProjects {
|
|
14
|
+
const roots: string[] = []
|
|
15
|
+
return {
|
|
16
|
+
makeProject() {
|
|
17
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), prefix)))
|
|
18
|
+
roots.push(root)
|
|
19
|
+
writeFileSync(join(root, "package.json"), "{}\n")
|
|
20
|
+
return root
|
|
21
|
+
},
|
|
22
|
+
cleanup() {
|
|
23
|
+
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function writeExecutable(path: string): string {
|
|
29
|
+
mkdirSync(join(path, ".."), { recursive: true })
|
|
30
|
+
writeFileSync(path, "#!/bin/sh\nexit 0\n")
|
|
31
|
+
chmodSync(path, 0o755)
|
|
32
|
+
return path
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** TypeScript 5 ships lib/tsserver.js; TypeScript 7 does not and serves LSP from tsc itself. */
|
|
36
|
+
export function installTypescript(nodeModules: string, major: 5 | 7): string {
|
|
37
|
+
const packageDir = join(nodeModules, "typescript")
|
|
38
|
+
mkdirSync(join(packageDir, "lib"), { recursive: true })
|
|
39
|
+
writeFileSync(join(packageDir, "package.json"), JSON.stringify({ name: "typescript", version: `${major}.0.0` }))
|
|
40
|
+
if (major === 5) writeFileSync(join(packageDir, "lib", "tsserver.js"), "")
|
|
41
|
+
return writeExecutable(join(nodeModules, ".bin", "tsc"))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function contextFor(cwd: string): LspRequestContext {
|
|
45
|
+
return {
|
|
46
|
+
cwd,
|
|
47
|
+
projectConfigPaths: [join(cwd, ".codex", "lsp-client.json")],
|
|
48
|
+
userConfigPath: join(cwd, "home-config", "lsp-client.json"),
|
|
49
|
+
installDecisionsPath: join(cwd, "home-config", "lsp-install-decisions.json"),
|
|
50
|
+
capabilities: { installDecisionTool: true },
|
|
51
|
+
}
|
|
52
|
+
}
|