pi-lens 3.8.73 → 4.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/CHANGELOG.md +2614 -12
- package/README.md +50 -21
- package/dist/clients/actionable-warnings.js +73 -18
- package/dist/clients/agent-behavior-client.js +21 -4
- package/dist/clients/ast-grep-client.js +68 -16
- package/dist/clients/ast-grep-types.js +0 -1
- package/dist/clients/ast-grep-yaml-synth.js +37 -10
- package/dist/clients/atomic-write-staging.js +63 -0
- package/dist/clients/atomic-write.js +116 -16
- package/dist/clients/bash-file-access.js +193 -23
- package/dist/clients/biome-client.js +29 -25
- package/dist/clients/bootstrap.js +11 -2
- package/dist/clients/bounded-cache.js +34 -0
- package/dist/clients/bounded-pid-file-lock.js +192 -0
- package/dist/clients/bus-events-logger.js +5 -1
- package/dist/clients/bus-publish.js +10 -3
- package/dist/clients/cache/rule-cache.js +89 -6
- package/dist/clients/cache-manager.js +97 -9
- package/dist/clients/cache-observability.js +498 -0
- package/dist/clients/call-graph.js +460 -108
- package/dist/clients/cascade-logger.js +5 -1
- package/dist/clients/child-unref.js +85 -0
- package/dist/clients/codebase-model.js +52 -23
- package/dist/clients/collateral-test-role.js +40 -0
- package/dist/clients/complexity-client.js +6 -8
- package/dist/clients/console-guard-install.js +14 -0
- package/dist/clients/cooperative-budget.js +42 -0
- package/dist/clients/dead-code-client.js +2 -1
- package/dist/clients/debug-handles.js +206 -0
- package/dist/clients/debug-heap.js +167 -0
- package/dist/clients/degradation-ledger.js +153 -0
- package/dist/clients/dependency-checker.js +466 -63
- package/dist/clients/diagnostic-dispositions.js +83 -13
- package/dist/clients/diagnostics-publish.js +10 -3
- package/dist/clients/dispatch/auxiliary-lsp.js +34 -0
- package/dist/clients/dispatch/dispatcher.js +71 -13
- package/dist/clients/dispatch/fact-store.js +11 -0
- package/dist/clients/dispatch/facts/function-facts.js +37 -7
- package/dist/clients/dispatch/facts/import-facts.js +108 -119
- package/dist/clients/dispatch/facts/tree-sitter-facts.js +12 -12
- package/dist/clients/dispatch/facts/try-catch-facts.js +13 -0
- package/dist/clients/dispatch/indent-detect.js +35 -0
- package/dist/clients/dispatch/inline-suppressions.js +17 -8
- package/dist/clients/dispatch/integration.js +1094 -611
- package/dist/clients/dispatch/lazy.js +14 -0
- package/dist/clients/dispatch/plan.js +11 -1
- package/dist/clients/dispatch/rule-id-normalize.js +50 -0
- package/dist/clients/dispatch/rule-policy.js +135 -0
- package/dist/clients/dispatch/rules/async-noise.js +1 -0
- package/dist/clients/dispatch/rules/unsafe-boundary.js +7 -0
- package/dist/clients/dispatch/runners/ast-grep-napi.js +47 -6
- package/dist/clients/dispatch/runners/biome-check.js +5 -9
- package/dist/clients/dispatch/runners/detekt.js +3 -2
- package/dist/clients/dispatch/runners/hadolint.js +2 -1
- package/dist/clients/dispatch/runners/helm-lint.js +154 -0
- package/dist/clients/dispatch/runners/htmlhint.js +3 -2
- package/dist/clients/dispatch/runners/index.js +5 -1
- package/dist/clients/dispatch/runners/lsp.js +14 -6
- package/dist/clients/dispatch/runners/markdownlint.js +4 -9
- package/dist/clients/dispatch/runners/psscriptanalyzer.js +10 -1
- package/dist/clients/dispatch/runners/pyright.js +9 -5
- package/dist/clients/dispatch/runners/ruff.js +4 -8
- package/dist/clients/dispatch/runners/shellcheck.js +2 -3
- package/dist/clients/dispatch/runners/shfmt.js +2 -3
- package/dist/clients/dispatch/runners/spotbugs.js +2 -1
- package/dist/clients/dispatch/runners/taplo.js +2 -1
- package/dist/clients/dispatch/runners/terragrunt.js +163 -0
- package/dist/clients/dispatch/runners/tflint.js +37 -5
- package/dist/clients/dispatch/runners/tree-sitter.js +155 -166
- package/dist/clients/dispatch/runners/trivy-config.js +13 -7
- package/dist/clients/dispatch/runners/utils/lazy-installer.js +3 -0
- package/dist/clients/dispatch/runners/utils/runner-helpers.js +284 -34
- package/dist/clients/dispatch/runners/utils/spawn-outcome.js +22 -0
- package/dist/clients/dispatch/runners/yaml-rule-parser.js +5 -4
- package/dist/clients/disposition-publish.js +10 -3
- package/dist/clients/durable-store.js +97 -0
- package/dist/clients/event-loop-monitor.js +94 -3
- package/dist/clients/extension-log.js +139 -0
- package/dist/clients/extension-mode.js +73 -0
- package/dist/clients/feature-hints.js +53 -7
- package/dist/clients/file-kinds.js +143 -31
- package/dist/clients/file-role.js +18 -3
- package/dist/clients/file-utils.js +56 -34
- package/dist/clients/fix-worklog.js +14 -2
- package/dist/clients/format-events-publish.js +16 -3
- package/dist/clients/format-service.js +24 -8
- package/dist/clients/formatters-lazy.js +8 -0
- package/dist/clients/formatters.js +358 -61
- package/dist/clients/generated-artifacts.js +169 -15
- package/dist/clients/git-guard.js +681 -11
- package/dist/clients/git-tracked-ignore.js +4 -0
- package/dist/clients/go-client.js +2 -1
- package/dist/clients/govulncheck-client.js +8 -0
- package/dist/clients/grammar-source.js +12 -4
- package/dist/clients/gzip-stage-write.js +102 -0
- package/dist/clients/host-ports.js +31 -0
- package/dist/clients/installer/index.js +733 -213
- package/dist/clients/instance-reaper.js +142 -172
- package/dist/clients/jscpd-client.js +31 -54
- package/dist/clients/knip-client.js +78 -36
- package/dist/clients/language-policy.js +14 -2
- package/dist/clients/language-profile.js +72 -77
- package/dist/clients/latency-logger.js +28 -16
- package/dist/clients/lens-config.js +140 -166
- package/dist/clients/lens-engine.js +124 -21
- package/dist/clients/lens-events.js +27 -4
- package/dist/clients/lens-flag-registry.js +293 -0
- package/dist/clients/lens-map.js +96 -26
- package/dist/clients/live-bus-emitter.js +30 -0
- package/dist/clients/log-cleanup.js +8 -18
- package/dist/clients/lsp/cascade-tier.js +23 -3
- package/dist/clients/lsp/client.js +566 -57
- package/dist/clients/lsp/config.js +74 -10
- package/dist/clients/lsp/diagnostic-binding.js +86 -0
- package/dist/clients/lsp/edits.js +1012 -121
- package/dist/clients/lsp/index.js +1840 -803
- package/dist/clients/lsp/language.js +4 -1
- package/dist/clients/lsp/launch.js +40 -32
- package/dist/clients/lsp/path-utils.js +1 -1
- package/dist/clients/lsp/ruby-drive-dirs.js +83 -0
- package/dist/clients/lsp/server.js +279 -60
- package/dist/clients/lsp/workspace-diagnostics-cache.js +28 -4
- package/dist/clients/lsp-document-symbols.js +112 -0
- package/dist/clients/lsp-lazy.js +8 -0
- package/dist/clients/lsp-mutation.js +248 -0
- package/dist/clients/mcp/analyze.js +128 -36
- package/dist/clients/mcp/ipc.js +157 -24
- package/dist/clients/mcp/review.js +36 -3
- package/dist/clients/mcp/session.js +216 -8
- package/dist/clients/memory-sampler.js +115 -0
- package/dist/clients/metrics-client.js +2 -1
- package/dist/clients/metrics-history.js +2 -1
- package/dist/clients/module-report-lsp.js +5 -0
- package/dist/clients/module-report.js +267 -82
- package/dist/clients/ndjson-logger.js +334 -103
- package/dist/clients/opengrep-client.js +1 -1
- package/dist/clients/partial-edit-apply.js +120 -5
- package/dist/clients/path-keyed-map.js +76 -0
- package/dist/clients/path-utils.js +141 -5
- package/dist/clients/performance-report.js +327 -0
- package/dist/clients/pipeline.js +54 -13
- package/dist/clients/print-mode.js +21 -0
- package/dist/clients/project-changes.js +117 -4
- package/dist/clients/project-diagnostics/cache.js +3 -2
- package/dist/clients/project-diagnostics/extractors.js +26 -115
- package/dist/clients/project-diagnostics/fresh-fetch.js +149 -19
- package/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +117 -0
- package/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +37 -5
- package/dist/clients/project-diagnostics/scanner.js +268 -128
- package/dist/clients/project-lens-config.js +138 -34
- package/dist/clients/project-report.js +64 -25
- package/dist/clients/project-scale.js +8 -10
- package/dist/clients/project-snapshot-persist-worker.js +6 -0
- package/dist/clients/project-snapshot.js +767 -8
- package/dist/clients/project-trust.js +181 -0
- package/dist/clients/quiet-window.js +27 -5
- package/dist/clients/read-bridge.js +147 -0
- package/dist/clients/read-expansion.js +22 -12
- package/dist/clients/read-guard-logger.js +159 -1
- package/dist/clients/read-guard-tool-lines.js +150 -29
- package/dist/clients/read-guard.js +262 -3
- package/dist/clients/redact/secrets.js +449 -0
- package/dist/clients/resource-sampler.js +144 -39
- package/dist/clients/reverse-deps.js +48 -0
- package/dist/clients/review-graph/builder.js +2570 -326
- package/dist/clients/review-graph/git-identity.js +2 -1
- package/dist/clients/review-graph/import-resolvers.js +21 -10
- package/dist/clients/review-graph/persist-worker.js +10 -0
- package/dist/clients/review-graph/query.js +5 -0
- package/dist/clients/review-graph/shared-extraction-ir.js +90 -0
- package/dist/clients/review-graph/symbol-id.js +46 -0
- package/dist/clients/review-graph/tsconfig-paths.js +57 -6
- package/dist/clients/review-graph/workspace-modules.js +51 -3
- package/dist/clients/review-graph-logger.js +53 -0
- package/dist/clients/ruff-client.js +27 -44
- package/dist/clients/runtime-agent-end.js +111 -75
- package/dist/clients/runtime-context.js +36 -12
- package/dist/clients/runtime-coordinator.js +76 -8
- package/dist/clients/runtime-session.js +799 -137
- package/dist/clients/runtime-tool-call.js +117 -62
- package/dist/clients/runtime-tool-result.js +218 -23
- package/dist/clients/runtime-turn.js +284 -40
- package/dist/clients/rust-client.js +2 -1
- package/dist/clients/safe-spawn.js +873 -71
- package/dist/clients/security-scan-client.js +2 -1
- package/dist/clients/session-start-observability.js +15 -0
- package/dist/clients/session-state-store.js +5 -3
- package/dist/clients/sessionstart-logger.js +18 -0
- package/dist/clients/sg-runner.js +284 -159
- package/dist/clients/slow-fs.js +2 -1
- package/dist/clients/smells-rollup.js +224 -0
- package/dist/clients/source-filter.js +231 -43
- package/dist/clients/source-walker.js +66 -10
- package/dist/clients/startup-scan.js +15 -16
- package/dist/clients/startup-timing.js +9 -0
- package/dist/clients/test-runner-client.js +38 -8
- package/dist/clients/todo-scanner.js +30 -3
- package/dist/clients/tool-event.js +35 -0
- package/dist/clients/tool-policy.js +388 -39
- package/dist/clients/tool-render.js +155 -0
- package/dist/clients/tree-sitter-cache.js +153 -140
- package/dist/clients/tree-sitter-client.js +1722 -80
- package/dist/clients/tree-sitter-logger.js +64 -1
- package/dist/clients/tree-sitter-query-loader.js +117 -12
- package/dist/clients/tree-sitter-shared.js +48 -19
- package/dist/clients/tree-sitter-symbol-extractor.js +115 -11
- package/dist/clients/user-notify.js +51 -0
- package/dist/clients/vanished-instance-marker.js +57 -0
- package/dist/clients/warm-attach.js +33 -13
- package/dist/clients/widget-state.js +342 -49
- package/dist/clients/word-index-logger.js +44 -0
- package/dist/clients/word-index.js +612 -68
- package/dist/clients/workspace-topology.js +100 -7
- package/dist/index.js +65923 -47161
- package/dist/mcp/analyze-cli.js +185 -29
- package/dist/mcp/cli.js +110 -0
- package/dist/mcp/server.js +272 -50
- package/dist/tools/ast-grep-search.js +93 -27
- package/dist/tools/lens-diagnostics.js +247 -41
- package/dist/tools/lsp-diagnostics.js +153 -40
- package/dist/tools/lsp-navigation.js +51 -31
- package/dist/tools/module-report.js +9 -0
- package/dist/tools/symbol-search.js +21 -2
- package/docs/agent-guide.md +247 -0
- package/docs/agent-tools.md +21 -10
- package/docs/analysisall.md +192 -0
- package/docs/api-ports-inventory.md +165 -0
- package/docs/ast-grep_rules_catalog.md +5 -2
- package/docs/astplayground.md +3 -4
- package/docs/audit1.md +5 -5
- package/docs/durable-store-audit-1202.md +32 -0
- package/docs/environment-variables.md +197 -11
- package/docs/fable.md +27 -0
- package/docs/features.md +35 -5
- package/docs/globalconfig.md +101 -5
- package/docs/language-coverage.md +6 -5
- package/docs/lsp-capability-matrix.md +2 -2
- package/docs/mcp.md +54 -20
- package/docs/servercapabilities.md +7 -4
- package/docs/settings.md +192 -0
- package/docs/tools.md +18 -1
- package/docs/tree-sitter_rules_catalog.md +11 -31
- package/docs/usage.md +31 -0
- package/package.json +139 -138
- package/rules/ast-grep-rules/rule-tests/hardcoded-url-js-test.yml +1 -0
- package/rules/ast-grep-rules/rule-tests/hardcoded-url-test.yml +2 -0
- package/rules/ast-grep-rules/rule-tests/no-bare-except-test.yml +49 -0
- package/rules/ast-grep-rules/rule-tests/no-bare-host-path-in-win32-branch-test.yml +87 -0
- package/rules/ast-grep-rules/rule-tests/no-case-declarations-js-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-case-declarations-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-javascript-url-js-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-javascript-url-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-nested-links-test.yml +11 -1
- package/rules/ast-grep-rules/rule-tests/no-raw-json-store-write-test.yml +17 -0
- package/rules/ast-grep-rules/rule-tests/no-win32-isabsolute-for-qualification-test.yml +16 -0
- package/rules/ast-grep-rules/rule-tests/strict-equality-js-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-equality-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-inequality-js-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-inequality-test.yml +4 -0
- package/rules/ast-grep-rules/rules/hardcoded-url-js.yml +22 -4
- package/rules/ast-grep-rules/rules/hardcoded-url.yml +22 -4
- package/rules/ast-grep-rules/rules/no-bare-except.yml +3 -15
- package/rules/ast-grep-rules/rules/no-bare-host-path-in-win32-branch.yml +25 -0
- package/rules/ast-grep-rules/rules/no-case-declarations-js.yml +4 -3
- package/rules/ast-grep-rules/rules/no-case-declarations.yml +4 -3
- package/rules/ast-grep-rules/rules/no-console-except-error-js.yml +10 -0
- package/rules/ast-grep-rules/rules/no-console-except-error.yml +10 -0
- package/rules/ast-grep-rules/rules/no-javascript-url-js.yml +42 -6
- package/rules/ast-grep-rules/rules/no-javascript-url.yml +42 -6
- package/rules/ast-grep-rules/rules/no-nested-links.yml +7 -0
- package/rules/ast-grep-rules/rules/no-raw-json-store-write.yml +30 -0
- package/rules/ast-grep-rules/rules/no-win32-isabsolute-for-qualification.yml +23 -0
- package/rules/ast-grep-rules/rules/strict-equality-js.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-equality.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-inequality-js.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-inequality.yml +14 -1
- package/rules/tree-sitter-queries/cpp/no-memset-sensitive-data.yml +9 -3
- package/rules/tree-sitter-queries/cpp/no-scoped-lock-without-args.yml +6 -6
- package/rules/tree-sitter-queries/css/calc-spacing.yml +8 -6
- package/rules/tree-sitter-queries/go/go-mutex-copy.yml +21 -18
- package/rules/tree-sitter-queries/go/go-shared-map-write-goroutine.yml +3 -3
- package/rules/tree-sitter-queries/java/infinite-loop-java.yml +3 -3
- package/rules/tree-sitter-queries/java/junit-call-super.yml +6 -4
- package/rules/tree-sitter-queries/java/no-double-checked-locking.yml +10 -8
- package/rules/tree-sitter-queries/java/no-field-shadowing.yml +1 -1
- package/rules/tree-sitter-queries/java/prepared-statement-valid-indices.yml +2 -3
- package/rules/tree-sitter-queries/java/resources-closed.yml +2 -2
- package/rules/tree-sitter-queries/java/springboot-default-package.yml +6 -3
- package/rules/tree-sitter-queries/java/switch-fall-through.yml +6 -4
- package/rules/tree-sitter-queries/java/switch-non-case-labels.yml +4 -3
- package/rules/tree-sitter-queries/java/tests-include-assertions.yml +6 -5
- package/rules/tree-sitter-queries/javascript/switch-case-termination-js.yml +5 -8
- package/rules/tree-sitter-queries/javascript/switch-non-case-labels.yml +3 -2
- package/rules/tree-sitter-queries/kotlin/prepared-statement-indices.yml +9 -5
- package/rules/tree-sitter-queries/php/this-in-static-context.yml +5 -5
- package/rules/tree-sitter-queries/python/exit-signature-check.yml +2 -9
- package/rules/tree-sitter-queries/python/in-operator-unsupported.yml +3 -4
- package/rules/tree-sitter-queries/python/no-super-torchscript.yml +4 -8
- package/rules/tree-sitter-queries/python/notimplemented-boolean-context.yml +1 -5
- package/rules/tree-sitter-queries/python/python-empty-except.yml +1 -1
- package/rules/tree-sitter-queries/python/return-in-init.yml +0 -2
- package/rules/tree-sitter-queries/python/yield-return-outside-function.yml +0 -3
- package/rules/tree-sitter-queries/ruby/ruby-command-injection.yml +1 -12
- package/rules/tree-sitter-queries/ruby/ruby-eval.yml +1 -1
- package/rules/tree-sitter-queries/ruby/ruby-insecure-deserialization.yml +4 -4
- package/rules/tree-sitter-queries/ruby/ruby-insecure-random.yml +4 -11
- package/rules/tree-sitter-queries/ruby/ruby-open-struct.yml +1 -1
- package/rules/tree-sitter-queries/ruby/ruby-string-eval.yml +2 -3
- package/rules/tree-sitter-queries/ruby/ruby-weak-hash.yml +4 -4
- package/rules/tree-sitter-queries/rust/rust-lock-held-across-await.yml +4 -3
- package/rules/tree-sitter-queries/tsx/no-nested-links.yml +4 -6
- package/rules/tree-sitter-queries/typescript/console-statement.yml +11 -0
- package/rules/tree-sitter-queries/typescript/duplicate-function-arg.yml +4 -9
- package/rules/tree-sitter-queries/typescript/empty-switch-case.yml +13 -9
- package/rules/tree-sitter-queries/typescript/infinite-loop.yml +2 -2
- package/rules/tree-sitter-queries/typescript/mixed-async-styles.yml +10 -1
- package/rules/tree-sitter-queries/typescript/switch-case-termination.yml +5 -8
- package/rules/tree-sitter-queries/typescript/ts-insecure-random.yml +7 -10
- package/rules/tree-sitter-queries/typescript/unsafe-regex.yml +4 -2
- package/rules/typos/_typos.toml +17 -0
- package/scripts/analyze-pi-lens-logs.mjs +55 -2
- package/skills/pi-lens-write-tree-sitter-rule/SKILL.md +5 -0
- package/dist/clients/ast-grep-parser.js +0 -86
- package/dist/clients/config-enabled-shape.js +0 -39
- package/dist/clients/lsp/interactive-install.js +0 -367
- package/dist/clients/lsp/lsp-index.js +0 -10
- package/dist/clients/lsp/server-strategies.js +0 -5
- package/dist/clients/project-metadata.js +0 -690
- package/dist/clients/source-groups.js +0 -96
- package/dist/clients/types.js +0 -11
- package/docs/env_variables.md +0 -10
- package/rules/tree-sitter-queries/abap-disabled/delete-where.yml +0 -46
- package/rules/tree-sitter-queries/cpp/no-confused-move-forward.yml +0 -59
- package/rules/tree-sitter-queries/cpp/noexcept-functions.yml +0 -58
- package/rules/tree-sitter-queries/java/mockito-initialized.yml +0 -66
- package/rules/tree-sitter-queries/java/no-wait-notify-on-thread.yml +0 -58
- package/rules/tree-sitter-queries/java/short-circuit-logic.yml +0 -57
- package/rules/tree-sitter-queries/java/spring-session-attributes-setcomplete.yml +0 -75
- package/rules/tree-sitter-queries/plsql-disabled/delete-update-where.yml +0 -56
- package/rules/tree-sitter-queries/plsql-disabled/end-loop-semicolon.yml +0 -51
- package/rules/tree-sitter-queries/plsql-disabled/fetch-bulk-collect-limit.yml +0 -47
- package/rules/tree-sitter-queries/plsql-disabled/forallsave-exceptions.yml +0 -51
- package/rules/tree-sitter-queries/plsql-disabled/nchar-nvarchar2-bytes.yml +0 -54
- package/rules/tree-sitter-queries/plsql-disabled/not-null-initialization.yml +0 -59
- package/rules/tree-sitter-queries/plsql-disabled/raise-application-error-codes.yml +0 -50
- package/rules/tree-sitter-queries/typescript-disabled/ts-path-traversal.yml +0 -71
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Diagnostics with debouncing
|
|
8
8
|
* - Request/response handling
|
|
9
9
|
*/
|
|
10
|
+
import { logExtension } from "../extension-log.js";
|
|
10
11
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
11
12
|
import { EventEmitter } from "node:events";
|
|
12
13
|
import { access, readFile } from "node:fs/promises";
|
|
@@ -18,7 +19,9 @@ import { logLatency } from "../latency-logger.js";
|
|
|
18
19
|
// `./node` subpath (no `.js`); the old `/node.js` file path no longer resolves.
|
|
19
20
|
import { CancellationTokenSource, createMessageConnection, StreamMessageReader, StreamMessageWriter, } from "../deps/vscode-jsonrpc.js";
|
|
20
21
|
import { getAmbientAbortSignal } from "../safe-spawn.js";
|
|
21
|
-
import {
|
|
22
|
+
import { hashDiagnosticContent, } from "./diagnostic-binding.js";
|
|
23
|
+
import { newLspMutationCorrelationId, } from "../lsp-mutation.js";
|
|
24
|
+
import { applyWorkspaceEdit, normalizeWorkspaceEditToUtf16, } from "./edits.js";
|
|
22
25
|
import { recordLspChild, removeLspChild } from "../instance-registry.js";
|
|
23
26
|
import { normalizeMapKey, uriToPath } from "./path-utils.js";
|
|
24
27
|
import { ADVERTISED_POSITION_ENCODINGS, convertCharacterOffset, lineTextAt, negotiatePositionEncoding, } from "./position-encoding.js";
|
|
@@ -71,7 +74,16 @@ const INITIALIZE_TIMEOUT_MS = positiveIntFromEnv("PI_LENS_LSP_INIT_TIMEOUT_MS",
|
|
|
71
74
|
*/
|
|
72
75
|
export const CLIENT_CAPABILITIES = {
|
|
73
76
|
general: { positionEncodings: ADVERTISED_POSITION_ENCODINGS },
|
|
74
|
-
|
|
77
|
+
// #974: workDoneProgress is intentionally NOT advertised. pi-lens never
|
|
78
|
+
// consumes `$/progress` notifications (grepped: zero listeners anywhere in
|
|
79
|
+
// clients/), so declaring the capability only invites servers to open
|
|
80
|
+
// progress tokens pi-lens will silently ignore — and opengrep's
|
|
81
|
+
// `--experimental` LSP mode crash-loops when it can't parse our
|
|
82
|
+
// spec-correct `{"result": null}` reply to its
|
|
83
|
+
// `window/workDoneProgress/create` request. "Only advertise what you
|
|
84
|
+
// implement" — the `window/workDoneProgress/create` handler below stays as
|
|
85
|
+
// a defensive no-op in case a server ignores capabilities and asks anyway.
|
|
86
|
+
window: {},
|
|
75
87
|
workspace: {
|
|
76
88
|
workspaceFolders: true,
|
|
77
89
|
configuration: true,
|
|
@@ -114,6 +126,25 @@ const PULL_DIAGNOSTICS_RETRY_INTERVAL_MS = positiveIntFromEnv("PI_LENS_LSP_PULL_
|
|
|
114
126
|
// (per #240) is NOT read as clean and falls through to the bounded push backstop.
|
|
115
127
|
const PULL_REQUEST_TIMEOUT_MS = positiveIntFromEnv("PI_LENS_LSP_PULL_REQUEST_TIMEOUT_MS", 10_000);
|
|
116
128
|
const SHUTDOWN_REQUEST_TIMEOUT_MS = positiveIntFromEnv("PI_LENS_LSP_SHUTDOWN_TIMEOUT_MS", 1000);
|
|
129
|
+
// #1277: cheap liveness round-trip for the silent-clean gates (`index.ts`).
|
|
130
|
+
// Those gates convert a diagnostics-wait timeout into a confirmed-clean
|
|
131
|
+
// result from a STATIC capability classification (`silentOnClean`) alone —
|
|
132
|
+
// but a wedged server (accepted the notify write, then hung) satisfies that
|
|
133
|
+
// classification identically to a genuinely clean one. This is deliberately
|
|
134
|
+
// short relative to NAV_REQUEST_TIMEOUT_MS: it only needs to prove the
|
|
135
|
+
// connection round-trips SOMETHING before the touch reports clean, not
|
|
136
|
+
// complete a real navigation request.
|
|
137
|
+
const LIVENESS_PING_TIMEOUT_MS = positiveIntFromEnv("PI_LENS_LSP_LIVENESS_PING_TIMEOUT_MS", 300);
|
|
138
|
+
// Distinctive, unlikely-to-collide query string — the response content is
|
|
139
|
+
// never inspected, only whether one arrived before the timeout.
|
|
140
|
+
const LIVENESS_PING_QUERY = "__pi_lens_liveness_ping__";
|
|
141
|
+
// #1104: bound on `state.workspacePullResultCache` — one entry per distinct
|
|
142
|
+
// file the server has ever returned a `resultId` for across this client's
|
|
143
|
+
// lifetime. A full clear on overflow (rather than an LRU) is fine, same
|
|
144
|
+
// reasoning as `DISK_BINDING_MEMO_MAX` in diagnostic-binding.ts: each entry is
|
|
145
|
+
// cheaply rebuilt by the next full pull, the worst case is just one extra full
|
|
146
|
+
// (non-`unchanged`) report per affected file.
|
|
147
|
+
const WORKSPACE_PULL_RESULT_CACHE_MAX = 4096;
|
|
117
148
|
// Anti-deadlock backstop for workspace/executeCommand. Deliberately generous
|
|
118
149
|
// (30s): the command is mutating and legitimately long-running (a real server
|
|
119
150
|
// refactor / organize-imports), so this must not truncate valid work — it only
|
|
@@ -273,12 +304,34 @@ export async function killProcessTree(proc, pid, options = {}) {
|
|
|
273
304
|
}
|
|
274
305
|
};
|
|
275
306
|
try {
|
|
307
|
+
// #1114: gate the escalation on OBSERVED exit, not `proc.killed`. Node
|
|
308
|
+
// only sets `proc.killed = true` when `proc.kill()` (the ChildProcess
|
|
309
|
+
// method) successfully SENDS a signal — never when the process actually
|
|
310
|
+
// dies, and the primary SIGTERM path above goes through the raw
|
|
311
|
+
// `process.kill(-pid, …)` process-group call, which never touches
|
|
312
|
+
// `proc.killed` at all. Checking `!proc.killed` here was therefore
|
|
313
|
+
// either always-true (unconditional SIGKILL after the window,
|
|
314
|
+
// regardless of whether the group already died — group-kill path) or
|
|
315
|
+
// always-false/dead (direct-child fallback path, same shape as the
|
|
316
|
+
// safe-spawn escalation bug). An `exit` listener set once, up front,
|
|
317
|
+
// gives a real observed-death signal for both. Seeded from the same
|
|
318
|
+
// `exitCode`/`signalCode` pre-check the top-of-function early return
|
|
319
|
+
// uses (:689) — that early return is skipped when
|
|
320
|
+
// `options.processExiting` is set, so a process that was ALREADY dead
|
|
321
|
+
// on entry can still reach here; without seeding, `exited` would stay
|
|
322
|
+
// false (the "exit" event already fired before this listener was
|
|
323
|
+
// attached) and the fast/non-fast branches below would still fire a
|
|
324
|
+
// redundant group SIGKILL at the escalation window.
|
|
325
|
+
let exited = proc.exitCode != null || proc.signalCode != null;
|
|
326
|
+
proc.once?.("exit", () => {
|
|
327
|
+
exited = true;
|
|
328
|
+
});
|
|
276
329
|
if (!killPosixProcessGroup("SIGTERM")) {
|
|
277
330
|
killDirectChild("SIGTERM");
|
|
278
331
|
}
|
|
279
332
|
if (options.fast) {
|
|
280
333
|
const timer = setTimeout(() => {
|
|
281
|
-
if (!
|
|
334
|
+
if (!exited) {
|
|
282
335
|
logLatency({
|
|
283
336
|
type: "phase",
|
|
284
337
|
phase: "lsp_kill_escalation",
|
|
@@ -295,10 +348,27 @@ export async function killProcessTree(proc, pid, options = {}) {
|
|
|
295
348
|
proc.unref?.();
|
|
296
349
|
return;
|
|
297
350
|
}
|
|
298
|
-
// SIGTERM → 1.5s → SIGKILL escalation.
|
|
299
|
-
//
|
|
300
|
-
|
|
301
|
-
|
|
351
|
+
// SIGTERM → exit-or-1.5s → SIGKILL escalation. SIGTERM alone can leave
|
|
352
|
+
// zombie processes if the server hangs — but a server that dies promptly
|
|
353
|
+
// must resolve on its exit event, not sleep the full escalation window
|
|
354
|
+
// (that unconditional 1500ms was the whole cost of every graceful LSP
|
|
355
|
+
// teardown, ×N clients per session and per test).
|
|
356
|
+
const exitedInTime = await new Promise((resolve) => {
|
|
357
|
+
if (proc.exitCode != null || proc.signalCode != null) {
|
|
358
|
+
resolve(true);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const onExit = () => {
|
|
362
|
+
clearTimeout(timer);
|
|
363
|
+
resolve(true);
|
|
364
|
+
};
|
|
365
|
+
const timer = setTimeout(() => {
|
|
366
|
+
proc.off?.("exit", onExit);
|
|
367
|
+
resolve(false);
|
|
368
|
+
}, 1500);
|
|
369
|
+
proc.once?.("exit", onExit);
|
|
370
|
+
});
|
|
371
|
+
if (!exitedInTime && !exited) {
|
|
302
372
|
logLatency({
|
|
303
373
|
type: "phase",
|
|
304
374
|
phase: "lsp_kill_escalation",
|
|
@@ -371,9 +441,33 @@ function clearDiagnosticsForPath(state, normalizedPath) {
|
|
|
371
441
|
state.documentPullDiagnostics?.delete(normalizedPath);
|
|
372
442
|
state.documentPullDiagnosticTimestamps?.delete(normalizedPath);
|
|
373
443
|
state.diagnosticDocVersions?.delete(normalizedPath);
|
|
444
|
+
// #1095: a cleared path must never serve a stale content binding alongside a
|
|
445
|
+
// later publish — drop it with the diagnostics it described. (The last-sent
|
|
446
|
+
// `documentContentHashes` record is intentionally retained: it describes what
|
|
447
|
+
// we sent, which the NEXT publish for that version still needs to bind to.)
|
|
448
|
+
state.diagnosticBindings?.delete(normalizedPath);
|
|
449
|
+
// #1104: a resync invalidates any `unchanged`-report basis too — the next
|
|
450
|
+
// pull must not inherit a resultId/contentHash computed against the
|
|
451
|
+
// content this resync just replaced.
|
|
452
|
+
state.pullResultIds?.delete(normalizedPath);
|
|
453
|
+
state.workspacePullResultCache?.delete(normalizedPath);
|
|
374
454
|
legacy.diagnostics?.delete(normalizedPath);
|
|
375
455
|
legacy.diagnosticTimestamps?.delete(normalizedPath);
|
|
376
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* #1095: fingerprint the EXACT didOpen/didChange payload text at SEND time and
|
|
459
|
+
* tag it with the document version it was sent as, so a later
|
|
460
|
+
* `publishDiagnostics` echoing that version can bind its diagnostics to the
|
|
461
|
+
* content they were computed against. Runs on in-memory content — never a disk
|
|
462
|
+
* read on the notification path (I1). Bounded by the same file-size gates the
|
|
463
|
+
* caller already applies to the content it hands us.
|
|
464
|
+
*/
|
|
465
|
+
function recordSentContent(state, normalizedPath, version, content) {
|
|
466
|
+
state.documentContentHashes.set(normalizedPath, {
|
|
467
|
+
version,
|
|
468
|
+
hash: hashDiagnosticContent(content),
|
|
469
|
+
});
|
|
470
|
+
}
|
|
377
471
|
// Methods that can be registered dynamically and map to operationSupport keys
|
|
378
472
|
const DYNAMIC_OPERATION_METHOD_MAP = {
|
|
379
473
|
"textDocument/definition": "definition",
|
|
@@ -417,6 +511,31 @@ export function applyDynamicCapabilities(state) {
|
|
|
417
511
|
}
|
|
418
512
|
}
|
|
419
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Resolve a `workspace/configuration` request item's `section` (a dot-path,
|
|
516
|
+
* e.g. "scan.jobs") against the server's `initializationOptions` blob.
|
|
517
|
+
* - No section (undefined/empty) → the whole blob, per spec ("if a scope
|
|
518
|
+
* isn't asked for" the client returns the full settings for that scope).
|
|
519
|
+
* - An unresolvable path → `null`, never the whole blob — a server asking
|
|
520
|
+
* for a section it doesn't get must not silently receive unrelated config.
|
|
521
|
+
* Exported for the #983 regression test.
|
|
522
|
+
*/
|
|
523
|
+
export function resolveConfigurationSection(initialization, section) {
|
|
524
|
+
if (!initialization)
|
|
525
|
+
return section ? null : {};
|
|
526
|
+
if (!section)
|
|
527
|
+
return initialization;
|
|
528
|
+
let cur = initialization;
|
|
529
|
+
for (const part of section.split(".")) {
|
|
530
|
+
if (typeof cur !== "object" ||
|
|
531
|
+
cur === null ||
|
|
532
|
+
!Object.prototype.hasOwnProperty.call(cur, part)) {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
cur = cur[part];
|
|
536
|
+
}
|
|
537
|
+
return cur;
|
|
538
|
+
}
|
|
420
539
|
// Exported (only) so tests can invoke the publishDiagnostics notification
|
|
421
540
|
// handler directly against a mock LSPClientState/connection without spawning
|
|
422
541
|
// a real language server. Not part of the public client API surface.
|
|
@@ -424,10 +543,20 @@ export function setupIncomingHandlers(state, initialization) {
|
|
|
424
543
|
state.connection.onNotification("textDocument/publishDiagnostics", (params) => {
|
|
425
544
|
const filePath = uriToPath(params.uri);
|
|
426
545
|
const normalizedPath = normalizeMapKey(filePath);
|
|
546
|
+
// A server can flush a queued publish after didClose during teardown.
|
|
547
|
+
// Do not resurrect diagnostics or their content binding for a document
|
|
548
|
+
// that is no longer open on this client.
|
|
549
|
+
if (state.closedDocuments?.has(normalizedPath))
|
|
550
|
+
return;
|
|
427
551
|
const newDiags = normalizeLspDiagnostics(params.diagnostics || []);
|
|
428
552
|
const docVersion = params.version;
|
|
429
553
|
if (PUB_DEBUG) {
|
|
430
|
-
|
|
554
|
+
// #1333: PUB_DEBUG gate preserved; sink is extension.log.
|
|
555
|
+
logExtension({
|
|
556
|
+
subsystem: "lsp-pub",
|
|
557
|
+
level: "debug",
|
|
558
|
+
message: `server=${state.serverId} pubVersion=${docVersion} docVersion=${state.documentVersions?.get(normalizedPath)} diags=${newDiags.length}`,
|
|
559
|
+
});
|
|
431
560
|
}
|
|
432
561
|
const strategy = getStrategy(state.serverId);
|
|
433
562
|
// Record the document version these diagnostics were computed against
|
|
@@ -437,6 +566,26 @@ export function setupIncomingHandlers(state, initialization) {
|
|
|
437
566
|
if (docVersion !== undefined) {
|
|
438
567
|
state.diagnosticDocVersions.set(normalizedPath, docVersion);
|
|
439
568
|
}
|
|
569
|
+
recordBinding();
|
|
570
|
+
};
|
|
571
|
+
// #1095: bind the just-stored diagnostics to the content they were
|
|
572
|
+
// computed against. Only when the server reported a version AND we still
|
|
573
|
+
// hold the sent-content fingerprint for exactly that version — otherwise
|
|
574
|
+
// no contentHash is recorded, so the binding reads "unknown" and a
|
|
575
|
+
// version-less server behaves exactly as before. Runs at the same
|
|
576
|
+
// write-time moment as `pushDiagnostics.set` (superseded pushes are
|
|
577
|
+
// dropped before this via `isSupersededPush`, so a binding never lags the
|
|
578
|
+
// latest sent version).
|
|
579
|
+
const recordBinding = () => {
|
|
580
|
+
if (docVersion === undefined) {
|
|
581
|
+
state.diagnosticBindings.delete(normalizedPath);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
const sent = state.documentContentHashes.get(normalizedPath);
|
|
585
|
+
state.diagnosticBindings.set(normalizedPath, {
|
|
586
|
+
version: docVersion,
|
|
587
|
+
contentHash: sent && sent.version === docVersion ? sent.hash : undefined,
|
|
588
|
+
});
|
|
440
589
|
};
|
|
441
590
|
// Late/superseded-push guard: if the server stamped this push with a
|
|
442
591
|
// version and that version already lags the latest didChange we sent,
|
|
@@ -529,8 +678,21 @@ export function setupIncomingHandlers(state, initialization) {
|
|
|
529
678
|
if (state.serverEditsAllowed <= 0 || !params?.edit) {
|
|
530
679
|
return { applied: false, failureReason: "edit not solicited" };
|
|
531
680
|
}
|
|
681
|
+
const context = (state.activeMutationDepth ?? 0) === 1
|
|
682
|
+
? state.activeMutationContext
|
|
683
|
+
: undefined;
|
|
684
|
+
const telemetryContext = context ?? {
|
|
685
|
+
cwd: state.root,
|
|
686
|
+
correlationId: newLspMutationCorrelationId(),
|
|
687
|
+
tool: "lsp-workspace-applyEdit",
|
|
688
|
+
source: "lsp-edit",
|
|
689
|
+
};
|
|
532
690
|
try {
|
|
533
|
-
await applyWorkspaceEdit(params.edit, state.root
|
|
691
|
+
await applyWorkspaceEdit(params.edit, state.root, {
|
|
692
|
+
positionEncoding: state.positionEncoding,
|
|
693
|
+
documentVersions: state.documentVersions,
|
|
694
|
+
mutationContext: telemetryContext,
|
|
695
|
+
});
|
|
534
696
|
return { applied: true };
|
|
535
697
|
}
|
|
536
698
|
catch (err) {
|
|
@@ -540,21 +702,42 @@ export function setupIncomingHandlers(state, initialization) {
|
|
|
540
702
|
};
|
|
541
703
|
}
|
|
542
704
|
});
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
705
|
+
// #983: the LSP spec requires the response array to have exactly one entry
|
|
706
|
+
// per requested item, each resolved against that item's `section` (a
|
|
707
|
+
// dot-path into the server's config, e.g. "scan.jobs") — not a fixed
|
|
708
|
+
// single-element array duplicating the whole blob for every item. An item
|
|
709
|
+
// with no `section` gets the whole blob (that's what "no section" means
|
|
710
|
+
// per spec); an unresolvable section gets `null`, never the whole blob.
|
|
711
|
+
state.connection.onRequest("workspace/configuration", async (params) => {
|
|
712
|
+
const items = params?.items ?? [];
|
|
713
|
+
return items.map((item) => resolveConfigurationSection(initialization, item?.section));
|
|
714
|
+
});
|
|
546
715
|
state.connection.onRequest("window/workDoneProgress/create", async () => { });
|
|
547
716
|
}
|
|
717
|
+
/**
|
|
718
|
+
* #1127: record the FIRST moment this client observed its own death. Detection
|
|
719
|
+
* of a dead client (the next `getClientForFile` attach in index.ts) can happen
|
|
720
|
+
* long after the process actually died — this timestamp is the only reliable
|
|
721
|
+
* "when did it die" signal, so it must be set here, at the earliest death
|
|
722
|
+
* signal, not derived later from detection time.
|
|
723
|
+
*/
|
|
724
|
+
function markExitedIfUnset(state) {
|
|
725
|
+
if (state.exitedAt === undefined) {
|
|
726
|
+
state.exitedAt = Date.now();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
548
729
|
function setupConnectionLifecycle(state, recentStderr) {
|
|
549
730
|
state.connection.onError(([error]) => {
|
|
550
731
|
state.lastError = error instanceof Error ? error : new Error(String(error));
|
|
551
732
|
state.isConnected = false;
|
|
552
733
|
state.isDestroyed = true;
|
|
734
|
+
markExitedIfUnset(state);
|
|
553
735
|
disposeClientConnection(state);
|
|
554
736
|
});
|
|
555
737
|
state.connection.onClose(() => {
|
|
556
738
|
state.isConnected = false;
|
|
557
739
|
state.isDestroyed = true;
|
|
740
|
+
markExitedIfUnset(state);
|
|
558
741
|
disposeClientConnection(state);
|
|
559
742
|
});
|
|
560
743
|
state.lspProcess.process.on("exit", (code, signal) => {
|
|
@@ -569,6 +752,7 @@ function setupConnectionLifecycle(state, recentStderr) {
|
|
|
569
752
|
const wasIntentional = state.shutdownRequested;
|
|
570
753
|
state.isConnected = false;
|
|
571
754
|
state.isDestroyed = true;
|
|
755
|
+
markExitedIfUnset(state);
|
|
572
756
|
disposeClientConnection(state);
|
|
573
757
|
if (!wasIntentional) {
|
|
574
758
|
logLatency({
|
|
@@ -591,29 +775,83 @@ async function clientRequestPullDiagnostics(state, filePath, budgetMs = PULL_REQ
|
|
|
591
775
|
if (!isClientAlive(state))
|
|
592
776
|
return { status: "unavailable" };
|
|
593
777
|
const uri = pathToFileURL(filePath).href;
|
|
778
|
+
const normalizedPath = normalizeMapKey(filePath);
|
|
779
|
+
// #1104: echo the last resultId we hold for this document so a server that
|
|
780
|
+
// hasn't changed its view can answer `kind: "unchanged"` instead of
|
|
781
|
+
// recomputing — see the `kind === "unchanged"` branch below for how that's
|
|
782
|
+
// honored (inherit, never treat an omitted `items` as clean).
|
|
783
|
+
const previousResultId = state.pullResultIds.get(normalizedPath);
|
|
594
784
|
try {
|
|
595
785
|
// withTimeout is the backstop against a hung pull-mode server: without it
|
|
596
786
|
// this await never settles unless the stream is destroyed. Bounded by the
|
|
597
787
|
// smaller of the absolute ceiling and the caller's remaining wait budget.
|
|
598
788
|
// On timeout the caught error yields `unavailable` below (never a false
|
|
599
789
|
// `clean`), so it falls through to the push-wait/timeout backstop.
|
|
600
|
-
const report = await withTimeout(safeSendRequest(state.connection, "textDocument/diagnostic", {
|
|
601
|
-
|
|
790
|
+
const report = await withTimeout(safeSendRequest(state.connection, "textDocument/diagnostic", {
|
|
791
|
+
textDocument: { uri },
|
|
792
|
+
...(previousResultId !== undefined && { previousResultId }),
|
|
793
|
+
}), Math.max(1, Math.min(PULL_REQUEST_TIMEOUT_MS, budgetMs)));
|
|
794
|
+
if (!report) {
|
|
795
|
+
recordPullFailure(state, "textDocument/diagnostic", new Error("empty response"));
|
|
602
796
|
return { status: "unavailable" };
|
|
603
|
-
|
|
604
|
-
const primaryItems = normalizeLspDiagnostics(report.items ?? []);
|
|
797
|
+
}
|
|
605
798
|
const now = Date.now();
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
799
|
+
// #1104: the fingerprint of the content we last sent for this document —
|
|
800
|
+
// the SAME `documentContentHashes` entry the push binding path uses
|
|
801
|
+
// (`recordSentContent` runs unconditionally on every didOpen/didChange,
|
|
802
|
+
// regardless of push/pull mode), so this costs no extra read. A pull
|
|
803
|
+
// response describes whatever the server had when it answered, which for
|
|
804
|
+
// a pi-lens-opened document is exactly that last-sent payload.
|
|
805
|
+
const sentHash = state.documentContentHashes.get(normalizedPath)?.hash;
|
|
806
|
+
let totalCount;
|
|
807
|
+
if (report.kind === "unchanged") {
|
|
808
|
+
// #1104: same resultId basis as last time — an omitted `items` here
|
|
809
|
+
// means "no change", NOT "clean". Overwriting with `[]` would be the
|
|
810
|
+
// exact false-clean shape #570/#571 already fixed for the touch path;
|
|
811
|
+
// keep the previously stored diagnostics and binding as-is.
|
|
812
|
+
totalCount = state.documentPullDiagnostics.get(normalizedPath)?.length ?? 0;
|
|
813
|
+
// Still a fresh confirmation as of `now` even though the content is
|
|
814
|
+
// unchanged — bump the timestamp so `getAllDiagnostics()` doesn't read
|
|
815
|
+
// this entry as aging purely because the server had nothing new to say.
|
|
816
|
+
state.documentPullDiagnosticTimestamps.set(normalizedPath, now);
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
const primaryItems = normalizeLspDiagnostics(report.items ?? []);
|
|
820
|
+
state.documentPullDiagnostics.set(normalizedPath, primaryItems);
|
|
821
|
+
state.documentPullDiagnosticTimestamps.set(normalizedPath, now);
|
|
822
|
+
state.diagnosticsVersion += 1;
|
|
823
|
+
state.diagnosticBindings.set(normalizedPath, { contentHash: sentHash });
|
|
824
|
+
totalCount = primaryItems.length;
|
|
825
|
+
}
|
|
826
|
+
if (report.resultId !== undefined) {
|
|
827
|
+
state.pullResultIds.set(normalizedPath, report.resultId);
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
state.pullResultIds.delete(normalizedPath);
|
|
831
|
+
}
|
|
610
832
|
if (report.relatedDocuments) {
|
|
611
833
|
for (const [relatedUri, related] of Object.entries(report.relatedDocuments)) {
|
|
612
834
|
const relatedPath = uriToPath(relatedUri);
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
835
|
+
const relatedNormalized = normalizeMapKey(relatedPath);
|
|
836
|
+
if (related?.kind === "unchanged") {
|
|
837
|
+
totalCount +=
|
|
838
|
+
state.documentPullDiagnostics.get(relatedNormalized)?.length ?? 0;
|
|
839
|
+
state.documentPullDiagnosticTimestamps.set(relatedNormalized, now);
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
const relatedItems = normalizeLspDiagnostics(related?.items ?? []);
|
|
843
|
+
state.documentPullDiagnostics.set(relatedNormalized, relatedItems);
|
|
844
|
+
state.documentPullDiagnosticTimestamps.set(relatedNormalized, now);
|
|
845
|
+
// #1104: a related document's diagnostics were NOT computed against
|
|
846
|
+
// content we independently sent/fingerprinted (we never requested
|
|
847
|
+
// it directly) — its binding stays honestly "unknown" rather than
|
|
848
|
+
// borrowing the primary document's hash.
|
|
849
|
+
state.diagnosticBindings.delete(relatedNormalized);
|
|
850
|
+
totalCount += relatedItems.length;
|
|
851
|
+
}
|
|
852
|
+
if (related?.resultId !== undefined) {
|
|
853
|
+
state.pullResultIds.set(relatedNormalized, related.resultId);
|
|
854
|
+
}
|
|
617
855
|
}
|
|
618
856
|
}
|
|
619
857
|
state.diagnosticEmitter.emit("diagnostics", normalizedPath);
|
|
@@ -621,10 +859,34 @@ async function clientRequestPullDiagnostics(state, filePath, budgetMs = PULL_REQ
|
|
|
621
859
|
? { status: "found", count: totalCount }
|
|
622
860
|
: { status: "clean" };
|
|
623
861
|
}
|
|
624
|
-
catch {
|
|
862
|
+
catch (err) {
|
|
863
|
+
recordPullFailure(state, "textDocument/diagnostic", err);
|
|
625
864
|
return { status: "unavailable" };
|
|
626
865
|
}
|
|
627
866
|
}
|
|
867
|
+
const PULL_FAILURE_HISTORY_LIMIT = 10;
|
|
868
|
+
function recordPullFailure(state, method, error) {
|
|
869
|
+
const candidate = error;
|
|
870
|
+
const message = typeof candidate.message === "string" ? candidate.message : "";
|
|
871
|
+
const unsupportedMessage = /^(?:method not found|unknown method|unsupported method)(?::|$)/i;
|
|
872
|
+
if (candidate.code === -32601 ||
|
|
873
|
+
candidate.code === "-32601" ||
|
|
874
|
+
unsupportedMessage.test(message.trim()))
|
|
875
|
+
return;
|
|
876
|
+
state.pullFailureHistory.push({
|
|
877
|
+
timestamp: Date.now(),
|
|
878
|
+
method,
|
|
879
|
+
...(typeof candidate.code === "number" || typeof candidate.code === "string"
|
|
880
|
+
? { code: candidate.code }
|
|
881
|
+
: {}),
|
|
882
|
+
message: typeof candidate.message === "string"
|
|
883
|
+
? candidate.message
|
|
884
|
+
: String(error),
|
|
885
|
+
});
|
|
886
|
+
if (state.pullFailureHistory.length > PULL_FAILURE_HISTORY_LIMIT) {
|
|
887
|
+
state.pullFailureHistory.splice(0, state.pullFailureHistory.length - PULL_FAILURE_HISTORY_LIMIT);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
628
890
|
/**
|
|
629
891
|
* One project-wide `workspace/diagnostic` pull — a single request that returns
|
|
630
892
|
* diagnostics for every document the server knows, instead of opening N files.
|
|
@@ -638,23 +900,73 @@ export async function clientRequestWorkspaceDiagnostics(state, budgetMs) {
|
|
|
638
900
|
if (!state.workspaceDiagnosticsSupport.workspaceDiagnostics)
|
|
639
901
|
return undefined;
|
|
640
902
|
try {
|
|
641
|
-
|
|
903
|
+
// #1104: echo every resultId we hold from a PRIOR pull so the server can
|
|
904
|
+
// answer `kind: "unchanged"` for files it hasn't recomputed, instead of
|
|
905
|
+
// resending (and us re-hashing) every file on every sweep.
|
|
906
|
+
const previousResultIds = Array.from(state.workspacePullResultCache.values()).map((entry) => ({ uri: entry.uri, value: entry.resultId }));
|
|
907
|
+
const report = await withTimeout(safeSendRequest(state.connection, "workspace/diagnostic", { previousResultIds }), Math.max(1, budgetMs));
|
|
642
908
|
if (!report || !Array.isArray(report.items))
|
|
643
909
|
return undefined;
|
|
644
910
|
const out = [];
|
|
645
911
|
for (const item of report.items) {
|
|
646
|
-
|
|
647
|
-
// (none, since previousResultIds is empty on this one-shot request).
|
|
648
|
-
if (!item?.uri || item.kind !== "full")
|
|
912
|
+
if (!item?.uri)
|
|
649
913
|
continue;
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
914
|
+
const filePath = uriToPath(item.uri);
|
|
915
|
+
const normalizedPath = normalizeMapKey(filePath);
|
|
916
|
+
if (item.kind === "unchanged") {
|
|
917
|
+
// #1104: inherit the prior pull's diagnostics + content binding for
|
|
918
|
+
// the SAME resultId basis — an "unchanged" report never carries
|
|
919
|
+
// `items`, so without this a file the server confirmed unchanged
|
|
920
|
+
// would silently drop out of the sweep result entirely.
|
|
921
|
+
const prior = state.workspacePullResultCache.get(normalizedPath);
|
|
922
|
+
if (!prior)
|
|
923
|
+
continue; // no earlier basis to inherit — nothing to report
|
|
924
|
+
if (item.resultId !== undefined) {
|
|
925
|
+
state.workspacePullResultCache.set(normalizedPath, {
|
|
926
|
+
...prior,
|
|
927
|
+
resultId: item.resultId,
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
out.push({
|
|
931
|
+
filePath,
|
|
932
|
+
diagnostics: prior.diagnostics,
|
|
933
|
+
contentHash: prior.contentHash,
|
|
934
|
+
});
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
// "full" (or a non-conforming server omitting `kind`, per the LSP
|
|
938
|
+
// default) — recompute and re-fingerprint.
|
|
939
|
+
const diagnostics = normalizeLspDiagnostics(item.items ?? []);
|
|
940
|
+
// #1104: fingerprint the file bytes active AT REQUEST TIME. Best-effort —
|
|
941
|
+
// a read failure (deleted/unreadable mid-sweep) just leaves contentHash
|
|
942
|
+
// undefined, so the binding reads honestly "unknown", never fabricated.
|
|
943
|
+
let contentHash;
|
|
944
|
+
try {
|
|
945
|
+
contentHash = hashDiagnosticContent(await readFile(filePath, "utf-8"));
|
|
946
|
+
}
|
|
947
|
+
catch {
|
|
948
|
+
contentHash = undefined;
|
|
949
|
+
}
|
|
950
|
+
if (item.resultId !== undefined) {
|
|
951
|
+
if (state.workspacePullResultCache.size >= WORKSPACE_PULL_RESULT_CACHE_MAX) {
|
|
952
|
+
state.workspacePullResultCache.clear();
|
|
953
|
+
}
|
|
954
|
+
state.workspacePullResultCache.set(normalizedPath, {
|
|
955
|
+
uri: item.uri,
|
|
956
|
+
resultId: item.resultId,
|
|
957
|
+
diagnostics,
|
|
958
|
+
contentHash,
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
state.workspacePullResultCache.delete(normalizedPath);
|
|
963
|
+
}
|
|
964
|
+
out.push({ filePath, diagnostics, contentHash });
|
|
654
965
|
}
|
|
655
966
|
return out;
|
|
656
967
|
}
|
|
657
|
-
catch {
|
|
968
|
+
catch (err) {
|
|
969
|
+
recordPullFailure(state, "workspace/diagnostic", err);
|
|
658
970
|
return undefined;
|
|
659
971
|
}
|
|
660
972
|
}
|
|
@@ -697,7 +1009,8 @@ export async function clientWaitForDiagnostics(state, filePath, timeoutMs, optio
|
|
|
697
1009
|
// Retry within budget to catch incremental servers whose first pull is
|
|
698
1010
|
// empty while analysis is still running (rust-analyzer). A `clean` seen at
|
|
699
1011
|
// any point is a valid affirmative answer for this touch.
|
|
700
|
-
while (outcome.status !== "found" &&
|
|
1012
|
+
while (outcome.status !== "found" &&
|
|
1013
|
+
Date.now() - startedAt < retryBudgetMs) {
|
|
701
1014
|
await new Promise((resolve) => setTimeout(resolve, PULL_DIAGNOSTICS_RETRY_INTERVAL_MS));
|
|
702
1015
|
outcome = await clientRequestPullDiagnostics(state, filePath, Math.max(0, retryBudgetMs - (Date.now() - startedAt)));
|
|
703
1016
|
if (outcome.status === "clean")
|
|
@@ -746,8 +1059,8 @@ export async function clientWaitForDiagnostics(state, filePath, timeoutMs, optio
|
|
|
746
1059
|
export async function handleNotifyOpen(state, filePath, content, languageId, preserveDiagnostics = false, silent = false) {
|
|
747
1060
|
if (!isClientAlive(state))
|
|
748
1061
|
return;
|
|
749
|
-
const uri = pathToFileURL(filePath).href;
|
|
750
1062
|
const normalizedPath = normalizeMapKey(filePath);
|
|
1063
|
+
const uri = state.openDocumentUris?.get(normalizedPath) ?? pathToFileURL(filePath).href;
|
|
751
1064
|
if (state.openDocuments.has(normalizedPath) ||
|
|
752
1065
|
state.pendingOpens.has(normalizedPath)) {
|
|
753
1066
|
const version = (state.documentVersions.get(normalizedPath) ?? 0) + 1;
|
|
@@ -755,6 +1068,12 @@ export async function handleNotifyOpen(state, filePath, content, languageId, pre
|
|
|
755
1068
|
// preserveDiagnostics: skip cache clear for format-only resyncs so
|
|
756
1069
|
// waitForDiagnostics fast-paths instead of waiting up to 5s for TypeScript
|
|
757
1070
|
// to re-publish what it already knows (formatting doesn't change semantics).
|
|
1071
|
+
// #1095 note: this also retains the prior content `binding`. Until the
|
|
1072
|
+
// server republishes for the new version, a binding read compares the OLD
|
|
1073
|
+
// content hash against the NEW disk bytes → boundToCurrentDisk `false` →
|
|
1074
|
+
// the consumer demotes to inconclusive. That's the SAFE (#533) direction (a
|
|
1075
|
+
// transient "unconfirmed", never a false-clean), self-healing on the next
|
|
1076
|
+
// publish — not a correctness hazard, unlike the reopen false-TRUE above.
|
|
758
1077
|
if (!preserveDiagnostics) {
|
|
759
1078
|
clearDiagnosticsForPath(state, normalizedPath);
|
|
760
1079
|
}
|
|
@@ -766,19 +1085,32 @@ export async function handleNotifyOpen(state, filePath, content, languageId, pre
|
|
|
766
1085
|
textDocument: { uri },
|
|
767
1086
|
});
|
|
768
1087
|
state.openDocuments.delete(normalizedPath);
|
|
769
|
-
state.
|
|
1088
|
+
state.openDocumentUris?.delete(normalizedPath);
|
|
1089
|
+
// #1095 (P2-3): carry the version counter FORWARD across the
|
|
1090
|
+
// close+reopen instead of resetting to 0. LSP lets a didOpen use any
|
|
1091
|
+
// version, and reusing 0 for successive resyncs made the version
|
|
1092
|
+
// ambiguous — a late publish for an earlier resync's content echoed the
|
|
1093
|
+
// SAME 0 as the current send, so the superseded-push guard (0 < 0 is
|
|
1094
|
+
// false) accepted it and `recordBinding` bound STALE diagnostics to the
|
|
1095
|
+
// CURRENT content's fingerprint → an affirmative boundToCurrentDisk TRUE
|
|
1096
|
+
// for a stale view (worse than "unknown"). Monotonic versions make that
|
|
1097
|
+
// late echo strictly older → dropped by isSupersededPush → never bound.
|
|
1098
|
+
state.documentVersions.set(normalizedPath, version);
|
|
770
1099
|
if (!isClientAlive(state))
|
|
771
1100
|
return;
|
|
772
1101
|
await safeSendNotification(state.connection, "textDocument/didOpen", {
|
|
773
|
-
textDocument: { uri, languageId, version
|
|
1102
|
+
textDocument: { uri, languageId, version, text: content },
|
|
774
1103
|
});
|
|
1104
|
+
recordSentContent(state, normalizedPath, version, content);
|
|
775
1105
|
state.openDocuments.add(normalizedPath);
|
|
1106
|
+
state.openDocumentUris?.set(normalizedPath, uri);
|
|
776
1107
|
return;
|
|
777
1108
|
}
|
|
778
1109
|
await safeSendNotification(state.connection, "textDocument/didChange", {
|
|
779
1110
|
textDocument: { uri, version },
|
|
780
1111
|
contentChanges: [{ text: content }],
|
|
781
1112
|
});
|
|
1113
|
+
recordSentContent(state, normalizedPath, version, content);
|
|
782
1114
|
return;
|
|
783
1115
|
}
|
|
784
1116
|
state.pendingOpens.add(normalizedPath);
|
|
@@ -812,14 +1144,17 @@ export async function handleNotifyOpen(state, filePath, content, languageId, pre
|
|
|
812
1144
|
await safeSendNotification(state.connection, "textDocument/didOpen", {
|
|
813
1145
|
textDocument: { uri, languageId, version: 0, text: content },
|
|
814
1146
|
});
|
|
1147
|
+
recordSentContent(state, normalizedPath, 0, content);
|
|
815
1148
|
state.pendingOpens.delete(normalizedPath);
|
|
816
1149
|
state.openDocuments.add(normalizedPath);
|
|
1150
|
+
state.closedDocuments?.delete(normalizedPath);
|
|
1151
|
+
state.openDocumentUris?.set(normalizedPath, uri);
|
|
817
1152
|
}
|
|
818
1153
|
export async function handleNotifyChange(state, filePath, content) {
|
|
819
1154
|
if (!isClientAlive(state))
|
|
820
1155
|
return;
|
|
821
|
-
const uri = pathToFileURL(filePath).href;
|
|
822
1156
|
const normalizedPath = normalizeMapKey(filePath);
|
|
1157
|
+
const uri = state.openDocumentUris?.get(normalizedPath) ?? pathToFileURL(filePath).href;
|
|
823
1158
|
if (!state.openDocuments.has(normalizedPath)) {
|
|
824
1159
|
// Safety fallback: keep protocol ordering valid even if caller sends
|
|
825
1160
|
// didChange before first didOpen for this document.
|
|
@@ -827,7 +1162,9 @@ export async function handleNotifyChange(state, filePath, content) {
|
|
|
827
1162
|
textDocument: { uri, languageId: "plaintext", version: 0, text: content },
|
|
828
1163
|
});
|
|
829
1164
|
state.documentVersions.set(normalizedPath, 0);
|
|
1165
|
+
recordSentContent(state, normalizedPath, 0, content);
|
|
830
1166
|
state.openDocuments.add(normalizedPath);
|
|
1167
|
+
state.openDocumentUris?.set(normalizedPath, uri);
|
|
831
1168
|
return;
|
|
832
1169
|
}
|
|
833
1170
|
const version = (state.documentVersions.get(normalizedPath) ?? 0) + 1;
|
|
@@ -839,6 +1176,25 @@ export async function handleNotifyChange(state, filePath, content) {
|
|
|
839
1176
|
textDocument: { uri, version },
|
|
840
1177
|
contentChanges: [{ text: content }],
|
|
841
1178
|
});
|
|
1179
|
+
recordSentContent(state, normalizedPath, version, content);
|
|
1180
|
+
}
|
|
1181
|
+
/** Close a document through the same lifecycle path exposed by the client. */
|
|
1182
|
+
export async function closeDocument(state, filePath) {
|
|
1183
|
+
if (!isClientAlive(state))
|
|
1184
|
+
return;
|
|
1185
|
+
const normalizedPath = normalizeMapKey(filePath);
|
|
1186
|
+
if (!state.openDocuments.has(normalizedPath))
|
|
1187
|
+
return;
|
|
1188
|
+
await safeSendNotification(state.connection, "textDocument/didClose", {
|
|
1189
|
+
textDocument: {
|
|
1190
|
+
uri: state.openDocumentUris?.get(normalizedPath) ?? pathToFileURL(filePath).href,
|
|
1191
|
+
},
|
|
1192
|
+
});
|
|
1193
|
+
state.openDocuments.delete(normalizedPath);
|
|
1194
|
+
state.closedDocuments?.add(normalizedPath);
|
|
1195
|
+
state.openDocumentUris?.delete(normalizedPath);
|
|
1196
|
+
state.documentVersions.delete(normalizedPath);
|
|
1197
|
+
clearDiagnosticsForPath(state, normalizedPath);
|
|
842
1198
|
}
|
|
843
1199
|
export async function clientShutdown(state, options = {}) {
|
|
844
1200
|
const shutdownStart = Date.now();
|
|
@@ -851,6 +1207,7 @@ export async function clientShutdown(state, options = {}) {
|
|
|
851
1207
|
state.pendingDiagnostics.clear();
|
|
852
1208
|
state.pendingOpens.clear();
|
|
853
1209
|
state.openDocuments.clear();
|
|
1210
|
+
state.openDocumentUris?.clear();
|
|
854
1211
|
// #271: drop any pending watched-files batch + its timer (a dying client's
|
|
855
1212
|
// queued FS changes are moot, and the timer must not outlive the connection).
|
|
856
1213
|
state.watchQueue?.cancel();
|
|
@@ -969,13 +1326,44 @@ signal = getAmbientAbortSignal()) {
|
|
|
969
1326
|
}
|
|
970
1327
|
return result;
|
|
971
1328
|
}
|
|
1329
|
+
// #1277: cheap liveness round-trip used by the silent-clean gates in
|
|
1330
|
+
// `index.ts`. `isAlive()`/`checkAlive()` only look at process/connection
|
|
1331
|
+
// state — a server that accepted the notify write and then wedged (still
|
|
1332
|
+
// running, connection still open, just never replying) reads as "alive" by
|
|
1333
|
+
// those checks even though it will never answer anything again. This sends a
|
|
1334
|
+
// real request (`workspace/symbol`, chosen because it needs no open document)
|
|
1335
|
+
// and reports whether the connection round-tripped it — success, a genuine
|
|
1336
|
+
// protocol-level error (e.g. MethodNotFound), and a stream-destroyed/
|
|
1337
|
+
// cancelled response (safeSendRequest swallows those to `undefined`, so the
|
|
1338
|
+
// final `isClientAlive` re-check is what catches "died mid-flight") ALL count
|
|
1339
|
+
// as "alive"; only a real timeout, or the connection having gone down by the
|
|
1340
|
+
// time this resolves, reports dead. The response content itself is never
|
|
1341
|
+
// inspected — only whether one arrived in time.
|
|
1342
|
+
async function clientPingLiveness(state, timeoutMs = LIVENESS_PING_TIMEOUT_MS) {
|
|
1343
|
+
if (!isClientAlive(state))
|
|
1344
|
+
return false;
|
|
1345
|
+
try {
|
|
1346
|
+
await withTimeout(safeSendRequest(state.connection, "workspace/symbol", {
|
|
1347
|
+
query: LIVENESS_PING_QUERY,
|
|
1348
|
+
}), timeoutMs);
|
|
1349
|
+
}
|
|
1350
|
+
catch (err) {
|
|
1351
|
+
if (err instanceof Error && err.message.startsWith("Timeout after")) {
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
// A real protocol-level error reply still proves the server round-
|
|
1355
|
+
// tripped the request — fall through to the alive re-check below
|
|
1356
|
+
// rather than treating an error response as "dead".
|
|
1357
|
+
}
|
|
1358
|
+
return isClientAlive(state);
|
|
1359
|
+
}
|
|
972
1360
|
// Run an advertised server command via workspace/executeCommand, with the
|
|
973
1361
|
// generous EXECUTE_COMMAND_TIMEOUT_MS anti-deadlock backstop. Preserves the
|
|
974
1362
|
// hardening invariants: allowlist-by-advertisement (only commands the server
|
|
975
1363
|
// declared) and the serverEditsAllowed window that gates server-driven
|
|
976
1364
|
// applyEdit to the duration of an explicit call. Exported with an overridable
|
|
977
1365
|
// `timeoutMs` for the #365 regression tests.
|
|
978
|
-
export async function runServerCommand(state, command, args, timeoutMs = EXECUTE_COMMAND_TIMEOUT_MS) {
|
|
1366
|
+
export async function runServerCommand(state, command, args, timeoutMs = EXECUTE_COMMAND_TIMEOUT_MS, mutationContext) {
|
|
979
1367
|
if (!isClientAlive(state)) {
|
|
980
1368
|
return { executed: false, reason: "lsp client not alive" };
|
|
981
1369
|
}
|
|
@@ -986,6 +1374,11 @@ export async function runServerCommand(state, command, args, timeoutMs = EXECUTE
|
|
|
986
1374
|
};
|
|
987
1375
|
}
|
|
988
1376
|
state.serverEditsAllowed += 1;
|
|
1377
|
+
state.activeMutationDepth = (state.activeMutationDepth ?? 0) + 1;
|
|
1378
|
+
if (state.activeMutationDepth === 1)
|
|
1379
|
+
state.activeMutationContext = mutationContext;
|
|
1380
|
+
else
|
|
1381
|
+
state.activeMutationContext = undefined;
|
|
989
1382
|
try {
|
|
990
1383
|
let result;
|
|
991
1384
|
try {
|
|
@@ -1011,22 +1404,85 @@ export async function runServerCommand(state, command, args, timeoutMs = EXECUTE
|
|
|
1011
1404
|
}
|
|
1012
1405
|
finally {
|
|
1013
1406
|
state.serverEditsAllowed -= 1;
|
|
1407
|
+
state.activeMutationDepth = Math.max(0, (state.activeMutationDepth ?? 0) - 1);
|
|
1408
|
+
if (state.activeMutationDepth === 0)
|
|
1409
|
+
state.activeMutationContext = undefined;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
function validateWorkspaceEditVersions(state, edit) {
|
|
1413
|
+
for (const change of edit.documentChanges ?? []) {
|
|
1414
|
+
if (typeof change !== "object" || change === null || !("textDocument" in change))
|
|
1415
|
+
continue;
|
|
1416
|
+
const textDocument = change.textDocument;
|
|
1417
|
+
if (!textDocument || typeof textDocument.uri !== "string" || textDocument.version == null)
|
|
1418
|
+
continue;
|
|
1419
|
+
const current = state.documentVersions.get(normalizeMapKey(uriToPath(textDocument.uri)));
|
|
1420
|
+
if (current === undefined || current !== textDocument.version) {
|
|
1421
|
+
throw new Error(`stale workspace edit document version for ${textDocument.uri}`);
|
|
1422
|
+
}
|
|
1014
1423
|
}
|
|
1015
1424
|
}
|
|
1425
|
+
// Neutralize numeric `textDocument.version` stamps AFTER they have been
|
|
1426
|
+
// validated against the live document map. The tool apply paths (rename
|
|
1427
|
+
// apply:true in tools/lsp-navigation.ts, code-action autofix in
|
|
1428
|
+
// actionable-warnings.ts) call applyWorkspaceEdit without a documentVersions
|
|
1429
|
+
// map, so a preserved numeric version would fail preflight 100% of the time for
|
|
1430
|
+
// servers that stamp real versions (gopls stamps open documents). Setting the
|
|
1431
|
+
// version to null is the spec's "do not check" — the freshness guarantee has
|
|
1432
|
+
// already been provided here by validateWorkspaceEditVersions at the correct
|
|
1433
|
+
// moment. The server-initiated workspace/applyEdit handler does NOT route
|
|
1434
|
+
// through here (it applies params.edit directly with state.documentVersions),
|
|
1435
|
+
// so its real preflight version check is left fully intact.
|
|
1436
|
+
function stripDocumentVersions(edit) {
|
|
1437
|
+
if (!Array.isArray(edit.documentChanges))
|
|
1438
|
+
return edit;
|
|
1439
|
+
const documentChanges = edit.documentChanges.map((change) => {
|
|
1440
|
+
if (typeof change === "object" &&
|
|
1441
|
+
change !== null &&
|
|
1442
|
+
"textDocument" in change &&
|
|
1443
|
+
"edits" in change) {
|
|
1444
|
+
const textDocument = change
|
|
1445
|
+
.textDocument;
|
|
1446
|
+
if (textDocument && typeof textDocument.version === "number") {
|
|
1447
|
+
return {
|
|
1448
|
+
...change,
|
|
1449
|
+
textDocument: { ...textDocument, version: null },
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return change;
|
|
1454
|
+
});
|
|
1455
|
+
return { ...edit, documentChanges };
|
|
1456
|
+
}
|
|
1457
|
+
export async function normalizeClientWorkspaceEdit(state, edit) {
|
|
1458
|
+
validateWorkspaceEditVersions(state, edit);
|
|
1459
|
+
const normalized = (await normalizeWorkspaceEditToUtf16(edit, state.positionEncoding, state.root));
|
|
1460
|
+
return stripDocumentVersions(normalized);
|
|
1461
|
+
}
|
|
1016
1462
|
async function resolveCodeActionBestEffort(state, action) {
|
|
1017
|
-
if (!isClientAlive(state)
|
|
1463
|
+
if (!isClientAlive(state))
|
|
1018
1464
|
return action;
|
|
1465
|
+
if (action.edit) {
|
|
1466
|
+
return {
|
|
1467
|
+
...action,
|
|
1468
|
+
edit: await normalizeClientWorkspaceEdit(state, action.edit),
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
let resolved;
|
|
1019
1472
|
try {
|
|
1020
|
-
|
|
1021
|
-
if (!resolved || typeof resolved !== "object")
|
|
1022
|
-
return action;
|
|
1023
|
-
return { ...action, ...resolved };
|
|
1473
|
+
resolved = await withTimeout(safeSendRequest(state.connection, "codeAction/resolve", action), NAV_REQUEST_TIMEOUT_MS);
|
|
1024
1474
|
}
|
|
1025
1475
|
catch {
|
|
1026
1476
|
// codeAction/resolve is optional. Keep the original lightweight action when
|
|
1027
1477
|
// the server does not support resolve or fails to populate an edit.
|
|
1028
1478
|
return action;
|
|
1029
1479
|
}
|
|
1480
|
+
if (!resolved || typeof resolved !== "object")
|
|
1481
|
+
return action;
|
|
1482
|
+
const merged = { ...action, ...resolved };
|
|
1483
|
+
return merged.edit
|
|
1484
|
+
? { ...merged, edit: await normalizeClientWorkspaceEdit(state, merged.edit) }
|
|
1485
|
+
: merged;
|
|
1030
1486
|
}
|
|
1031
1487
|
// --- Client Factory ---
|
|
1032
1488
|
export async function createLSPClient(options) {
|
|
@@ -1126,6 +1582,7 @@ export async function createLSPClient(options) {
|
|
|
1126
1582
|
isConnected: true,
|
|
1127
1583
|
isDestroyed: false,
|
|
1128
1584
|
shutdownRequested: false,
|
|
1585
|
+
exitedAt: undefined,
|
|
1129
1586
|
connectionDisposed: false,
|
|
1130
1587
|
lastError: undefined,
|
|
1131
1588
|
connection,
|
|
@@ -1133,12 +1590,19 @@ export async function createLSPClient(options) {
|
|
|
1133
1590
|
pushDiagnosticTimestamps: new Map(),
|
|
1134
1591
|
documentPullDiagnostics: new Map(),
|
|
1135
1592
|
documentPullDiagnosticTimestamps: new Map(),
|
|
1593
|
+
pullFailureHistory: [],
|
|
1136
1594
|
pendingDiagnostics: new Map(),
|
|
1137
1595
|
diagnosticEmitter,
|
|
1138
1596
|
diagnosticsVersion: 0,
|
|
1139
1597
|
documentVersions: new Map(),
|
|
1140
1598
|
diagnosticDocVersions: new Map(),
|
|
1599
|
+
documentContentHashes: new Map(),
|
|
1600
|
+
diagnosticBindings: new Map(),
|
|
1601
|
+
pullResultIds: new Map(),
|
|
1602
|
+
workspacePullResultCache: new Map(),
|
|
1141
1603
|
openDocuments: new Set(),
|
|
1604
|
+
closedDocuments: new Set(),
|
|
1605
|
+
openDocumentUris: new Map(),
|
|
1142
1606
|
pendingOpens: new Set(),
|
|
1143
1607
|
// these are filled in after initialize — cast to avoid two-phase init
|
|
1144
1608
|
workspaceDiagnosticsSupport: undefined,
|
|
@@ -1148,6 +1612,7 @@ export async function createLSPClient(options) {
|
|
|
1148
1612
|
dynamicRegistrations: new Map(),
|
|
1149
1613
|
advertisedCommands: new Set(),
|
|
1150
1614
|
serverEditsAllowed: 0,
|
|
1615
|
+
activeMutationDepth: 0,
|
|
1151
1616
|
serverId,
|
|
1152
1617
|
launchVariant,
|
|
1153
1618
|
root,
|
|
@@ -1197,7 +1662,22 @@ export async function createLSPClient(options) {
|
|
|
1197
1662
|
});
|
|
1198
1663
|
});
|
|
1199
1664
|
setTimeout(() => {
|
|
1200
|
-
|
|
1665
|
+
// #1114: gate on the process's own observed `exitCode`/`signalCode`,
|
|
1666
|
+
// not `.killed` — `killProcessTree` above signals the POSIX process
|
|
1667
|
+
// GROUP via the raw `process.kill(-pid, …)`, which never touches
|
|
1668
|
+
// this `ChildProcess` instance's `.killed` flag, so `!…killed` here
|
|
1669
|
+
// was always true and this 2s backstop unconditionally re-sent
|
|
1670
|
+
// SIGKILL even when the group had already exited. `exitCode` alone
|
|
1671
|
+
// is insufficient too: a process that died FROM a signal (the
|
|
1672
|
+
// common case here — killProcessTree's own SIGTERM/SIGKILL) has
|
|
1673
|
+
// `exitCode === null` forever and only `signalCode` set, so
|
|
1674
|
+
// checking `exitCode === null` alone still re-SIGKILLs that corpse
|
|
1675
|
+
// on the common path (harmless — `kill()` on an already-exited pid
|
|
1676
|
+
// is a swallowed no-op — but not actually "observed still alive").
|
|
1677
|
+
// Require both null to mean "no exit observed by either signal".
|
|
1678
|
+
if (lspProcess.process.exitCode === null &&
|
|
1679
|
+
lspProcess.process.signalCode === null &&
|
|
1680
|
+
process.platform !== "win32") {
|
|
1201
1681
|
lspProcess.process.kill("SIGKILL");
|
|
1202
1682
|
}
|
|
1203
1683
|
}, 2000);
|
|
@@ -1251,10 +1731,20 @@ export async function createLSPClient(options) {
|
|
|
1251
1731
|
/** True if the server process has exited or been killed. */
|
|
1252
1732
|
processExited: () => lspProcess.process.exitCode !== null ||
|
|
1253
1733
|
lspProcess.process.killed === true,
|
|
1734
|
+
/** #1127: mirrors `state.shutdownRequested` — see interface doc. */
|
|
1735
|
+
wasShutdownIntentional: () => state.shutdownRequested,
|
|
1736
|
+
/** #1127: mirrors `state.exitedAt` — see interface doc. */
|
|
1737
|
+
getExitedAt: () => state.exitedAt,
|
|
1254
1738
|
/** Last N lines of server stderr for diagnostics. */
|
|
1255
1739
|
recentStderr: (lines) => recentStderr(lines),
|
|
1740
|
+
getPullFailureHistory: () => state.pullFailureHistory.map((entry) => ({
|
|
1741
|
+
...entry,
|
|
1742
|
+
message: entry.message.slice(0, 200),
|
|
1743
|
+
})),
|
|
1256
1744
|
/** Pre-request health check — returns error string if dead. */
|
|
1257
1745
|
checkAlive: () => checkProcessAlive(),
|
|
1746
|
+
/** #1277: cheap request round-trip proving the server still responds. */
|
|
1747
|
+
pingLiveness: (timeoutMs) => clientPingLiveness(state, timeoutMs),
|
|
1258
1748
|
notify: {
|
|
1259
1749
|
async open(filePath, content, languageId, preserveDiagnostics, silent) {
|
|
1260
1750
|
return handleNotifyOpen(state, filePath, content, languageId, preserveDiagnostics, silent);
|
|
@@ -1266,6 +1756,9 @@ export async function createLSPClient(options) {
|
|
|
1266
1756
|
getDiagnostics(filePath) {
|
|
1267
1757
|
return getMergedDiagnosticsForPath(state, normalizeMapKey(filePath));
|
|
1268
1758
|
},
|
|
1759
|
+
getDiagnosticBinding(filePath) {
|
|
1760
|
+
return state.diagnosticBindings.get(normalizeMapKey(filePath));
|
|
1761
|
+
},
|
|
1269
1762
|
getAllDiagnostics() {
|
|
1270
1763
|
const result = new Map();
|
|
1271
1764
|
const keys = new Set([
|
|
@@ -1276,17 +1769,16 @@ export async function createLSPClient(options) {
|
|
|
1276
1769
|
result.set(key, {
|
|
1277
1770
|
diags: getMergedDiagnosticsForPath(state, key),
|
|
1278
1771
|
ts: Math.max(state.pushDiagnosticTimestamps.get(key) ?? 0, state.documentPullDiagnosticTimestamps.get(key) ?? 0),
|
|
1772
|
+
binding: state.diagnosticBindings.get(key),
|
|
1279
1773
|
});
|
|
1280
1774
|
}
|
|
1281
1775
|
return result;
|
|
1282
1776
|
},
|
|
1283
1777
|
getTrackedDiagnosticPaths() {
|
|
1284
|
-
return [
|
|
1285
|
-
...new Set([
|
|
1778
|
+
return [...new Set([
|
|
1286
1779
|
...state.pushDiagnostics.keys(),
|
|
1287
1780
|
...state.documentPullDiagnostics.keys(),
|
|
1288
|
-
]),
|
|
1289
|
-
];
|
|
1781
|
+
])].map((filePath) => process.platform === "win32" ? filePath.replace(/\//g, "\\") : filePath);
|
|
1290
1782
|
},
|
|
1291
1783
|
pruneDiagnostics(predicate) {
|
|
1292
1784
|
let removed = 0;
|
|
@@ -1322,8 +1814,8 @@ export async function createLSPClient(options) {
|
|
|
1322
1814
|
getLaunchVariant() {
|
|
1323
1815
|
return state.launchVariant;
|
|
1324
1816
|
},
|
|
1325
|
-
async executeCommand(command, args) {
|
|
1326
|
-
return runServerCommand(state, command, args);
|
|
1817
|
+
async executeCommand(command, args, mutationContext) {
|
|
1818
|
+
return runServerCommand(state, command, args, EXECUTE_COMMAND_TIMEOUT_MS, mutationContext);
|
|
1327
1819
|
},
|
|
1328
1820
|
get diagnosticsVersion() {
|
|
1329
1821
|
return state.diagnosticsVersion;
|
|
@@ -1384,6 +1876,15 @@ export async function createLSPClient(options) {
|
|
|
1384
1876
|
const result = await navRequest(state, "textDocument/documentSymbol", { textDocument: { uri: pathToFileURL(filePath).href } }, filePath);
|
|
1385
1877
|
return result ?? [];
|
|
1386
1878
|
},
|
|
1879
|
+
isDocumentOpen(filePath) {
|
|
1880
|
+
return state.openDocuments.has(normalizeMapKey(filePath));
|
|
1881
|
+
},
|
|
1882
|
+
isBusy() {
|
|
1883
|
+
return (activeRequestsByConnection.get(connection) ?? 0) > 0;
|
|
1884
|
+
},
|
|
1885
|
+
getDocumentUri(filePath) {
|
|
1886
|
+
return state.openDocumentUris?.get(normalizeMapKey(filePath));
|
|
1887
|
+
},
|
|
1387
1888
|
async workspaceSymbol(query) {
|
|
1388
1889
|
if (!isClientAlive(state))
|
|
1389
1890
|
return [];
|
|
@@ -1423,8 +1924,9 @@ export async function createLSPClient(options) {
|
|
|
1423
1924
|
position: await toWirePosition(state, filePath, line, character),
|
|
1424
1925
|
newName,
|
|
1425
1926
|
}, filePath);
|
|
1426
|
-
return result
|
|
1927
|
+
return result ? await normalizeClientWorkspaceEdit(state, result) : null;
|
|
1427
1928
|
},
|
|
1929
|
+
closeDocument: (filePath) => closeDocument(state, filePath),
|
|
1428
1930
|
async willRenameFiles(oldFilePath, newFilePath) {
|
|
1429
1931
|
const result = await navRequest(state, "workspace/willRenameFiles", {
|
|
1430
1932
|
files: [
|
|
@@ -1434,16 +1936,16 @@ export async function createLSPClient(options) {
|
|
|
1434
1936
|
},
|
|
1435
1937
|
],
|
|
1436
1938
|
});
|
|
1437
|
-
return result
|
|
1939
|
+
return result ? await normalizeClientWorkspaceEdit(state, result) : null;
|
|
1438
1940
|
},
|
|
1439
|
-
async didRenameFiles(oldFilePath, newFilePath) {
|
|
1941
|
+
async didRenameFiles(oldFilePath, newFilePath, oldUri, newUri) {
|
|
1440
1942
|
if (!isClientAlive(state))
|
|
1441
1943
|
return;
|
|
1442
1944
|
await safeSendNotification(state.connection, "workspace/didRenameFiles", {
|
|
1443
1945
|
files: [
|
|
1444
1946
|
{
|
|
1445
|
-
oldUri: pathToFileURL(oldFilePath).href,
|
|
1446
|
-
newUri: pathToFileURL(newFilePath).href,
|
|
1947
|
+
oldUri: oldUri ?? pathToFileURL(oldFilePath).href,
|
|
1948
|
+
newUri: newUri ?? pathToFileURL(newFilePath).href,
|
|
1447
1949
|
},
|
|
1448
1950
|
],
|
|
1449
1951
|
});
|
|
@@ -1492,6 +1994,7 @@ async function safeSendNotification(connection, method, params) {
|
|
|
1492
1994
|
throw err;
|
|
1493
1995
|
}
|
|
1494
1996
|
}
|
|
1997
|
+
const activeRequestsByConnection = new WeakMap();
|
|
1495
1998
|
// Helper to safely send requests - catches stream destruction
|
|
1496
1999
|
async function safeSendRequest(connection, method, params,
|
|
1497
2000
|
// When provided, aborting the signal cancels the in-flight request via
|
|
@@ -1514,6 +2017,7 @@ signal) {
|
|
|
1514
2017
|
const send = () => tokenSource
|
|
1515
2018
|
? connection.sendRequest(method, params, tokenSource.token)
|
|
1516
2019
|
: connection.sendRequest(method, params);
|
|
2020
|
+
activeRequestsByConnection.set(connection, (activeRequestsByConnection.get(connection) ?? 0) + 1);
|
|
1517
2021
|
try {
|
|
1518
2022
|
// One safe retry on ContentModified (-32801): the document changed under
|
|
1519
2023
|
// us, so the server discarded the request. A single retry beats returning
|
|
@@ -1543,6 +2047,11 @@ signal) {
|
|
|
1543
2047
|
}
|
|
1544
2048
|
}
|
|
1545
2049
|
finally {
|
|
2050
|
+
const remaining = (activeRequestsByConnection.get(connection) ?? 1) - 1;
|
|
2051
|
+
if (remaining > 0)
|
|
2052
|
+
activeRequestsByConnection.set(connection, remaining);
|
|
2053
|
+
else
|
|
2054
|
+
activeRequestsByConnection.delete(connection);
|
|
1546
2055
|
if (signal && onAbort)
|
|
1547
2056
|
signal.removeEventListener("abort", onAbort);
|
|
1548
2057
|
tokenSource?.dispose();
|