oh-my-opencode 5.1.81 → 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 +443 -276
- package/dist/cli-node/index.js +443 -276
- package/dist/hooks/claude-code-hooks/handlers/empty-hook-config.fixture.d.ts +1 -0
- package/dist/index.js +650 -431
- package/dist/shared/opencode-message-dir.d.ts +1 -1
- package/dist/skills/browser/references/owned-engine/README.md +4 -2
- package/dist/skills/browser/references/owned-engine/frames-and-humans.md +9 -3
- package/dist/skills/browser/runtime/omowright/index.js +8 -8
- package/dist/skills/browser/runtime/omowright/manifest.json +4 -4
- package/dist/skills/frontend/SKILL.md +4 -2
- package/dist/skills/frontend/references/perfection/state-and-flow.md +120 -0
- package/dist/skills/visual-qa/AGENTS.md +2 -1
- package/dist/skills/visual-qa/SKILL.md +43 -11
- package/dist/skills/visual-qa/references/behaviour-evidence.md +189 -0
- package/dist/tui.js +15 -15
- package/package.json +15 -15
- 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/references/owned-engine/README.md +4 -2
- package/packages/omo-codex/plugin/skills/browser/references/owned-engine/frames-and-humans.md +9 -3
- package/packages/omo-codex/plugin/skills/browser/runtime/omowright/index.js +8 -8
- package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +4 -4
- package/packages/omo-codex/plugin/skills/frontend/SKILL.md +4 -2
- package/packages/omo-codex/plugin/skills/frontend/references/perfection/state-and-flow.md +120 -0
- package/packages/omo-codex/plugin/skills/visual-qa/AGENTS.md +2 -1
- package/packages/omo-codex/plugin/skills/visual-qa/SKILL.md +43 -11
- package/packages/omo-codex/plugin/skills/visual-qa/references/behaviour-evidence.md +189 -0
- package/packages/omo-codex/scripts/install-dist/install-local.mjs +2 -2
- package/packages/shared-skills/skills/browser/references/owned-engine/README.md +4 -2
- package/packages/shared-skills/skills/browser/references/owned-engine/frames-and-humans.md +9 -3
- package/packages/shared-skills/skills/browser/runtime/omowright/index.js +8 -8
- package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +4 -4
- package/packages/shared-skills/skills/frontend/SKILL.md +4 -2
- package/packages/shared-skills/skills/frontend/references/perfection/state-and-flow.md +120 -0
- package/packages/shared-skills/skills/visual-qa/AGENTS.md +2 -1
- package/packages/shared-skills/skills/visual-qa/SKILL.md +43 -11
- package/packages/shared-skills/skills/visual-qa/references/behaviour-evidence.md +189 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// ../lsp-core/src/lsp/client-wrapper.ts
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import { basename as basename3, dirname as
|
|
2
|
+
import { existsSync as existsSync11, realpathSync as realpathSync7, statSync as statSync4 } from "node:fs";
|
|
3
|
+
import { basename as basename3, dirname as dirname9, join as join6, resolve as resolve9 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// ../lsp-core/src/request-context.ts
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -290,6 +290,24 @@ var realTimerProvider = {
|
|
|
290
290
|
setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
|
|
291
291
|
clearTimeout: (handle) => clearTimeout(handle)
|
|
292
292
|
};
|
|
293
|
+
function repeatEvery(timers, intervalMs, tick) {
|
|
294
|
+
let handle = null;
|
|
295
|
+
const arm = () => {
|
|
296
|
+
handle = timers.setTimeout(() => {
|
|
297
|
+
tick();
|
|
298
|
+
if (handle !== null)
|
|
299
|
+
arm();
|
|
300
|
+
}, intervalMs);
|
|
301
|
+
if (typeof handle.unref === "function")
|
|
302
|
+
handle.unref();
|
|
303
|
+
};
|
|
304
|
+
arm();
|
|
305
|
+
return () => {
|
|
306
|
+
if (handle !== null)
|
|
307
|
+
timers.clearTimeout(handle);
|
|
308
|
+
handle = null;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
293
311
|
|
|
294
312
|
// ../lsp-core/src/lsp/constants.ts
|
|
295
313
|
var DEFAULT_MAX_REFERENCES = 200;
|
|
@@ -2952,30 +2970,54 @@ function abortError2(signal) {
|
|
|
2952
2970
|
return error;
|
|
2953
2971
|
}
|
|
2954
2972
|
|
|
2955
|
-
// ../lsp-core/src/lsp/
|
|
2956
|
-
function
|
|
2957
|
-
|
|
2958
|
-
const handler = () => {
|
|
2959
|
-
cleanup().catch((error) => {
|
|
2960
|
-
reportBestEffortCleanupError("signal cleanup", error);
|
|
2961
|
-
});
|
|
2962
|
-
};
|
|
2963
|
-
for (const signal of signals) {
|
|
2964
|
-
process.on(signal, handler);
|
|
2965
|
-
}
|
|
2966
|
-
return () => {
|
|
2967
|
-
for (const signal of signals) {
|
|
2968
|
-
process.removeListener(signal, handler);
|
|
2969
|
-
}
|
|
2970
|
-
};
|
|
2973
|
+
// ../lsp-core/src/lsp/client-key.ts
|
|
2974
|
+
function lspClientKey(root, server) {
|
|
2975
|
+
return JSON.stringify([root, server.id, server.command]);
|
|
2971
2976
|
}
|
|
2972
2977
|
|
|
2973
|
-
// ../lsp-core/src/lsp/
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2978
|
+
// ../lsp-core/src/lsp/client-startup.ts
|
|
2979
|
+
class ClientStartups {
|
|
2980
|
+
constructor(now, discard) {
|
|
2981
|
+
this.now = now;
|
|
2982
|
+
this.discard = discard;
|
|
2983
|
+
}
|
|
2984
|
+
begin(request) {
|
|
2985
|
+
const { client } = request;
|
|
2986
|
+
const startedAt = this.now();
|
|
2987
|
+
const initPromise = (async () => {
|
|
2988
|
+
await client.start();
|
|
2989
|
+
await client.initialize();
|
|
2990
|
+
})();
|
|
2991
|
+
const managed = {
|
|
2992
|
+
...request,
|
|
2993
|
+
refCount: 0,
|
|
2994
|
+
pendingWaiters: 0,
|
|
2995
|
+
lastUsedAt: startedAt,
|
|
2996
|
+
initPromise,
|
|
2997
|
+
isInitializing: true,
|
|
2998
|
+
initializingSince: startedAt
|
|
2999
|
+
};
|
|
3000
|
+
initPromise.then(() => {
|
|
3001
|
+
managed.isInitializing = false;
|
|
3002
|
+
managed.initializingSince = null;
|
|
3003
|
+
managed.initPromise = null;
|
|
3004
|
+
managed.lastUsedAt = this.now();
|
|
3005
|
+
}, () => this.discard(managed));
|
|
3006
|
+
return managed;
|
|
3007
|
+
}
|
|
3008
|
+
async wait(managed, initPromise, signal) {
|
|
3009
|
+
managed.pendingWaiters++;
|
|
3010
|
+
try {
|
|
3011
|
+
await awaitWithSignal(initPromise, signal);
|
|
3012
|
+
} catch (error) {
|
|
3013
|
+
this.detach(managed);
|
|
3014
|
+
throw error;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
detach(managed) {
|
|
3018
|
+
managed.pendingWaiters--;
|
|
3019
|
+
if (managed.pendingWaiters === 0 && managed.refCount === 0 && managed.heldByWaiters)
|
|
3020
|
+
this.discard(managed);
|
|
2979
3021
|
}
|
|
2980
3022
|
}
|
|
2981
3023
|
function awaitWithSignal(promise, signal) {
|
|
@@ -3010,36 +3052,50 @@ function awaitWithSignal(promise, signal) {
|
|
|
3010
3052
|
});
|
|
3011
3053
|
}
|
|
3012
3054
|
|
|
3055
|
+
// ../lsp-core/src/lsp/process-signal-cleanup.ts
|
|
3056
|
+
function installProcessSignalCleanup(cleanup) {
|
|
3057
|
+
const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGBREAK"] : ["SIGINT", "SIGTERM"];
|
|
3058
|
+
const handler = () => {
|
|
3059
|
+
cleanup().catch((error) => {
|
|
3060
|
+
reportBestEffortCleanupError("signal cleanup", error);
|
|
3061
|
+
});
|
|
3062
|
+
};
|
|
3063
|
+
for (const signal of signals) {
|
|
3064
|
+
process.on(signal, handler);
|
|
3065
|
+
}
|
|
3066
|
+
return () => {
|
|
3067
|
+
for (const signal of signals) {
|
|
3068
|
+
process.removeListener(signal, handler);
|
|
3069
|
+
}
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
// ../lsp-core/src/lsp/manager.ts
|
|
3074
|
+
async function stopClientBestEffort(client) {
|
|
3075
|
+
try {
|
|
3076
|
+
await client.stop();
|
|
3077
|
+
} catch (error) {
|
|
3078
|
+
reportBestEffortCleanupError("client stop", error);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3013
3082
|
class LspManager {
|
|
3014
3083
|
constructor(options = {}) {
|
|
3015
3084
|
this.clients = new Map;
|
|
3016
3085
|
this.pendingStops = new Map;
|
|
3017
3086
|
this.respawnBudgets = new Map;
|
|
3018
|
-
this.reaperHandle = null;
|
|
3019
3087
|
this.signalDisposer = null;
|
|
3020
3088
|
this.disposed = false;
|
|
3021
3089
|
this.idleTimeoutMs = options.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
|
|
3022
3090
|
this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS;
|
|
3023
3091
|
this.maxResidentClients = options.maxResidentClients ?? MAX_RESIDENT_CLIENTS;
|
|
3024
|
-
this.reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
|
|
3025
3092
|
this.clientFactory = options.clientFactory ?? ((root, server) => new LspClient(root, server));
|
|
3026
3093
|
this.now = options.now ?? (() => Date.now());
|
|
3027
|
-
this.
|
|
3094
|
+
this.startups = new ClientStartups(this.now, (managed) => this.discard(managed));
|
|
3095
|
+
const reaperIntervalMs = options.reaperIntervalMs ?? REAPER_INTERVAL_MS;
|
|
3096
|
+
this.stopReaper = repeatEvery(options.timers ?? realTimerProvider, reaperIntervalMs, () => this.reapStale());
|
|
3028
3097
|
this.signalDisposer = installProcessSignalCleanup(() => this.stopAll());
|
|
3029
3098
|
}
|
|
3030
|
-
startReaper() {
|
|
3031
|
-
if (this.reaperHandle)
|
|
3032
|
-
return;
|
|
3033
|
-
this.reaperHandle = setInterval(() => {
|
|
3034
|
-
this.reapStale();
|
|
3035
|
-
}, this.reaperIntervalMs);
|
|
3036
|
-
if (typeof this.reaperHandle.unref === "function") {
|
|
3037
|
-
this.reaperHandle.unref();
|
|
3038
|
-
}
|
|
3039
|
-
}
|
|
3040
|
-
getKey(root, serverId) {
|
|
3041
|
-
return `${root}::${serverId}`;
|
|
3042
|
-
}
|
|
3043
3099
|
tombstoneStop(key, client) {
|
|
3044
3100
|
const stop = stopClientBestEffort(client);
|
|
3045
3101
|
this.pendingStops.set(key, stop);
|
|
@@ -3075,18 +3131,15 @@ class LspManager {
|
|
|
3075
3131
|
budget.deadGenerations = 0;
|
|
3076
3132
|
budget.exhaustedAt = null;
|
|
3077
3133
|
}
|
|
3134
|
+
startupExpired(managed, t) {
|
|
3135
|
+
return managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs;
|
|
3136
|
+
}
|
|
3078
3137
|
reapStale() {
|
|
3079
3138
|
const t = this.now();
|
|
3080
|
-
for (const
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
this.
|
|
3084
|
-
continue;
|
|
3085
|
-
}
|
|
3086
|
-
if (!managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs) {
|
|
3087
|
-
this.clients.delete(key);
|
|
3088
|
-
this.tombstoneStop(key, managed.client);
|
|
3089
|
-
}
|
|
3139
|
+
for (const managed of [...this.clients.values()]) {
|
|
3140
|
+
const idle = !managed.isInitializing && managed.refCount === 0 && managed.pendingWaiters === 0 && t - managed.lastUsedAt > this.idleTimeoutMs;
|
|
3141
|
+
if (idle || this.startupExpired(managed, t))
|
|
3142
|
+
this.discard(managed);
|
|
3090
3143
|
}
|
|
3091
3144
|
}
|
|
3092
3145
|
evictForAdmission() {
|
|
@@ -3094,152 +3147,96 @@ class LspManager {
|
|
|
3094
3147
|
const victim = this.leastRecentlyUsedIdleClient();
|
|
3095
3148
|
if (!victim)
|
|
3096
3149
|
return;
|
|
3097
|
-
this.
|
|
3098
|
-
this.tombstoneStop(victim.key, victim.managed.client);
|
|
3150
|
+
this.discard(victim);
|
|
3099
3151
|
}
|
|
3100
3152
|
}
|
|
3101
3153
|
leastRecentlyUsedIdleClient() {
|
|
3102
3154
|
let candidate = null;
|
|
3103
|
-
for (const
|
|
3155
|
+
for (const managed of this.clients.values()) {
|
|
3104
3156
|
if (managed.refCount > 0 || managed.pendingWaiters > 0 || managed.isInitializing)
|
|
3105
3157
|
continue;
|
|
3106
|
-
if (candidate === null || managed.lastUsedAt < candidate.
|
|
3107
|
-
candidate =
|
|
3108
|
-
}
|
|
3158
|
+
if (candidate === null || managed.lastUsedAt < candidate.lastUsedAt)
|
|
3159
|
+
candidate = managed;
|
|
3109
3160
|
}
|
|
3110
3161
|
return candidate;
|
|
3111
3162
|
}
|
|
3112
|
-
|
|
3113
|
-
if (
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3163
|
+
discard(managed) {
|
|
3164
|
+
if (this.clients.get(managed.key) !== managed)
|
|
3165
|
+
return;
|
|
3166
|
+
this.clients.delete(managed.key);
|
|
3167
|
+
this.tombstoneStop(managed.key, managed.client);
|
|
3117
3168
|
}
|
|
3118
3169
|
async getClient(root, server, signal) {
|
|
3119
|
-
|
|
3120
|
-
throw new Error("LspManager has been disposed");
|
|
3121
|
-
}
|
|
3122
|
-
signal?.throwIfAborted();
|
|
3123
|
-
const key = this.getKey(root, server.id);
|
|
3170
|
+
const key = lspClientKey(root, server);
|
|
3124
3171
|
for (;; ) {
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
await awaitWithSignal(pendingStop, signal);
|
|
3172
|
+
if (this.disposed) {
|
|
3173
|
+
throw new Error("LspManager has been disposed");
|
|
3174
|
+
}
|
|
3129
3175
|
signal?.throwIfAborted();
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
let managed = this.clients.get(key);
|
|
3135
|
-
if (managed) {
|
|
3136
|
-
const t = this.now();
|
|
3137
|
-
if (managed.isInitializing && managed.initializingSince !== null && t - managed.initializingSince > this.initTimeoutMs) {
|
|
3138
|
-
this.clients.delete(key);
|
|
3139
|
-
await this.tombstoneStop(key, managed.client);
|
|
3140
|
-
managed = undefined;
|
|
3176
|
+
const pendingStop = this.pendingStops.get(key);
|
|
3177
|
+
if (pendingStop !== undefined) {
|
|
3178
|
+
await awaitWithSignal(pendingStop, signal);
|
|
3179
|
+
continue;
|
|
3141
3180
|
}
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3181
|
+
let managed = this.clients.get(key);
|
|
3182
|
+
if (managed !== undefined && this.startupExpired(managed, this.now())) {
|
|
3183
|
+
this.discard(managed);
|
|
3184
|
+
continue;
|
|
3185
|
+
}
|
|
3186
|
+
if (managed === undefined) {
|
|
3187
|
+
this.evictForAdmission();
|
|
3188
|
+
this.ensureRespawnAllowed(key, root, server.id);
|
|
3189
|
+
managed = this.startClient(key, root, server, true);
|
|
3190
|
+
}
|
|
3191
|
+
const { initPromise } = managed;
|
|
3192
|
+
if (initPromise !== null) {
|
|
3193
|
+
await this.startups.wait(managed, initPromise, signal);
|
|
3194
|
+
if (signal?.aborted) {
|
|
3195
|
+
this.startups.detach(managed);
|
|
3196
|
+
signal.throwIfAborted();
|
|
3152
3197
|
}
|
|
3153
3198
|
managed.pendingWaiters--;
|
|
3154
3199
|
}
|
|
3155
|
-
if (
|
|
3156
|
-
|
|
3157
|
-
signal.throwIfAborted();
|
|
3158
|
-
}
|
|
3200
|
+
if (this.clients.get(key) !== managed)
|
|
3201
|
+
continue;
|
|
3159
3202
|
if (!managed.client.isAlive()) {
|
|
3160
3203
|
this.recordDeadGeneration(key);
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
}
|
|
3164
|
-
await this.tombstoneStop(key, managed.client);
|
|
3165
|
-
return this.getClient(root, server, signal);
|
|
3204
|
+
this.discard(managed);
|
|
3205
|
+
continue;
|
|
3166
3206
|
}
|
|
3167
3207
|
this.markHealthyGeneration(key);
|
|
3168
3208
|
managed.refCount++;
|
|
3169
3209
|
managed.lastUsedAt = this.now();
|
|
3170
3210
|
return managed.client;
|
|
3171
3211
|
}
|
|
3172
|
-
|
|
3173
|
-
|
|
3212
|
+
}
|
|
3213
|
+
startClient(key, root, server, heldByWaiters) {
|
|
3174
3214
|
const client = this.clientFactory(root, server);
|
|
3175
|
-
const
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
const
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
pendingWaiters: 1,
|
|
3184
|
-
lastUsedAt: initStartedAt,
|
|
3185
|
-
initPromise,
|
|
3186
|
-
isInitializing: true,
|
|
3187
|
-
initializingSince: initStartedAt
|
|
3188
|
-
};
|
|
3189
|
-
this.clients.set(key, newManaged);
|
|
3190
|
-
try {
|
|
3191
|
-
await awaitWithSignal(initPromise, signal);
|
|
3192
|
-
} catch (err) {
|
|
3193
|
-
newManaged.pendingWaiters--;
|
|
3194
|
-
if (this.clients.get(key) === newManaged) {
|
|
3195
|
-
this.clients.delete(key);
|
|
3196
|
-
}
|
|
3197
|
-
await this.tombstoneStop(key, client);
|
|
3198
|
-
throw err;
|
|
3199
|
-
}
|
|
3200
|
-
newManaged.pendingWaiters--;
|
|
3201
|
-
newManaged.isInitializing = false;
|
|
3202
|
-
newManaged.initializingSince = null;
|
|
3203
|
-
newManaged.initPromise = null;
|
|
3204
|
-
if (signal?.aborted) {
|
|
3205
|
-
await this.tryDeleteIfOrphaned(key, newManaged);
|
|
3206
|
-
signal.throwIfAborted();
|
|
3207
|
-
}
|
|
3208
|
-
if (!client.isAlive()) {
|
|
3209
|
-
this.recordDeadGeneration(key);
|
|
3210
|
-
if (this.clients.get(key) === newManaged) {
|
|
3211
|
-
this.clients.delete(key);
|
|
3212
|
-
}
|
|
3213
|
-
await this.tombstoneStop(key, client);
|
|
3214
|
-
return this.getClient(root, server, signal);
|
|
3215
|
-
}
|
|
3216
|
-
this.markHealthyGeneration(key);
|
|
3217
|
-
newManaged.refCount++;
|
|
3218
|
-
newManaged.lastUsedAt = this.now();
|
|
3219
|
-
return client;
|
|
3220
|
-
}
|
|
3221
|
-
releaseClient(root, serverId) {
|
|
3222
|
-
const key = this.getKey(root, serverId);
|
|
3223
|
-
const managed = this.clients.get(key);
|
|
3215
|
+
const managed = this.startups.begin({ key, root, serverId: server.id, client, heldByWaiters });
|
|
3216
|
+
this.clients.set(key, managed);
|
|
3217
|
+
return managed;
|
|
3218
|
+
}
|
|
3219
|
+
releaseClient(root, server, client) {
|
|
3220
|
+
const managed = this.clients.get(lspClientKey(root, server));
|
|
3221
|
+
if (client !== undefined && managed?.client !== client)
|
|
3222
|
+
return;
|
|
3224
3223
|
if (managed && managed.refCount > 0) {
|
|
3225
3224
|
managed.refCount--;
|
|
3226
3225
|
managed.lastUsedAt = this.now();
|
|
3227
3226
|
}
|
|
3228
3227
|
}
|
|
3229
|
-
invalidateClient(root,
|
|
3230
|
-
const
|
|
3231
|
-
const managed = this.clients.get(key);
|
|
3228
|
+
invalidateClient(root, server, client) {
|
|
3229
|
+
const managed = this.clients.get(lspClientKey(root, server));
|
|
3232
3230
|
if (!managed)
|
|
3233
3231
|
return;
|
|
3234
3232
|
if (client && managed.client !== client)
|
|
3235
3233
|
return;
|
|
3236
|
-
this.
|
|
3237
|
-
this.tombstoneStop(key, managed.client);
|
|
3234
|
+
this.discard(managed);
|
|
3238
3235
|
}
|
|
3239
3236
|
warmupClient(root, server) {
|
|
3240
3237
|
if (this.disposed)
|
|
3241
3238
|
return;
|
|
3242
|
-
const key =
|
|
3239
|
+
const key = lspClientKey(root, server);
|
|
3243
3240
|
if (this.clients.has(key) || this.pendingStops.has(key))
|
|
3244
3241
|
return;
|
|
3245
3242
|
this.evictForAdmission();
|
|
@@ -3248,45 +3245,18 @@ class LspManager {
|
|
|
3248
3245
|
} catch {
|
|
3249
3246
|
return;
|
|
3250
3247
|
}
|
|
3251
|
-
|
|
3252
|
-
const initStartedAt = this.now();
|
|
3253
|
-
const initPromise = (async () => {
|
|
3254
|
-
await client.start();
|
|
3255
|
-
await client.initialize();
|
|
3256
|
-
})();
|
|
3257
|
-
const managed = {
|
|
3258
|
-
client,
|
|
3259
|
-
refCount: 0,
|
|
3260
|
-
pendingWaiters: 0,
|
|
3261
|
-
lastUsedAt: initStartedAt,
|
|
3262
|
-
initPromise,
|
|
3263
|
-
isInitializing: true,
|
|
3264
|
-
initializingSince: initStartedAt
|
|
3265
|
-
};
|
|
3266
|
-
this.clients.set(key, managed);
|
|
3267
|
-
initPromise.then(() => {
|
|
3268
|
-
managed.isInitializing = false;
|
|
3269
|
-
managed.initializingSince = null;
|
|
3270
|
-
managed.initPromise = null;
|
|
3271
|
-
managed.lastUsedAt = this.now();
|
|
3272
|
-
}, () => {
|
|
3273
|
-
if (this.clients.get(key) === managed) {
|
|
3274
|
-
this.clients.delete(key);
|
|
3275
|
-
}
|
|
3276
|
-
this.tombstoneStop(key, client);
|
|
3277
|
-
});
|
|
3248
|
+
this.startClient(key, root, server, false);
|
|
3278
3249
|
}
|
|
3279
|
-
isServerInitializing(root,
|
|
3280
|
-
const managed = this.clients.get(
|
|
3250
|
+
isServerInitializing(root, server) {
|
|
3251
|
+
const managed = this.clients.get(lspClientKey(root, server));
|
|
3281
3252
|
return managed?.isInitializing ?? false;
|
|
3282
3253
|
}
|
|
3283
3254
|
getSnapshot() {
|
|
3284
3255
|
const snapshots = [];
|
|
3285
|
-
for (const
|
|
3286
|
-
const [root, serverId] = key.split("::");
|
|
3256
|
+
for (const managed of this.clients.values()) {
|
|
3287
3257
|
snapshots.push({
|
|
3288
|
-
root,
|
|
3289
|
-
serverId,
|
|
3258
|
+
root: managed.root,
|
|
3259
|
+
serverId: managed.serverId,
|
|
3290
3260
|
refCount: managed.refCount,
|
|
3291
3261
|
pendingWaiters: managed.pendingWaiters,
|
|
3292
3262
|
lastUsedAt: managed.lastUsedAt,
|
|
@@ -3297,18 +3267,15 @@ class LspManager {
|
|
|
3297
3267
|
}
|
|
3298
3268
|
return snapshots;
|
|
3299
3269
|
}
|
|
3300
|
-
hasClient(root,
|
|
3301
|
-
return this.clients.has(
|
|
3270
|
+
hasClient(root, server) {
|
|
3271
|
+
return this.clients.has(lspClientKey(root, server));
|
|
3302
3272
|
}
|
|
3303
3273
|
clientCount() {
|
|
3304
3274
|
return this.clients.size;
|
|
3305
3275
|
}
|
|
3306
3276
|
async stopAll() {
|
|
3307
3277
|
this.disposed = true;
|
|
3308
|
-
|
|
3309
|
-
clearInterval(this.reaperHandle);
|
|
3310
|
-
this.reaperHandle = null;
|
|
3311
|
-
}
|
|
3278
|
+
this.stopReaper();
|
|
3312
3279
|
if (this.signalDisposer) {
|
|
3313
3280
|
this.signalDisposer();
|
|
3314
3281
|
this.signalDisposer = null;
|
|
@@ -3677,6 +3644,7 @@ function getMergedServers() {
|
|
|
3677
3644
|
extensions: config.extensions,
|
|
3678
3645
|
priority: -100,
|
|
3679
3646
|
source: "builtin",
|
|
3647
|
+
inheritsBuiltinCommand: true,
|
|
3680
3648
|
...config.initialization === undefined ? {} : { initialization: config.initialization }
|
|
3681
3649
|
});
|
|
3682
3650
|
}
|
|
@@ -3702,8 +3670,11 @@ function createServerFromEntry(id, entry, source) {
|
|
|
3702
3670
|
command: builtin.command,
|
|
3703
3671
|
extensions: entry.extensions ?? builtin.extensions,
|
|
3704
3672
|
priority: entry.priority ?? 0,
|
|
3705
|
-
source
|
|
3673
|
+
source,
|
|
3674
|
+
inheritsBuiltinCommand: true
|
|
3706
3675
|
});
|
|
3676
|
+
if (entry.initialization !== undefined)
|
|
3677
|
+
server.configuredInitialization = entry.initialization;
|
|
3707
3678
|
const initialization = mergeInitialization(builtin.initialization, entry.initialization);
|
|
3708
3679
|
if (initialization !== undefined) {
|
|
3709
3680
|
server.initialization = initialization;
|
|
@@ -3716,7 +3687,8 @@ function createServerFromEntry(id, entry, source) {
|
|
|
3716
3687
|
command: entry.command,
|
|
3717
3688
|
extensions: entry.extensions,
|
|
3718
3689
|
priority: entry.priority ?? 0,
|
|
3719
|
-
source
|
|
3690
|
+
source,
|
|
3691
|
+
inheritsBuiltinCommand: false
|
|
3720
3692
|
});
|
|
3721
3693
|
applyOptionalServerFields(server, entry);
|
|
3722
3694
|
return server;
|
|
@@ -3728,7 +3700,8 @@ function createServerFromEntry(id, entry, source) {
|
|
|
3728
3700
|
command: entry.command ?? builtin.command,
|
|
3729
3701
|
extensions: entry.extensions ?? builtin.extensions,
|
|
3730
3702
|
priority: entry.priority ?? 0,
|
|
3731
|
-
source
|
|
3703
|
+
source,
|
|
3704
|
+
inheritsBuiltinCommand: entry.command === undefined
|
|
3732
3705
|
});
|
|
3733
3706
|
applyOptionalServerFields(server, entry);
|
|
3734
3707
|
const builtinInitialization = entry.command === undefined ? builtin.initialization : undefined;
|
|
@@ -3751,7 +3724,8 @@ function createServer(input) {
|
|
|
3751
3724
|
command: input.command,
|
|
3752
3725
|
extensions: input.extensions,
|
|
3753
3726
|
priority: input.priority,
|
|
3754
|
-
source: input.source
|
|
3727
|
+
source: input.source,
|
|
3728
|
+
inheritsBuiltinCommand: input.inheritsBuiltinCommand
|
|
3755
3729
|
};
|
|
3756
3730
|
if (input.env !== undefined) {
|
|
3757
3731
|
server.env = input.env;
|
|
@@ -3767,6 +3741,7 @@ function applyOptionalServerFields(server, entry) {
|
|
|
3767
3741
|
}
|
|
3768
3742
|
if (entry.initialization !== undefined) {
|
|
3769
3743
|
server.initialization = entry.initialization;
|
|
3744
|
+
server.configuredInitialization = entry.initialization;
|
|
3770
3745
|
}
|
|
3771
3746
|
}
|
|
3772
3747
|
function isConfigJson(value) {
|
|
@@ -3858,14 +3833,24 @@ function readHead(path) {
|
|
|
3858
3833
|
}
|
|
3859
3834
|
}
|
|
3860
3835
|
|
|
3836
|
+
// ../lsp-core/src/lsp/native-typescript.ts
|
|
3837
|
+
import { existsSync as existsSync10, realpathSync as realpathSync6, statSync as statSync3 } from "node:fs";
|
|
3838
|
+
import { dirname as dirname8, join as join5, resolve as resolve8 } from "node:path";
|
|
3839
|
+
|
|
3861
3840
|
// ../lsp-core/src/lsp/server-installation.ts
|
|
3862
3841
|
import { existsSync as existsSync9 } from "node:fs";
|
|
3863
3842
|
import { delimiter as delimiter3, dirname as dirname7, isAbsolute as isAbsolute3, join as join4, resolve as resolve7 } from "node:path";
|
|
3843
|
+
var NODE_PROJECT_MARKERS = [
|
|
3844
|
+
"package.json",
|
|
3845
|
+
"bun.lock",
|
|
3846
|
+
"bun.lockb",
|
|
3847
|
+
"package-lock.json",
|
|
3848
|
+
"yarn.lock",
|
|
3849
|
+
"pnpm-lock.yaml"
|
|
3850
|
+
];
|
|
3851
|
+
var NODE_LOCAL_BIN_DIR = join4("node_modules", ".bin");
|
|
3864
3852
|
var LOCAL_BIN_RULES = [
|
|
3865
|
-
{
|
|
3866
|
-
markers: ["package.json", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"],
|
|
3867
|
-
binDirs: [join4("node_modules", ".bin")]
|
|
3868
|
-
},
|
|
3853
|
+
{ markers: NODE_PROJECT_MARKERS, binDirs: [NODE_LOCAL_BIN_DIR] },
|
|
3869
3854
|
{
|
|
3870
3855
|
markers: [
|
|
3871
3856
|
"pyproject.toml",
|
|
@@ -3993,6 +3978,57 @@ function isServerInstalled(command, workingDirectory, options = {}) {
|
|
|
3993
3978
|
return resolveServerBinary(command, workingDirectory, options) !== null;
|
|
3994
3979
|
}
|
|
3995
3980
|
|
|
3981
|
+
// ../lsp-core/src/lsp/native-typescript.ts
|
|
3982
|
+
function nativeTypescriptSearchDirectory(targetPath, workingDirectory) {
|
|
3983
|
+
try {
|
|
3984
|
+
const session = realpathSync6(workingDirectory);
|
|
3985
|
+
if (targetPath === undefined)
|
|
3986
|
+
return session;
|
|
3987
|
+
const target = canonicalizeExistingOrNearestAncestor(resolve8(workingDirectory, targetPath));
|
|
3988
|
+
if (!isPathInside(session, target))
|
|
3989
|
+
return session;
|
|
3990
|
+
return statSync3(target, { throwIfNoEntry: false })?.isDirectory() === true ? target : dirname8(target);
|
|
3991
|
+
} catch {
|
|
3992
|
+
return workingDirectory;
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3995
|
+
function nativeTypescriptCommand(server, searchDirectory) {
|
|
3996
|
+
if (server.id !== "typescript" || !server.inheritsBuiltinCommand)
|
|
3997
|
+
return null;
|
|
3998
|
+
const found = findProjectTsc(searchDirectory);
|
|
3999
|
+
if (found === null)
|
|
4000
|
+
return null;
|
|
4001
|
+
const speaksLsp = !existsSync10(join5(found.packageDir, "lib", "tsserver.js"));
|
|
4002
|
+
return speaksLsp ? [found.tsc, "--lsp", "--stdio"] : null;
|
|
4003
|
+
}
|
|
4004
|
+
function findProjectTsc(searchDirectory) {
|
|
4005
|
+
const suffixes = executableSuffixes(process.platform, undefined);
|
|
4006
|
+
let current = searchDirectory;
|
|
4007
|
+
for (;; ) {
|
|
4008
|
+
if (NODE_PROJECT_MARKERS.some((marker) => probe(join5(current, marker)))) {
|
|
4009
|
+
const binDir = join5(current, NODE_LOCAL_BIN_DIR);
|
|
4010
|
+
const tsc = probeWithSuffixes(binDir, "tsc", suffixes);
|
|
4011
|
+
const packageDir = join5(binDir, "..", "typescript");
|
|
4012
|
+
if (tsc !== null && isRealDirectory(binDir) && existsSync10(join5(packageDir, "package.json"))) {
|
|
4013
|
+
return { tsc, packageDir };
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
if (probe(join5(current, ".git")))
|
|
4017
|
+
return null;
|
|
4018
|
+
const parent = dirname8(current);
|
|
4019
|
+
if (parent === current)
|
|
4020
|
+
return null;
|
|
4021
|
+
current = parent;
|
|
4022
|
+
}
|
|
4023
|
+
}
|
|
4024
|
+
function isRealDirectory(directory) {
|
|
4025
|
+
try {
|
|
4026
|
+
return realpathSync6(directory) === directory;
|
|
4027
|
+
} catch {
|
|
4028
|
+
return false;
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
|
|
3996
4032
|
// ../lsp-core/src/lsp/server-resolution.ts
|
|
3997
4033
|
function withResolvedCommand(command, binaryPath) {
|
|
3998
4034
|
return [binaryPath, ...command.slice(1)];
|
|
@@ -4001,12 +4037,27 @@ function usesBuiltinCommand(id, command) {
|
|
|
4001
4037
|
const builtin = BUILTIN_SERVERS[id]?.command;
|
|
4002
4038
|
return builtin !== undefined && builtin.length === command.length && builtin.every((part, index) => part === command[index]);
|
|
4003
4039
|
}
|
|
4004
|
-
function findServerForExtension(ext) {
|
|
4040
|
+
function findServerForExtension(ext, targetPath) {
|
|
4005
4041
|
const servers = getMergedServers();
|
|
4006
4042
|
const workingDirectory = contextCwd();
|
|
4043
|
+
const searchDirectory = nativeTypescriptSearchDirectory(targetPath, workingDirectory);
|
|
4007
4044
|
for (const server of servers) {
|
|
4008
4045
|
if (!server.extensions.includes(ext))
|
|
4009
4046
|
continue;
|
|
4047
|
+
const nativeTypescript = nativeTypescriptCommand(server, searchDirectory);
|
|
4048
|
+
if (nativeTypescript !== null) {
|
|
4049
|
+
return {
|
|
4050
|
+
status: "found",
|
|
4051
|
+
server: {
|
|
4052
|
+
id: server.id,
|
|
4053
|
+
command: withHostJsRuntime(server.id, nativeTypescript),
|
|
4054
|
+
extensions: server.extensions,
|
|
4055
|
+
priority: server.priority,
|
|
4056
|
+
...server.env === undefined ? {} : { env: server.env },
|
|
4057
|
+
...server.configuredInitialization === undefined ? {} : { initialization: server.configuredInitialization }
|
|
4058
|
+
}
|
|
4059
|
+
};
|
|
4060
|
+
}
|
|
4010
4061
|
const binaryPath = resolveServerBinary(server.command, workingDirectory);
|
|
4011
4062
|
if (binaryPath !== null) {
|
|
4012
4063
|
const resolvedServer = {
|
|
@@ -4059,6 +4110,7 @@ function getAllServers() {
|
|
|
4059
4110
|
const servers = getMergedServers();
|
|
4060
4111
|
const disabled = getDisabledServerIds();
|
|
4061
4112
|
const workingDirectory = contextCwd();
|
|
4113
|
+
const nativeSearchDirectory = nativeTypescriptSearchDirectory(undefined, workingDirectory);
|
|
4062
4114
|
const result = [];
|
|
4063
4115
|
const seen = new Set;
|
|
4064
4116
|
for (const server of servers) {
|
|
@@ -4066,7 +4118,7 @@ function getAllServers() {
|
|
|
4066
4118
|
continue;
|
|
4067
4119
|
result.push({
|
|
4068
4120
|
id: server.id,
|
|
4069
|
-
installed: isServerInstalled(server.command, workingDirectory),
|
|
4121
|
+
installed: isServerInstalled(server.command, workingDirectory) || nativeTypescriptCommand(server, nativeSearchDirectory) !== null,
|
|
4070
4122
|
extensions: server.extensions,
|
|
4071
4123
|
disabled: false,
|
|
4072
4124
|
source: server.source,
|
|
@@ -4093,7 +4145,7 @@ function getAllServers() {
|
|
|
4093
4145
|
// ../lsp-core/src/lsp/client-wrapper.ts
|
|
4094
4146
|
function isDirectoryPath(filePath) {
|
|
4095
4147
|
try {
|
|
4096
|
-
return
|
|
4148
|
+
return statSync4(filePath).isDirectory();
|
|
4097
4149
|
} catch {
|
|
4098
4150
|
return false;
|
|
4099
4151
|
}
|
|
@@ -4103,7 +4155,7 @@ function findWorkspaceRoot(filePath) {
|
|
|
4103
4155
|
const abs = resolveReadablePathInsideContext(filePath);
|
|
4104
4156
|
let dir = abs;
|
|
4105
4157
|
if (!isDirectoryPath(dir)) {
|
|
4106
|
-
dir =
|
|
4158
|
+
dir = dirname9(dir);
|
|
4107
4159
|
}
|
|
4108
4160
|
if (!isPathInside(cwd, abs))
|
|
4109
4161
|
return findWorkspaceRootOutsideContext(dir);
|
|
@@ -4112,7 +4164,7 @@ function findWorkspaceRoot(filePath) {
|
|
|
4112
4164
|
while (isPathInside(cwd, dir)) {
|
|
4113
4165
|
const canonicalDir = existingDirectoryInsideContext(dir, cwd);
|
|
4114
4166
|
if (canonicalDir !== undefined) {
|
|
4115
|
-
if (
|
|
4167
|
+
if (existsSync11(join6(dir, GIT_WORKSPACE_MARKER))) {
|
|
4116
4168
|
return canonicalDir;
|
|
4117
4169
|
}
|
|
4118
4170
|
if (nearestPackageRoot === undefined && hasProjectWorkspaceMarker(dir)) {
|
|
@@ -4121,16 +4173,16 @@ function findWorkspaceRoot(filePath) {
|
|
|
4121
4173
|
}
|
|
4122
4174
|
if (dir === cwd)
|
|
4123
4175
|
break;
|
|
4124
|
-
dir =
|
|
4176
|
+
dir = dirname9(dir);
|
|
4125
4177
|
}
|
|
4126
4178
|
return nearestPackageRoot ?? fallbackRoot;
|
|
4127
4179
|
}
|
|
4128
4180
|
function hasProjectWorkspaceMarker(directory) {
|
|
4129
|
-
return PROJECT_WORKSPACE_MARKERS.some((marker) =>
|
|
4181
|
+
return PROJECT_WORKSPACE_MARKERS.some((marker) => existsSync11(join6(directory, marker)));
|
|
4130
4182
|
}
|
|
4131
4183
|
function resolveReadablePathInsideContext(filePath) {
|
|
4132
4184
|
const cwd = contextCwd();
|
|
4133
|
-
const abs =
|
|
4185
|
+
const abs = resolve9(cwd, filePath);
|
|
4134
4186
|
if (isPathInside(cwd, abs))
|
|
4135
4187
|
return abs;
|
|
4136
4188
|
const rebased = rebaseThroughCanonicalAncestor(abs, cwd);
|
|
@@ -4151,12 +4203,12 @@ function rebaseThroughCanonicalAncestor(path, cwd) {
|
|
|
4151
4203
|
let current = path;
|
|
4152
4204
|
const suffix = [];
|
|
4153
4205
|
while (true) {
|
|
4154
|
-
if (
|
|
4155
|
-
const canonical =
|
|
4206
|
+
if (existsSync11(current)) {
|
|
4207
|
+
const canonical = realpathSync7(current);
|
|
4156
4208
|
if (isPathInside(cwd, canonical))
|
|
4157
|
-
return suffix.length === 0 ? canonical :
|
|
4209
|
+
return suffix.length === 0 ? canonical : join6(canonical, ...suffix);
|
|
4158
4210
|
}
|
|
4159
|
-
const parent =
|
|
4211
|
+
const parent = dirname9(current);
|
|
4160
4212
|
if (parent === current)
|
|
4161
4213
|
return;
|
|
4162
4214
|
suffix.unshift(basename3(current));
|
|
@@ -4164,10 +4216,10 @@ function rebaseThroughCanonicalAncestor(path, cwd) {
|
|
|
4164
4216
|
}
|
|
4165
4217
|
}
|
|
4166
4218
|
function existingDirectoryInsideContext(directory, cwd) {
|
|
4167
|
-
if (!
|
|
4219
|
+
if (!existsSync11(directory))
|
|
4168
4220
|
return;
|
|
4169
|
-
const canonical =
|
|
4170
|
-
if (!
|
|
4221
|
+
const canonical = realpathSync7(directory);
|
|
4222
|
+
if (!statSync4(canonical).isDirectory())
|
|
4171
4223
|
return;
|
|
4172
4224
|
return isPathInside(cwd, canonical) ? canonical : undefined;
|
|
4173
4225
|
}
|
|
@@ -4179,7 +4231,7 @@ function nearestExistingDirectoryInsideContext(directory, cwd) {
|
|
|
4179
4231
|
return canonical;
|
|
4180
4232
|
if (current === cwd)
|
|
4181
4233
|
return;
|
|
4182
|
-
current =
|
|
4234
|
+
current = dirname9(current);
|
|
4183
4235
|
}
|
|
4184
4236
|
return;
|
|
4185
4237
|
}
|
|
@@ -4279,7 +4331,7 @@ async function withLspClient(filePath, fn, toolName, options = {}) {
|
|
|
4279
4331
|
throw new LspInvalidPathError("Directory paths are not supported by this LSP tool. " + "Use lsp.diagnostics with a directory path for directory diagnostics.");
|
|
4280
4332
|
}
|
|
4281
4333
|
const ext = effectiveExtension(absPath);
|
|
4282
|
-
const result = findServerForExtension(ext);
|
|
4334
|
+
const result = findServerForExtension(ext, absPath);
|
|
4283
4335
|
if (result.status !== "found") {
|
|
4284
4336
|
throw new LspServerLookupError(formatServerLookupError(result), result);
|
|
4285
4337
|
}
|
|
@@ -4292,25 +4344,153 @@ async function withLspClient(filePath, fn, toolName, options = {}) {
|
|
|
4292
4344
|
return await fn(client, root, absPath);
|
|
4293
4345
|
} catch (err) {
|
|
4294
4346
|
if (allowRetry && READ_ONLY_TOOLS.has(toolName) && isLspDeadConnectionError(err)) {
|
|
4295
|
-
manager.invalidateClient(root, server
|
|
4347
|
+
manager.invalidateClient(root, server, client);
|
|
4296
4348
|
return acquireAndCall(false);
|
|
4297
4349
|
}
|
|
4298
4350
|
if (err instanceof LspRequestTimeoutError) {
|
|
4299
|
-
if (manager.isServerInitializing(root, server
|
|
4351
|
+
if (manager.isServerInitializing(root, server)) {
|
|
4300
4352
|
throw new LspServerInitializingError(err);
|
|
4301
4353
|
}
|
|
4302
4354
|
}
|
|
4303
4355
|
throw err;
|
|
4304
4356
|
} finally {
|
|
4305
|
-
manager.releaseClient(root, server
|
|
4357
|
+
manager.releaseClient(root, server, client);
|
|
4306
4358
|
}
|
|
4307
4359
|
};
|
|
4308
4360
|
return acquireAndCall(true);
|
|
4309
4361
|
}
|
|
4310
4362
|
|
|
4311
4363
|
// ../lsp-core/src/lsp/directory-diagnostics.ts
|
|
4312
|
-
import { existsSync as
|
|
4313
|
-
import { join as
|
|
4364
|
+
import { existsSync as existsSync12, lstatSync as lstatSync4, readdirSync as readdirSync3 } from "node:fs";
|
|
4365
|
+
import { join as join7, resolve as resolve10 } from "node:path";
|
|
4366
|
+
|
|
4367
|
+
// ../lsp-core/src/lsp/directory-group-scan.ts
|
|
4368
|
+
async function scanServedGroups(options) {
|
|
4369
|
+
const { groups, signal } = options;
|
|
4370
|
+
const limit = Math.max(1, options.maxConcurrency);
|
|
4371
|
+
const fileSlots = createSlots(limit);
|
|
4372
|
+
let nextGroup = 0;
|
|
4373
|
+
let startedGroups = 0;
|
|
4374
|
+
let firstError;
|
|
4375
|
+
const runners = Array.from({ length: Math.min(limit, groups.length) }, async () => {
|
|
4376
|
+
for (;; ) {
|
|
4377
|
+
if (signal?.aborted)
|
|
4378
|
+
return;
|
|
4379
|
+
const group = groups[nextGroup];
|
|
4380
|
+
nextGroup += 1;
|
|
4381
|
+
if (group === undefined)
|
|
4382
|
+
return;
|
|
4383
|
+
let client;
|
|
4384
|
+
try {
|
|
4385
|
+
client = await acquireWithinInitTimeout(options, group);
|
|
4386
|
+
} catch (error) {
|
|
4387
|
+
if (signal?.aborted)
|
|
4388
|
+
return;
|
|
4389
|
+
firstError ??= error;
|
|
4390
|
+
options.onGroupUnavailable(group, error instanceof Error ? error.message : String(error));
|
|
4391
|
+
continue;
|
|
4392
|
+
}
|
|
4393
|
+
startedGroups += 1;
|
|
4394
|
+
try {
|
|
4395
|
+
await Promise.all(group.files.map(async (file) => {
|
|
4396
|
+
const release = await fileSlots.acquire();
|
|
4397
|
+
try {
|
|
4398
|
+
if (!signal?.aborted)
|
|
4399
|
+
await options.checkFile(client, file);
|
|
4400
|
+
} finally {
|
|
4401
|
+
release();
|
|
4402
|
+
}
|
|
4403
|
+
}));
|
|
4404
|
+
} finally {
|
|
4405
|
+
options.manager.releaseClient(group.root, group.server, client);
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
});
|
|
4409
|
+
await Promise.all(runners);
|
|
4410
|
+
signal?.throwIfAborted();
|
|
4411
|
+
if (startedGroups === 0 && firstError !== undefined)
|
|
4412
|
+
throw firstError;
|
|
4413
|
+
}
|
|
4414
|
+
async function acquireWithinInitTimeout(options, group) {
|
|
4415
|
+
const { signal } = options;
|
|
4416
|
+
const timers = options.timers ?? realTimerProvider;
|
|
4417
|
+
const controller = new AbortController;
|
|
4418
|
+
const forwardAbort = () => controller.abort(signal?.reason);
|
|
4419
|
+
signal?.addEventListener("abort", forwardAbort, { once: true });
|
|
4420
|
+
if (signal?.aborted)
|
|
4421
|
+
forwardAbort();
|
|
4422
|
+
let timedOut = false;
|
|
4423
|
+
const timer = timers.setTimeout(() => {
|
|
4424
|
+
timedOut = true;
|
|
4425
|
+
controller.abort();
|
|
4426
|
+
}, INIT_TIMEOUT_MS);
|
|
4427
|
+
try {
|
|
4428
|
+
return await options.manager.getClient(group.root, group.server, controller.signal);
|
|
4429
|
+
} catch (error) {
|
|
4430
|
+
if (timedOut && signal?.aborted !== true) {
|
|
4431
|
+
throw new Error(`${group.server.id} did not start within ${INIT_TIMEOUT_MS}ms`);
|
|
4432
|
+
}
|
|
4433
|
+
throw error;
|
|
4434
|
+
} finally {
|
|
4435
|
+
timers.clearTimeout(timer);
|
|
4436
|
+
signal?.removeEventListener("abort", forwardAbort);
|
|
4437
|
+
}
|
|
4438
|
+
}
|
|
4439
|
+
function createSlots(limit) {
|
|
4440
|
+
let free = limit;
|
|
4441
|
+
const waiting = [];
|
|
4442
|
+
const release = () => {
|
|
4443
|
+
const next = waiting.shift();
|
|
4444
|
+
if (next === undefined)
|
|
4445
|
+
free += 1;
|
|
4446
|
+
else
|
|
4447
|
+
next();
|
|
4448
|
+
};
|
|
4449
|
+
return {
|
|
4450
|
+
acquire() {
|
|
4451
|
+
if (free > 0) {
|
|
4452
|
+
free -= 1;
|
|
4453
|
+
return Promise.resolve(release);
|
|
4454
|
+
}
|
|
4455
|
+
return new Promise((resolve) => waiting.push(() => resolve(release)));
|
|
4456
|
+
}
|
|
4457
|
+
};
|
|
4458
|
+
}
|
|
4459
|
+
|
|
4460
|
+
// ../lsp-core/src/lsp/directory-server-groups.ts
|
|
4461
|
+
import { dirname as dirname10 } from "node:path";
|
|
4462
|
+
function groupFilesByClient(files, extension, fixed = {}) {
|
|
4463
|
+
const byDirectory = new Map;
|
|
4464
|
+
const served = new Map;
|
|
4465
|
+
const unserved = new Map;
|
|
4466
|
+
for (const file of files) {
|
|
4467
|
+
const directory = dirname10(file);
|
|
4468
|
+
let resolution = byDirectory.get(directory);
|
|
4469
|
+
if (resolution === undefined) {
|
|
4470
|
+
resolution = resolveDirectory(directory, extension, fixed);
|
|
4471
|
+
byDirectory.set(directory, resolution);
|
|
4472
|
+
}
|
|
4473
|
+
if (resolution.kind === "served") {
|
|
4474
|
+
const group = served.get(resolution.key) ?? { root: resolution.root, server: resolution.server, files: [] };
|
|
4475
|
+
group.files.push(file);
|
|
4476
|
+
served.set(resolution.key, group);
|
|
4477
|
+
} else {
|
|
4478
|
+
const group = unserved.get(resolution.key) ?? { lookup: resolution.lookup, files: [] };
|
|
4479
|
+
group.files.push(file);
|
|
4480
|
+
unserved.set(resolution.key, group);
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
return { served: [...served.values()], unserved: [...unserved.values()] };
|
|
4484
|
+
}
|
|
4485
|
+
function resolveDirectory(directory, extension, fixed) {
|
|
4486
|
+
const lookup = fixed.server === undefined ? findServerForExtension(extension, directory) : { status: "found", server: fixed.server };
|
|
4487
|
+
if (lookup.status !== "found") {
|
|
4488
|
+
const serverId = lookup.status === "not_installed" ? lookup.server.id : "";
|
|
4489
|
+
return { kind: "unserved", key: JSON.stringify([lookup.status, serverId]), lookup };
|
|
4490
|
+
}
|
|
4491
|
+
const root = fixed.workspaceRoot ?? findWorkspaceRoot(directory);
|
|
4492
|
+
return { kind: "served", key: lspClientKey(root, lookup.server), root, server: lookup.server };
|
|
4493
|
+
}
|
|
4314
4494
|
|
|
4315
4495
|
// ../lsp-core/src/lsp/formatters.ts
|
|
4316
4496
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -4440,7 +4620,7 @@ function collectFilesWithExtension(dir, extension, maxFiles) {
|
|
|
4440
4620
|
for (const entry of entries) {
|
|
4441
4621
|
if (files.length >= maxFiles)
|
|
4442
4622
|
return;
|
|
4443
|
-
const fullPath =
|
|
4623
|
+
const fullPath = join7(currentDir, entry);
|
|
4444
4624
|
let stat;
|
|
4445
4625
|
try {
|
|
4446
4626
|
stat = lstatSync4(fullPath);
|
|
@@ -4465,15 +4645,10 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
|
|
|
4465
4645
|
if (!extension.startsWith(".")) {
|
|
4466
4646
|
throw new LspInvalidPathError(`Extension must start with a dot (e.g., ".ts", not "${extension}"). Use ".${extension}" instead.`);
|
|
4467
4647
|
}
|
|
4468
|
-
const absDir =
|
|
4469
|
-
if (!
|
|
4648
|
+
const absDir = resolve10(options.workspaceRoot ?? contextCwd(), directory);
|
|
4649
|
+
if (!existsSync12(absDir)) {
|
|
4470
4650
|
throw new LspInvalidPathError(`Directory does not exist: ${absDir}`);
|
|
4471
4651
|
}
|
|
4472
|
-
const serverResult = options.server === undefined ? findServerForExtension(extension) : { status: "found", server: options.server };
|
|
4473
|
-
if (serverResult.status !== "found") {
|
|
4474
|
-
throw new LspServerLookupError(formatServerLookupError(serverResult));
|
|
4475
|
-
}
|
|
4476
|
-
const server = serverResult.server;
|
|
4477
4652
|
const allFiles = (options.listFiles ?? collectFilesWithExtension)(absDir, extension, maxFiles + 1);
|
|
4478
4653
|
const wasCapped = allFiles.length > maxFiles;
|
|
4479
4654
|
const filesToProcess = allFiles.slice(0, maxFiles);
|
|
@@ -4487,42 +4662,43 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
|
|
|
4487
4662
|
`);
|
|
4488
4663
|
return { output, totalDiagnostics: 0, fileFailures: [] };
|
|
4489
4664
|
}
|
|
4490
|
-
const
|
|
4665
|
+
const groups = groupFilesByClient(filesToProcess, extension, {
|
|
4666
|
+
...options.server === undefined ? {} : { server: options.server },
|
|
4667
|
+
...options.workspaceRoot === undefined ? {} : { workspaceRoot: options.workspaceRoot }
|
|
4668
|
+
});
|
|
4669
|
+
const firstUnserved = groups.unserved[0];
|
|
4670
|
+
if (groups.served.length === 0 && firstUnserved !== undefined) {
|
|
4671
|
+
throw new LspServerLookupError(formatServerLookupError(firstUnserved.lookup));
|
|
4672
|
+
}
|
|
4491
4673
|
const manager = options.manager ?? getLspManager();
|
|
4492
4674
|
const allDiagnostics = [];
|
|
4493
4675
|
const fileErrors = [];
|
|
4494
4676
|
const maxConcurrency = Math.max(1, options.maxConcurrency ?? DIRECTORY_DIAGNOSTICS_MAX_CONCURRENCY);
|
|
4677
|
+
for (const group of groups.unserved) {
|
|
4678
|
+
const error = formatServerLookupError(group.lookup).split(`
|
|
4679
|
+
`)[0] ?? "No LSP server";
|
|
4680
|
+
fileErrors.push(...group.files.map((file) => ({ file, error })));
|
|
4681
|
+
}
|
|
4495
4682
|
options.signal?.throwIfAborted();
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
diagnostic
|
|
4513
|
-
})));
|
|
4514
|
-
} catch (e) {
|
|
4515
|
-
fileErrors.push({
|
|
4516
|
-
file,
|
|
4517
|
-
error: e instanceof Error ? e.message : String(e)
|
|
4518
|
-
});
|
|
4519
|
-
}
|
|
4683
|
+
await scanServedGroups({
|
|
4684
|
+
manager,
|
|
4685
|
+
groups: groups.served,
|
|
4686
|
+
maxConcurrency,
|
|
4687
|
+
...options.signal === undefined ? {} : { signal: options.signal },
|
|
4688
|
+
...options.timers === undefined ? {} : { timers: options.timers },
|
|
4689
|
+
onGroupUnavailable: (group, error) => {
|
|
4690
|
+
fileErrors.push(...group.files.map((file) => ({ file, error })));
|
|
4691
|
+
},
|
|
4692
|
+
checkFile: async (client, file) => {
|
|
4693
|
+
try {
|
|
4694
|
+
const result = await client.diagnostics(file, options.signal);
|
|
4695
|
+
const filtered = filterDiagnosticsBySeverity(result.items, severity);
|
|
4696
|
+
allDiagnostics.push(...filtered.map((diagnostic) => ({ filePath: file, diagnostic })));
|
|
4697
|
+
} catch (e) {
|
|
4698
|
+
fileErrors.push({ file, error: e instanceof Error ? e.message : String(e) });
|
|
4520
4699
|
}
|
|
4521
|
-
}
|
|
4522
|
-
|
|
4523
|
-
} finally {
|
|
4524
|
-
manager.releaseClient(root, server.id);
|
|
4525
|
-
}
|
|
4700
|
+
}
|
|
4701
|
+
});
|
|
4526
4702
|
const displayDiagnostics = allDiagnostics.slice(0, DEFAULT_MAX_DIAGNOSTICS);
|
|
4527
4703
|
const wasDiagCapped = allDiagnostics.length > DEFAULT_MAX_DIAGNOSTICS;
|
|
4528
4704
|
const lines = [
|
|
@@ -4553,7 +4729,7 @@ async function aggregateDiagnosticsForDirectory(directory, extension, severity,
|
|
|
4553
4729
|
|
|
4554
4730
|
// ../lsp-core/src/lsp/infer-extension.ts
|
|
4555
4731
|
import { lstatSync as lstatSync5, readdirSync as readdirSync4 } from "node:fs";
|
|
4556
|
-
import { join as
|
|
4732
|
+
import { join as join8 } from "node:path";
|
|
4557
4733
|
var SKIP_DIRECTORIES2 = new Set(["node_modules", ".git", "dist", "build", ".next", "out"]);
|
|
4558
4734
|
var MAX_SCAN_ENTRIES = 500;
|
|
4559
4735
|
function inferExtensionFromDirectory(directory) {
|
|
@@ -4571,7 +4747,7 @@ function inferExtensionFromDirectory(directory) {
|
|
|
4571
4747
|
for (const entry of entries) {
|
|
4572
4748
|
if (scanned >= MAX_SCAN_ENTRIES)
|
|
4573
4749
|
return;
|
|
4574
|
-
const fullPath =
|
|
4750
|
+
const fullPath = join8(dir, entry);
|
|
4575
4751
|
let stat;
|
|
4576
4752
|
try {
|
|
4577
4753
|
stat = lstatSync5(fullPath);
|
|
@@ -4690,7 +4866,7 @@ function missingDependencyAvailability(error) {
|
|
|
4690
4866
|
}
|
|
4691
4867
|
|
|
4692
4868
|
// ../lsp-core/src/lsp/bun-command-output.ts
|
|
4693
|
-
import { resolve as
|
|
4869
|
+
import { resolve as resolve11 } from "node:path";
|
|
4694
4870
|
var TSC_LINE = /^(.+?)\((\d+),(\d+)\): (error|warning|message) (TS\d+): (.*)$/;
|
|
4695
4871
|
var TSC_SEVERITY = { error: 1, warning: 2, message: 3 };
|
|
4696
4872
|
function parseBunCheckOutput(stdout, cwd) {
|
|
@@ -4701,7 +4877,7 @@ function parseBunCheckOutput(stdout, cwd) {
|
|
|
4701
4877
|
const [, path, lineNumber, column, severity, code, message] = match;
|
|
4702
4878
|
const start = { line: Number(lineNumber) - 1, character: Number(column) - 1 };
|
|
4703
4879
|
results.push({
|
|
4704
|
-
file:
|
|
4880
|
+
file: resolve11(cwd, path ?? ""),
|
|
4705
4881
|
diagnostic: {
|
|
4706
4882
|
range: { start, end: start },
|
|
4707
4883
|
severity: TSC_SEVERITY[severity ?? "error"] ?? 1,
|
|
@@ -4760,9 +4936,9 @@ function parseBunLintJson(stdout) {
|
|
|
4760
4936
|
|
|
4761
4937
|
// ../lsp-core/src/lsp/bun-project-checks.ts
|
|
4762
4938
|
import { spawn as spawn2 } from "node:child_process";
|
|
4763
|
-
import { existsSync as
|
|
4939
|
+
import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync5, rmSync as rmSync2, statSync as statSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
4764
4940
|
import { homedir as homedir2, tmpdir } from "node:os";
|
|
4765
|
-
import { dirname as
|
|
4941
|
+
import { dirname as dirname11, join as join9, resolve as resolve12 } from "node:path";
|
|
4766
4942
|
var BUN_LOCKFILES = ["bun.lock", "bun.lockb", "bunfig.toml"];
|
|
4767
4943
|
var RUNNABLE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".cts", ".cjs", ".js", ".mjs", ".mts"];
|
|
4768
4944
|
var BIN_SUFFIXES = process.platform === "win32" ? [".exe", ".bunx", ".cmd", ""] : [""];
|
|
@@ -4771,18 +4947,18 @@ var UNFORMATTED_PROBE = `const a=1
|
|
|
4771
4947
|
`;
|
|
4772
4948
|
var probeCache = new Map;
|
|
4773
4949
|
function findBunProjectRoot(start, home = homedir2()) {
|
|
4774
|
-
const stopAt =
|
|
4775
|
-
let dir =
|
|
4950
|
+
const stopAt = resolve12(home);
|
|
4951
|
+
let dir = resolve12(start);
|
|
4776
4952
|
for (;; ) {
|
|
4777
4953
|
if (dir === stopAt)
|
|
4778
4954
|
return;
|
|
4779
|
-
if (BUN_LOCKFILES.some((name) =>
|
|
4955
|
+
if (BUN_LOCKFILES.some((name) => existsSync13(join9(dir, name))))
|
|
4780
4956
|
return dir;
|
|
4781
|
-
if (packageManagerIsBun(
|
|
4957
|
+
if (packageManagerIsBun(join9(dir, "package.json")))
|
|
4782
4958
|
return dir;
|
|
4783
|
-
if (
|
|
4959
|
+
if (existsSync13(join9(dir, ".git")))
|
|
4784
4960
|
return;
|
|
4785
|
-
const parent =
|
|
4961
|
+
const parent = dirname11(dir);
|
|
4786
4962
|
if (parent === dir)
|
|
4787
4963
|
return;
|
|
4788
4964
|
dir = parent;
|
|
@@ -4794,7 +4970,7 @@ function packageManagerIsBun(packageJsonPath) {
|
|
|
4794
4970
|
return typeof packageManager === "string" && packageManager.startsWith("bun@");
|
|
4795
4971
|
}
|
|
4796
4972
|
function readJsonObject(path) {
|
|
4797
|
-
if (!
|
|
4973
|
+
if (!existsSync13(path))
|
|
4798
4974
|
return;
|
|
4799
4975
|
try {
|
|
4800
4976
|
const parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
@@ -4805,14 +4981,14 @@ function readJsonObject(path) {
|
|
|
4805
4981
|
}
|
|
4806
4982
|
function isFile(path) {
|
|
4807
4983
|
try {
|
|
4808
|
-
return
|
|
4984
|
+
return statSync5(path).isFile();
|
|
4809
4985
|
} catch {
|
|
4810
4986
|
return false;
|
|
4811
4987
|
}
|
|
4812
4988
|
}
|
|
4813
4989
|
function isDirectory(path) {
|
|
4814
4990
|
try {
|
|
4815
|
-
return
|
|
4991
|
+
return statSync5(path).isDirectory();
|
|
4816
4992
|
} catch {
|
|
4817
4993
|
return false;
|
|
4818
4994
|
}
|
|
@@ -4820,35 +4996,35 @@ function isDirectory(path) {
|
|
|
4820
4996
|
function projectShadowsBunCommand(command, cwd) {
|
|
4821
4997
|
const packageJsonDir = nearestPackageJsonDir(cwd);
|
|
4822
4998
|
if (packageJsonDir !== undefined) {
|
|
4823
|
-
const scripts = readJsonObject(
|
|
4999
|
+
const scripts = readJsonObject(join9(packageJsonDir, "package.json"))?.["scripts"];
|
|
4824
5000
|
if (scripts !== null && typeof scripts === "object" && typeof scripts[command] === "string") {
|
|
4825
5001
|
return true;
|
|
4826
5002
|
}
|
|
4827
5003
|
}
|
|
4828
5004
|
if (command === "check")
|
|
4829
5005
|
return false;
|
|
4830
|
-
const base =
|
|
5006
|
+
const base = join9(cwd, command);
|
|
4831
5007
|
if (isFile(base) || RUNNABLE_EXTENSIONS.some((extension) => isFile(`${base}${extension}`)))
|
|
4832
5008
|
return true;
|
|
4833
|
-
if (isDirectory(base) && (isFile(
|
|
5009
|
+
if (isDirectory(base) && (isFile(join9(base, "package.json")) || RUNNABLE_EXTENSIONS.some((extension) => isFile(join9(base, `index${extension}`))))) {
|
|
4834
5010
|
return true;
|
|
4835
5011
|
}
|
|
4836
|
-
let dir =
|
|
5012
|
+
let dir = resolve12(cwd);
|
|
4837
5013
|
for (;; ) {
|
|
4838
|
-
if (BIN_SUFFIXES.some((suffix) =>
|
|
5014
|
+
if (BIN_SUFFIXES.some((suffix) => existsSync13(join9(dir, "node_modules", ".bin", `${command}${suffix}`))))
|
|
4839
5015
|
return true;
|
|
4840
|
-
const parent =
|
|
5016
|
+
const parent = dirname11(dir);
|
|
4841
5017
|
if (parent === dir)
|
|
4842
5018
|
return false;
|
|
4843
5019
|
dir = parent;
|
|
4844
5020
|
}
|
|
4845
5021
|
}
|
|
4846
5022
|
function nearestPackageJsonDir(start) {
|
|
4847
|
-
let dir =
|
|
5023
|
+
let dir = resolve12(start);
|
|
4848
5024
|
for (;; ) {
|
|
4849
|
-
if (
|
|
5025
|
+
if (existsSync13(join9(dir, "package.json")))
|
|
4850
5026
|
return dir;
|
|
4851
|
-
const parent =
|
|
5027
|
+
const parent = dirname11(dir);
|
|
4852
5028
|
if (parent === dir)
|
|
4853
5029
|
return;
|
|
4854
5030
|
dir = parent;
|
|
@@ -4856,7 +5032,7 @@ function nearestPackageJsonDir(start) {
|
|
|
4856
5032
|
}
|
|
4857
5033
|
function binaryIdentity(bunPath) {
|
|
4858
5034
|
try {
|
|
4859
|
-
const stats =
|
|
5035
|
+
const stats = statSync5(bunPath);
|
|
4860
5036
|
return `${stats.mtimeMs}:${stats.size}`;
|
|
4861
5037
|
} catch {
|
|
4862
5038
|
return "missing";
|
|
@@ -4876,7 +5052,7 @@ function bunHasCommand(bunPath, command, timeoutMs = PROBE_TIMEOUT_MS) {
|
|
|
4876
5052
|
return probe;
|
|
4877
5053
|
}
|
|
4878
5054
|
async function probeOnce(bunPath, command, timeoutMs) {
|
|
4879
|
-
const emptyDir = mkdtempSync(
|
|
5055
|
+
const emptyDir = mkdtempSync(join9(tmpdir(), "omo-bun-probe-"));
|
|
4880
5056
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
4881
5057
|
try {
|
|
4882
5058
|
const help = await runBunCommand(bunPath, [command, "--help"], emptyDir, timeout);
|
|
@@ -4886,7 +5062,7 @@ async function probeOnce(bunPath, command, timeoutMs) {
|
|
|
4886
5062
|
return false;
|
|
4887
5063
|
if (command !== "format")
|
|
4888
5064
|
return true;
|
|
4889
|
-
const probeFile =
|
|
5065
|
+
const probeFile = join9(emptyDir, "probe.ts");
|
|
4890
5066
|
writeFileSync3(probeFile, UNFORMATTED_PROBE);
|
|
4891
5067
|
const write = await runBunCommand(bunPath, ["format", "--write", "probe.ts"], emptyDir, timeout);
|
|
4892
5068
|
if (write.exitCode === null)
|