@mrclrchtr/supi-review 6.3.0 → 7.0.0
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/node_modules/@mrclrchtr/supi-agent-runtime/node_modules/@mrclrchtr/supi-core/README.md +8 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-agent-runtime/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +10 -3
- package/node_modules/@mrclrchtr/supi-agent-runtime/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-agent-runtime/node_modules/@mrclrchtr/supi-core/src/llm.ts +141 -16
- package/node_modules/@mrclrchtr/supi-agent-runtime/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-agent-runtime/src/provider-authority.ts +8 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/README.md +164 -82
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +8 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/README.md +8 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +10 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/src/llm.ts +141 -16
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/README.md +35 -13
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +8 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/README.md +8 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +10 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/llm.ts +141 -16
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/index.js +3 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/legacy.js +3 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/ignore/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/api.ts +16 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +43 -35
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +83 -17
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +108 -92
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-evidence.ts +44 -82
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +3 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-publication.ts +9 -68
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-pull.ts +45 -58
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +230 -331
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +201 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +129 -70
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-typescript.ts +395 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-waiters.ts +8 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +685 -183
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +60 -60
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-request-enrollment.ts +75 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-semantic-input-barrier.ts +443 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-semantic-input-errors.ts +30 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client-semantic-input-file.ts +15 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +290 -37
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +72 -16
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +1 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +30 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/workspace-sentinels.ts +4 -32
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/workspace-sources.ts +108 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-diagnostics.ts +10 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-process-crash-report.ts +50 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-recovery.ts +11 -7
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +770 -56
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +3 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +37 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +48 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +50 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +8 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +8 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +10 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/llm.ts +141 -16
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/src/provider/tree-sitter-provider.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callee-display-name.ts +165 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +67 -9
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +19 -18
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/yaml/browser/dist/nodes/Alias.js +25 -23
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/yaml/dist/compose/resolve-flow-scalar.js +19 -18
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/yaml/dist/nodes/Alias.js +25 -23
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/yaml/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/package.json +5 -5
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/health/diagnostics.ts +1 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/health/file-scope.ts +4 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/health/server-status.ts +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/relations/callees.ts +17 -8
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/relations/implementations.ts +1 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/relations/references.ts +8 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/relations/types.ts +6 -30
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/target/anchored.ts +9 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/target/symbol.ts +29 -11
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/analysis/target/types.ts +14 -6
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/api.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/graph/collect.ts +18 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/health-refresh.ts +27 -11
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/health-types.ts +21 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/health-workflow.ts +28 -22
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/orientation-types.ts +5 -6
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/orientation-workflow.ts +10 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/session.ts +12 -5
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/session/target-workflow.ts +9 -6
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/substrate/lsp/maintenance.ts +53 -47
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/substrate/lsp/source-tracking.ts +252 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_find/guidance.ts +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_find/spec.ts +5 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_find/tui.ts +7 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/details.ts +32 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/display.ts +54 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/format.ts +60 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/guidance.ts +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/markdown.ts +76 -198
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/read-next.ts +65 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/result.ts +118 -83
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_graph/tui.ts +216 -54
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/guidance.ts +3 -5
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/markdown.ts +90 -57
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/refresh-outcome.ts +51 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/refresh-status.ts +130 -43
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/scope.ts +78 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/spec.ts +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_health/tui.ts +29 -38
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_inspect/guidance.ts +5 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_inspect/tui.ts +7 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_orientation/guidance.ts +3 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_orientation/result.ts +31 -8
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_orientation/tui.ts +26 -5
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_refactor_apply/guidance.ts +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_refactor_apply/tui.ts +7 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_refactor_plan/guidance.ts +3 -5
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_refactor_plan/tui.ts +7 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_resolve/guidance.ts +3 -5
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_resolve/result.ts +13 -10
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/code_resolve/tui.ts +18 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/guidance.ts +11 -9
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/infra/truncate.ts +39 -13
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/result/candidate-row.ts +27 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/result/errors.ts +21 -6
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/result/types.ts +7 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/tool/schemas.ts +5 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/types/execution.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/types/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/ui/tui/candidate-legacy-body.ts +69 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/ui/tui/candidate-selection.ts +366 -0
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/ui/tui/common.ts +26 -31
- package/node_modules/@mrclrchtr/supi-code-intelligence/src/ui/tui/execution-error.ts +92 -0
- package/node_modules/@mrclrchtr/supi-core/README.md +8 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +10 -3
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/llm.ts +141 -16
- package/package.json +4 -4
- package/src/tool/review_audit/guidance.ts +3 -7
- package/src/tool/review_output/guidance.ts +2 -3
- package/src/tool/review_run/guidance.ts +4 -9
- package/src/tool/review_run/input-schema.ts +10 -15
- package/src/tool/review_run/schemas.ts +8 -12
|
@@ -1,12 +1,131 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
Api,
|
|
4
|
+
AssistantMessage,
|
|
5
|
+
Context,
|
|
6
|
+
Model,
|
|
7
|
+
ModelsApiStreamOptions,
|
|
8
|
+
ProviderHeaders,
|
|
9
|
+
} from "@earendil-works/pi-ai";
|
|
2
10
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
11
|
import type { TSchema } from "typebox";
|
|
4
12
|
import { Value } from "typebox/value";
|
|
5
13
|
|
|
6
14
|
// Shared LLM utilities for SuPi extensions.
|
|
7
15
|
//
|
|
8
|
-
// Provides retry logic, structured LLM call helpers,
|
|
9
|
-
// common patterns for extensions that interact with AI models.
|
|
16
|
+
// Provides PI-owned model requests, retry logic, structured LLM call helpers,
|
|
17
|
+
// and other common patterns for extensions that interact with AI models.
|
|
18
|
+
|
|
19
|
+
const MODEL_REQUEST_NAMESPACE = "supi-direct-model-request-v1";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link completeModelRequest}.
|
|
23
|
+
*
|
|
24
|
+
* Authentication, provider environment, and session identity stay under PI
|
|
25
|
+
* control. The feature supplies a stable scope for its prompt stream.
|
|
26
|
+
*/
|
|
27
|
+
export type CompleteModelRequestOptions<TApi extends Api = Api> = Omit<
|
|
28
|
+
ModelsApiStreamOptions<TApi>,
|
|
29
|
+
"apiKey" | "env" | "sessionId"
|
|
30
|
+
> & {
|
|
31
|
+
/** Stable feature scope. Do not include prompt, turn, or retry data. */
|
|
32
|
+
affinityScope: string;
|
|
33
|
+
/** PI owns these fields, including for APIs with open-ended option types. */
|
|
34
|
+
apiKey?: never;
|
|
35
|
+
env?: never;
|
|
36
|
+
sessionId?: never;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function createModelRequestAffinityId(
|
|
40
|
+
sessionId: string,
|
|
41
|
+
affinityScope: string,
|
|
42
|
+
model: Model<Api>,
|
|
43
|
+
): string {
|
|
44
|
+
const material = JSON.stringify([
|
|
45
|
+
MODEL_REQUEST_NAMESPACE,
|
|
46
|
+
sessionId,
|
|
47
|
+
affinityScope,
|
|
48
|
+
model.provider,
|
|
49
|
+
model.id,
|
|
50
|
+
]);
|
|
51
|
+
const digest = createHash("sha256").update(material, "utf8").digest("hex");
|
|
52
|
+
return `supi-${digest.slice(0, 56)}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isOpenCodeModel(model: Model<Api>): boolean {
|
|
56
|
+
if (model.provider === "opencode" || model.provider === "opencode-go") return true;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
return new URL(model.baseUrl).hostname === "opencode.ai";
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function hasHeader(headers: ProviderHeaders, name: string): boolean {
|
|
66
|
+
const lowerName = name.toLowerCase();
|
|
67
|
+
return Object.keys(headers).some((headerName) => headerName.toLowerCase() === lowerName);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function addOpenCodeDefaultHeaders(
|
|
71
|
+
model: Model<Api>,
|
|
72
|
+
affinityId: string,
|
|
73
|
+
headers: ProviderHeaders,
|
|
74
|
+
): ProviderHeaders {
|
|
75
|
+
if (!isOpenCodeModel(model)) return headers;
|
|
76
|
+
|
|
77
|
+
const result = { ...headers };
|
|
78
|
+
if (!hasHeader(result, "x-opencode-session")) {
|
|
79
|
+
result["x-opencode-session"] = affinityId;
|
|
80
|
+
}
|
|
81
|
+
if (!hasHeader(result, "x-opencode-client")) {
|
|
82
|
+
result["x-opencode-client"] = "pi";
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Complete a direct request through PI's model registry.
|
|
89
|
+
*
|
|
90
|
+
* PI resolves authentication, provider headers, environment, and the
|
|
91
|
+
* effective endpoint. This helper adds one stable opaque session identity for
|
|
92
|
+
* the feature prompt stream and applies the OpenCode compatibility defaults.
|
|
93
|
+
* It does not retry, validate output, or present errors.
|
|
94
|
+
*
|
|
95
|
+
* When `maxTokens` is omitted, the underlying registry receives no explicit
|
|
96
|
+
* output cap. A caller that needs the selected model's declared cap can pass
|
|
97
|
+
* `maxTokens: model.maxTokens` without importing PI internals.
|
|
98
|
+
*/
|
|
99
|
+
export async function completeModelRequest<TApi extends Api>(
|
|
100
|
+
ctx: ExtensionContext,
|
|
101
|
+
model: Model<TApi>,
|
|
102
|
+
context: Context,
|
|
103
|
+
options: CompleteModelRequestOptions<TApi>,
|
|
104
|
+
): Promise<AssistantMessage> {
|
|
105
|
+
const { affinityScope, transformHeaders: callerTransformHeaders, ...requestOptions } = options;
|
|
106
|
+
const safeRequestOptions = { ...requestOptions };
|
|
107
|
+
delete safeRequestOptions.apiKey;
|
|
108
|
+
delete safeRequestOptions.env;
|
|
109
|
+
delete safeRequestOptions.sessionId;
|
|
110
|
+
|
|
111
|
+
const affinityId = createModelRequestAffinityId(
|
|
112
|
+
ctx.sessionManager.getSessionId(),
|
|
113
|
+
affinityScope,
|
|
114
|
+
model,
|
|
115
|
+
);
|
|
116
|
+
const transformHeaders = async (headers: ProviderHeaders): Promise<ProviderHeaders> => {
|
|
117
|
+
const transformed = callerTransformHeaders ? await callerTransformHeaders(headers) : headers;
|
|
118
|
+
return addOpenCodeDefaultHeaders(model, affinityId, transformed);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// Restore PI's conditional provider-option type after removing owned fields.
|
|
122
|
+
return ctx.modelRegistry.complete(model, context, {
|
|
123
|
+
...safeRequestOptions,
|
|
124
|
+
signal: safeRequestOptions.signal ?? ctx.signal,
|
|
125
|
+
sessionId: affinityId,
|
|
126
|
+
transformHeaders,
|
|
127
|
+
} as unknown as ModelsApiStreamOptions<TApi>);
|
|
128
|
+
}
|
|
10
129
|
|
|
11
130
|
/**
|
|
12
131
|
* Options for {@link withRetry}.
|
|
@@ -122,6 +241,8 @@ export function extractJsonFromResponse<T extends TSchema>(
|
|
|
122
241
|
export interface CallWithJsonResponseOptions {
|
|
123
242
|
/** The prompt to send to the LLM. */
|
|
124
243
|
prompt: string;
|
|
244
|
+
/** Stable feature scope for request affinity. Do not include prompt or retry data. */
|
|
245
|
+
affinityScope: string;
|
|
125
246
|
/** Optional data context appended to the prompt. */
|
|
126
247
|
dataContext?: string;
|
|
127
248
|
/** Maximum tokens for the response. Default: 4096 */
|
|
@@ -135,8 +256,9 @@ export interface CallWithJsonResponseOptions {
|
|
|
135
256
|
/**
|
|
136
257
|
* Call the LLM with a prompt and validate the JSON response against a TypeBox schema.
|
|
137
258
|
*
|
|
138
|
-
* Handles model resolution,
|
|
139
|
-
*
|
|
259
|
+
* Handles model resolution, retry via `withRetry`, text extraction, JSON
|
|
260
|
+
* matching, and TypeBox validation. The request itself stays under PI
|
|
261
|
+
* registry authority through {@link completeModelRequest}.
|
|
140
262
|
*
|
|
141
263
|
* Returns `null` when:
|
|
142
264
|
* - No model is available
|
|
@@ -145,7 +267,7 @@ export interface CallWithJsonResponseOptions {
|
|
|
145
267
|
* - JSON doesn't match the schema
|
|
146
268
|
* - The request is aborted
|
|
147
269
|
*
|
|
148
|
-
* @param ctx - The extension context for model
|
|
270
|
+
* @param ctx - The extension context for model selection and PI registry access.
|
|
149
271
|
* @param options - Call options including prompt, schema, and retry config.
|
|
150
272
|
* @param schema - TypeBox schema to validate the JSON response against.
|
|
151
273
|
* @returns The parsed and validated result, or `null`.
|
|
@@ -155,14 +277,18 @@ export async function callWithJsonResponse<T extends TSchema>(
|
|
|
155
277
|
options: CallWithJsonResponseOptions,
|
|
156
278
|
schema: T,
|
|
157
279
|
): Promise<{ parsed: import("typebox").Static<T> } | null> {
|
|
158
|
-
const {
|
|
280
|
+
const {
|
|
281
|
+
prompt,
|
|
282
|
+
affinityScope,
|
|
283
|
+
dataContext,
|
|
284
|
+
maxTokens = 4096,
|
|
285
|
+
systemPrompt = "",
|
|
286
|
+
retries = 2,
|
|
287
|
+
} = options;
|
|
159
288
|
|
|
160
289
|
const model = ctx.model ?? ctx.modelRegistry.getAvailable()[0] ?? null;
|
|
161
290
|
if (!model) return null;
|
|
162
291
|
|
|
163
|
-
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
164
|
-
if (!auth.ok || !auth.apiKey) return null;
|
|
165
|
-
|
|
166
292
|
const fullPrompt = dataContext
|
|
167
293
|
? `${prompt}
|
|
168
294
|
|
|
@@ -171,8 +297,9 @@ ${dataContext}`
|
|
|
171
297
|
: prompt;
|
|
172
298
|
|
|
173
299
|
const response = await withRetry(
|
|
174
|
-
async () =>
|
|
175
|
-
|
|
300
|
+
async () =>
|
|
301
|
+
completeModelRequest(
|
|
302
|
+
ctx,
|
|
176
303
|
model,
|
|
177
304
|
{
|
|
178
305
|
systemPrompt,
|
|
@@ -185,13 +312,11 @@ ${dataContext}`
|
|
|
185
312
|
],
|
|
186
313
|
},
|
|
187
314
|
{
|
|
188
|
-
|
|
189
|
-
headers: auth.headers,
|
|
315
|
+
affinityScope,
|
|
190
316
|
signal: ctx.signal,
|
|
191
317
|
maxTokens,
|
|
192
318
|
},
|
|
193
|
-
)
|
|
194
|
-
},
|
|
319
|
+
),
|
|
195
320
|
{ retries, baseDelayMs: 1000, signal: ctx.signal },
|
|
196
321
|
);
|
|
197
322
|
|
|
@@ -16,7 +16,9 @@ const REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/
|
|
|
16
16
|
// A line of only spaces is blank -- the trailing-space trimming empties it --
|
|
17
17
|
// but a line holding a tab is a pattern for a tab-named path, since git
|
|
18
18
|
// never trims a tab.
|
|
19
|
-
|
|
19
|
+
// A leading BOM is removed during compilation, so reject a line that would
|
|
20
|
+
// become empty after removing it and trimming spaces.
|
|
21
|
+
const REGEX_TEST_BLANK_LINE = /^\uFEFF? *$/
|
|
20
22
|
const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/
|
|
21
23
|
const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/
|
|
22
24
|
const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/
|
|
@@ -29,7 +29,9 @@ var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
|
29
29
|
// A line of only spaces is blank -- the trailing-space trimming empties it --
|
|
30
30
|
// but a line holding a tab is a pattern for a tab-named path, since git
|
|
31
31
|
// never trims a tab.
|
|
32
|
-
|
|
32
|
+
// A leading BOM is removed during compilation, so reject a line that would
|
|
33
|
+
// become empty after removing it and trimming spaces.
|
|
34
|
+
var REGEX_TEST_BLANK_LINE = /^\uFEFF? *$/;
|
|
33
35
|
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
34
36
|
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
35
37
|
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-lsp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Language Server Protocol runtime for SuPi code intelligence",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"vscode-jsonrpc": "^9.0.0",
|
|
38
38
|
"vscode-languageserver-protocol": "^3.18.0",
|
|
39
39
|
"vscode-languageserver-types": "^3.18.0",
|
|
40
|
-
"@mrclrchtr/supi-code-runtime": "
|
|
41
|
-
"@mrclrchtr/supi-core": "
|
|
40
|
+
"@mrclrchtr/supi-code-runtime": "7.0.0",
|
|
41
|
+
"@mrclrchtr/supi-core": "7.0.0"
|
|
42
42
|
},
|
|
43
43
|
"bundledDependencies": [
|
|
44
44
|
"@mrclrchtr/supi-code-runtime",
|
package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/src/api.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Public API surface for the LSP session-scoped service.
|
|
2
2
|
|
|
3
|
+
export { isMissingFileError } from "./client/client-file-state.ts";
|
|
3
4
|
export { type LoadConfigOptions, loadConfig } from "./config/config.ts";
|
|
4
5
|
export type { LspSettings } from "./config/lsp-settings.ts";
|
|
5
6
|
export { loadLspSettings } from "./config/lsp-settings.ts";
|
|
@@ -11,6 +12,7 @@ export {
|
|
|
11
12
|
invalidateTsconfigCacheForConfig,
|
|
12
13
|
invalidateTsconfigCacheForConfigDir,
|
|
13
14
|
isProjectConfigFileName,
|
|
15
|
+
isTsconfigApplicableFile,
|
|
14
16
|
type ScopeDecisionBasis,
|
|
15
17
|
} from "./config/tsconfig-scope.ts";
|
|
16
18
|
export type {
|
|
@@ -41,6 +43,12 @@ export {
|
|
|
41
43
|
type WorkspaceSentinelScanOptions,
|
|
42
44
|
type WorkspaceSentinelSyncResult,
|
|
43
45
|
} from "./diagnostics/workspace-sentinels.ts";
|
|
46
|
+
export {
|
|
47
|
+
scanWorkspaceSources,
|
|
48
|
+
type WorkspaceSourceInventory,
|
|
49
|
+
type WorkspaceSourceInventoryReason,
|
|
50
|
+
type WorkspaceSourceScanOptions,
|
|
51
|
+
} from "./diagnostics/workspace-sources.ts";
|
|
44
52
|
export { raceReadinessValue, raceRequestControl } from "./session/readiness.ts";
|
|
45
53
|
export type {
|
|
46
54
|
LspControllerState,
|
|
@@ -51,6 +59,8 @@ export type {
|
|
|
51
59
|
} from "./session/runtime-controller.ts";
|
|
52
60
|
export { LspRuntimeController } from "./session/runtime-controller.ts";
|
|
53
61
|
export type {
|
|
62
|
+
BulkTrackFileOutcome,
|
|
63
|
+
BulkTrackFilesResult,
|
|
54
64
|
DiagnosticEvidenceDocument,
|
|
55
65
|
DiagnosticEvidenceStatus,
|
|
56
66
|
DiagnosticEvidenceSummary,
|
|
@@ -63,6 +73,10 @@ export type {
|
|
|
63
73
|
RecoverDiagnosticsResult,
|
|
64
74
|
RoutedMutationResponse,
|
|
65
75
|
SemanticReadinessResult,
|
|
76
|
+
StartupRetryEntry,
|
|
77
|
+
StartupRetryNextAction,
|
|
78
|
+
StartupRetryOutcome,
|
|
79
|
+
StartupRetryReport,
|
|
66
80
|
WorkspaceDiagnosticReport,
|
|
67
81
|
WorkspaceDiagnosticSnapshot,
|
|
68
82
|
WorkspaceDiagnosticSummaryEntry,
|
|
@@ -73,12 +87,14 @@ export type {
|
|
|
73
87
|
export {
|
|
74
88
|
clearWorkspaceLspRuntime,
|
|
75
89
|
emptyProcessCrashRecoveryReport,
|
|
90
|
+
emptyStartupRetryReport,
|
|
76
91
|
getWorkspaceLspRuntime,
|
|
77
92
|
MAX_PROCESS_CRASH_RECOVERY_ENTRIES,
|
|
78
93
|
setWorkspaceLspRuntimeState,
|
|
79
94
|
waitForWorkspaceLspRuntime,
|
|
80
95
|
} from "./session/runtime-registry.ts";
|
|
81
96
|
export { scanMissingServers } from "./session/scanner.ts";
|
|
97
|
+
export { MAX_BULK_TRACK_FILES } from "./session/workspace-lsp-runtime.ts";
|
|
82
98
|
export {
|
|
83
99
|
AUTOMATIC_LSP_EXCLUDED_DIRECTORIES,
|
|
84
100
|
type AutomaticLspPathPolicy,
|
|
@@ -23,42 +23,51 @@ interface ApplyPushOptions {
|
|
|
23
23
|
/**
|
|
24
24
|
* Apply one valid push publication.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* state. The first valid publication for a synchronization is tentative; a
|
|
34
|
-
* later valid publication for the same synchronization ID and evidence
|
|
35
|
-
* revision promotes the cache to confirmed (ADR 0021).
|
|
26
|
+
* Ambient pushes are observations, not confirmation evidence. Fail-closed
|
|
27
|
+
* policy (ADR 0020): unversioned pushes are rejected for closed and
|
|
28
|
+
* untracked URIs and for arrivals before the URI's sync moment; versioned
|
|
29
|
+
* pushes for a URI closed by a lifecycle operation are rejected because their
|
|
30
|
+
* version cannot be verified. An unversioned push that arrives after the sync
|
|
31
|
+
* moment of an open document is accepted and re-stamped with that document's
|
|
32
|
+
* current synchronization state. Publication counts remain telemetry only.
|
|
36
33
|
*/
|
|
37
|
-
export function applyPushDiagnostics(options: ApplyPushOptions): {
|
|
38
|
-
accepted:
|
|
39
|
-
promoted: boolean;
|
|
40
|
-
} {
|
|
41
|
-
if (!isValidPublishDiagnosticsParams(options.params)) return { accepted: false, promoted: false };
|
|
34
|
+
export function applyPushDiagnostics(options: ApplyPushOptions): { accepted: boolean } {
|
|
35
|
+
if (!isValidPublishDiagnosticsParams(options.params)) return { accepted: false };
|
|
42
36
|
const openDocument = options.openDocuments.get(options.params.uri);
|
|
43
37
|
if (options.params.version !== undefined) {
|
|
44
|
-
if (!Number.isInteger(options.params.version)) return { accepted: false
|
|
38
|
+
if (!Number.isInteger(options.params.version)) return { accepted: false };
|
|
45
39
|
if (openDocument && options.params.version !== openDocument.version) {
|
|
46
|
-
return { accepted: false
|
|
40
|
+
return { accepted: false };
|
|
47
41
|
}
|
|
48
|
-
if (!openDocument && options.closedVersionedBarrier)
|
|
49
|
-
return { accepted: false, promoted: false };
|
|
42
|
+
if (!openDocument && options.closedVersionedBarrier) return { accepted: false };
|
|
50
43
|
}
|
|
51
|
-
if (!Array.isArray(options.params.diagnostics)) return { accepted: false
|
|
52
|
-
if (!acceptUnversionedPush(options, openDocument)) return { accepted: false
|
|
53
|
-
const entry = buildPushCacheEntry(options, openDocument);
|
|
44
|
+
if (!Array.isArray(options.params.diagnostics)) return { accepted: false };
|
|
45
|
+
if (!acceptUnversionedPush(options, openDocument)) return { accepted: false };
|
|
54
46
|
const previous = options.store.get(options.params.uri);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
// A request-confirmed result owns the synchronization. Ambient pushes may
|
|
48
|
+
// still release waiters and telemetry, but they must not replace that result.
|
|
49
|
+
if (isCurrentRequestEvidence(previous, openDocument, options.evidenceRevision)) {
|
|
50
|
+
return { accepted: true };
|
|
51
|
+
}
|
|
52
|
+
const entry = buildPushCacheEntry(options, openDocument);
|
|
60
53
|
options.store.set(options.params.uri, entry);
|
|
61
|
-
return { accepted: true
|
|
54
|
+
return { accepted: true };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Test whether a request result still owns the current document generation. */
|
|
58
|
+
function isCurrentRequestEvidence(
|
|
59
|
+
entry: DiagnosticCacheEntry | undefined,
|
|
60
|
+
document: OpenDocumentState | undefined,
|
|
61
|
+
evidenceRevision: number,
|
|
62
|
+
): boolean {
|
|
63
|
+
return Boolean(
|
|
64
|
+
entry &&
|
|
65
|
+
entry.source !== "push" &&
|
|
66
|
+
document &&
|
|
67
|
+
entry.synchronizationId === document.synchronizationId &&
|
|
68
|
+
entry.evidenceRevision === evidenceRevision &&
|
|
69
|
+
document.evidenceRevision === evidenceRevision,
|
|
70
|
+
);
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
/** Gate one unversioned push publication against the sync-moment policy. */
|
|
@@ -77,9 +86,9 @@ function acceptUnversionedPush(
|
|
|
77
86
|
* Build the stored entry for one accepted push publication.
|
|
78
87
|
*
|
|
79
88
|
* Time-gated unversioned acceptance re-stamps the entry with the open
|
|
80
|
-
* document's current synchronization state
|
|
81
|
-
*
|
|
82
|
-
*
|
|
89
|
+
* document's current synchronization state. Versioned pushes keep the
|
|
90
|
+
* current-revision check: a version match alone does not prove a current
|
|
91
|
+
* generation.
|
|
83
92
|
*/
|
|
84
93
|
function buildPushCacheEntry(
|
|
85
94
|
options: ApplyPushOptions,
|
|
@@ -92,9 +101,8 @@ function buildPushCacheEntry(
|
|
|
92
101
|
const evidenceRevision = openDocument?.evidenceRevision;
|
|
93
102
|
const previous = options.store.get(options.params.uri);
|
|
94
103
|
// A later valid publication for the same synchronization ID and evidence
|
|
95
|
-
// revision continues the entry's publication count
|
|
96
|
-
//
|
|
97
|
-
// is promoted. Any other publication starts a fresh count.
|
|
104
|
+
// revision continues the entry's publication count for telemetry. Any
|
|
105
|
+
// other publication starts a fresh count.
|
|
98
106
|
const sameSynchronization =
|
|
99
107
|
synchronizationId !== undefined &&
|
|
100
108
|
previous?.synchronizationId === synchronizationId &&
|
|
@@ -233,7 +241,7 @@ function collectCachedDiagnostics(options: {
|
|
|
233
241
|
options.evidenceRevision,
|
|
234
242
|
);
|
|
235
243
|
// A current tentative error is useful partial evidence. Keep its entry
|
|
236
|
-
// non-current so it cannot establish a clean or settled result
|
|
244
|
+
// non-current so it cannot establish a clean or settled result.
|
|
237
245
|
const tentative = entryCurrent && isTentativePushEntry(entry);
|
|
238
246
|
const confirmed = entryCurrent && !tentative;
|
|
239
247
|
current &&= confirmed;
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
// support is enabled only while the static provider shape is valid or the
|
|
7
7
|
// dynamic set for `textDocument/diagnostic` is non-empty.
|
|
8
8
|
|
|
9
|
+
import { posix as posixPath } from "node:path";
|
|
10
|
+
import { uriToFile } from "@mrclrchtr/supi-core/path";
|
|
11
|
+
import { detectLanguageId } from "../utils.ts";
|
|
12
|
+
|
|
9
13
|
/** LSP method for document diagnostic pulls. */
|
|
10
14
|
export const DOCUMENT_DIAGNOSTIC_METHOD = "textDocument/diagnostic";
|
|
11
15
|
|
|
@@ -27,13 +31,67 @@ export function isValidDiagnosticOptions(value: unknown): boolean {
|
|
|
27
31
|
if (typeof value.interFileDependencies !== "boolean") return false;
|
|
28
32
|
if (typeof value.workspaceDiagnostics !== "boolean") return false;
|
|
29
33
|
if (value.identifier !== undefined && typeof value.identifier !== "string") return false;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
return isValidDocumentSelector(value.documentSelector);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Test whether an optional LSP document selector has a valid shape. */
|
|
38
|
+
export function isValidDocumentSelector(value: unknown): boolean {
|
|
39
|
+
if (value === undefined || value === null) return true;
|
|
40
|
+
return (
|
|
41
|
+
Array.isArray(value) &&
|
|
42
|
+
value.every((entry) => {
|
|
43
|
+
if (typeof entry === "string") return entry.length > 0;
|
|
44
|
+
if (!isRecord(entry)) return false;
|
|
45
|
+
return (
|
|
46
|
+
(entry.language === undefined || typeof entry.language === "string") &&
|
|
47
|
+
(entry.scheme === undefined || typeof entry.scheme === "string") &&
|
|
48
|
+
(entry.pattern === undefined || typeof entry.pattern === "string")
|
|
49
|
+
);
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Match one valid document selector against a file URI. */
|
|
55
|
+
export function isDocumentSelectorApplicable(selector: unknown, uri: string): boolean {
|
|
56
|
+
if (selector === undefined || selector === null) return true;
|
|
57
|
+
if (!isValidDocumentSelector(selector)) return false;
|
|
58
|
+
if (!Array.isArray(selector) || selector.length === 0) return false;
|
|
59
|
+
const language = detectLanguageId(uriToFile(uri));
|
|
60
|
+
const scheme = readUriScheme(uri);
|
|
61
|
+
const filePath = uriToFile(uri).replaceAll("\\", "/");
|
|
62
|
+
return selector.some((entry) => {
|
|
63
|
+
if (typeof entry === "string") return entry === language;
|
|
64
|
+
if (!isRecord(entry)) return false;
|
|
65
|
+
if (entry.language !== undefined && entry.language !== language) return false;
|
|
66
|
+
if (entry.scheme !== undefined && entry.scheme !== scheme) return false;
|
|
67
|
+
const pattern = entry.pattern;
|
|
68
|
+
if (pattern === undefined) return true;
|
|
69
|
+
if (typeof pattern !== "string") return false;
|
|
70
|
+
const basename = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
71
|
+
return globMatches(pattern, filePath) || globMatches(pattern, basename);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function readUriScheme(uri: string): string | undefined {
|
|
76
|
+
try {
|
|
77
|
+
return new URL(uri).protocol.replace(/:$/, "");
|
|
78
|
+
} catch {
|
|
79
|
+
return undefined;
|
|
35
80
|
}
|
|
36
|
-
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function globMatches(pattern: string, value: string): boolean {
|
|
84
|
+
try {
|
|
85
|
+
return posixPath.matchesGlob(value, pattern);
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** One validated diagnostic registration retained for selector matching. */
|
|
92
|
+
export interface DiagnosticRegistration {
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly options: Record<string, unknown>;
|
|
37
95
|
}
|
|
38
96
|
|
|
39
97
|
/**
|
|
@@ -44,30 +102,38 @@ export function isValidDiagnosticOptions(value: unknown): boolean {
|
|
|
44
102
|
* removes one id; pull stays enabled until the last id is removed.
|
|
45
103
|
*/
|
|
46
104
|
export class ClientDynamicRegistrations {
|
|
47
|
-
private readonly
|
|
105
|
+
private readonly registrationsByMethod = new Map<string, Map<string, Record<string, unknown>>>();
|
|
48
106
|
|
|
49
|
-
/** Record one registration id for a method. Duplicate ids
|
|
50
|
-
register(method: string, id: string): void {
|
|
51
|
-
let
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
this.
|
|
107
|
+
/** Record one registration id for a method. Duplicate ids replace options. */
|
|
108
|
+
register(method: string, id: string, options: Record<string, unknown> = {}): void {
|
|
109
|
+
let registrations = this.registrationsByMethod.get(method);
|
|
110
|
+
if (registrations === undefined) {
|
|
111
|
+
registrations = new Map();
|
|
112
|
+
this.registrationsByMethod.set(method, registrations);
|
|
55
113
|
}
|
|
56
|
-
|
|
114
|
+
registrations.set(id, options);
|
|
57
115
|
}
|
|
58
116
|
|
|
59
117
|
/** Remove one registration id; unknown ids are harmless no-ops. */
|
|
60
118
|
unregister(method: string, id: string): void {
|
|
61
|
-
this.
|
|
119
|
+
this.registrationsByMethod.get(method)?.delete(id);
|
|
62
120
|
}
|
|
63
121
|
|
|
64
122
|
/** Whether any registration id remains active for a method. */
|
|
65
123
|
has(method: string): boolean {
|
|
66
|
-
return (this.
|
|
124
|
+
return (this.registrationsByMethod.get(method)?.size ?? 0) > 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Return active registration options for one method. */
|
|
128
|
+
get(method: string): readonly DiagnosticRegistration[] {
|
|
129
|
+
return Array.from(this.registrationsByMethod.get(method) ?? [], ([id, options]) => ({
|
|
130
|
+
id,
|
|
131
|
+
options,
|
|
132
|
+
}));
|
|
67
133
|
}
|
|
68
134
|
|
|
69
135
|
/** Drop all registrations — capability loss on shutdown, crash, or disposal. */
|
|
70
136
|
clear(): void {
|
|
71
|
-
this.
|
|
137
|
+
this.registrationsByMethod.clear();
|
|
72
138
|
}
|
|
73
139
|
}
|