@duckmind/dm-darwin-x64 0.67.2 → 0.67.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dm +1 -1
- package/extensions/.dm-extensions.json +611 -13
- package/extensions/dm-lens/clients/dispatch/runners/utils/runner-helpers.js +1 -1
- package/extensions/dm-lens/dist/clients/actionable-warnings-logger.js +24 -0
- package/extensions/dm-lens/dist/clients/actionable-warnings.js +1066 -0
- package/extensions/dm-lens/dist/clients/advisory-provenance.js +388 -0
- package/extensions/dm-lens/dist/clients/agent-behavior-client.js +94 -0
- package/extensions/dm-lens/dist/clients/agent-nudge.js +253 -0
- package/extensions/dm-lens/dist/clients/analysed-root.js +1 -0
- package/extensions/dm-lens/dist/clients/analysis-root.js +133 -0
- package/extensions/dm-lens/dist/clients/ast-grep-client.js +587 -0
- package/extensions/dm-lens/dist/clients/ast-grep-rule-manager.js +137 -0
- package/extensions/dm-lens/dist/clients/ast-grep-tool-logger.js +85 -0
- package/extensions/dm-lens/dist/clients/ast-grep-types.js +1 -0
- package/extensions/dm-lens/dist/clients/ast-grep-yaml-synth.js +109 -0
- package/extensions/dm-lens/dist/clients/atomic-write-staging.js +66 -0
- package/extensions/dm-lens/dist/clients/atomic-write.js +37 -0
- package/extensions/dm-lens/dist/clients/availability-probe-flight.js +11 -0
- package/extensions/dm-lens/dist/clients/bash-file-access.js +1257 -0
- package/extensions/dm-lens/dist/clients/biome-client.js +223 -0
- package/extensions/dm-lens/dist/clients/blocker-freshness.js +553 -0
- package/extensions/dm-lens/dist/clients/blocker-past-eof.js +51 -0
- package/extensions/dm-lens/dist/clients/bootstrap.js +246 -0
- package/extensions/dm-lens/dist/clients/bounded-cache.js +105 -0
- package/extensions/dm-lens/dist/clients/bounded-pid-file-lock.js +275 -0
- package/extensions/dm-lens/dist/clients/bounded-telemetry.js +110 -0
- package/extensions/dm-lens/dist/clients/build-identity.js +45 -0
- package/extensions/dm-lens/dist/clients/bundled-resource-health.js +41 -0
- package/extensions/dm-lens/dist/clients/bus-events-logger.js +48 -0
- package/extensions/dm-lens/dist/clients/bus-publish.js +117 -0
- package/extensions/dm-lens/dist/clients/cache/rule-cache.js +87 -0
- package/extensions/dm-lens/dist/clients/cache-manager.js +449 -0
- package/extensions/dm-lens/dist/clients/cache-observability.js +1105 -0
- package/extensions/dm-lens/dist/clients/call-graph.js +628 -0
- package/extensions/dm-lens/dist/clients/cargo-manifest.js +167 -0
- package/extensions/dm-lens/dist/clients/cascade-budget.js +52 -0
- package/extensions/dm-lens/dist/clients/cascade-format.js +301 -0
- package/extensions/dm-lens/dist/clients/cascade-logger.js +22 -0
- package/extensions/dm-lens/dist/clients/cascade-types.js +1 -0
- package/extensions/dm-lens/dist/clients/child-unref.js +59 -0
- package/extensions/dm-lens/dist/clients/code-quality-warnings.js +192 -0
- package/extensions/dm-lens/dist/clients/codebase-model.js +110 -0
- package/extensions/dm-lens/dist/clients/collateral-test-role.js +8 -0
- package/extensions/dm-lens/dist/clients/complexity-client.js +398 -0
- package/extensions/dm-lens/dist/clients/config-core/deny.js +117 -0
- package/extensions/dm-lens/dist/clients/config-core/index.js +2 -0
- package/extensions/dm-lens/dist/clients/config-core/merge.js +228 -0
- package/extensions/dm-lens/dist/clients/config-core/normalize.js +226 -0
- package/extensions/dm-lens/dist/clients/config-core/process-spec.js +147 -0
- package/extensions/dm-lens/dist/clients/config-core/provenance.js +54 -0
- package/extensions/dm-lens/dist/clients/config-core/records.js +79 -0
- package/extensions/dm-lens/dist/clients/config-core/resolve.js +48 -0
- package/extensions/dm-lens/dist/clients/config-core/safe-object.js +22 -0
- package/extensions/dm-lens/dist/clients/config-core/schema.js +93 -0
- package/extensions/dm-lens/dist/clients/config-diagnostic-codes.js +90 -0
- package/extensions/dm-lens/dist/clients/config-locations.js +169 -0
- package/extensions/dm-lens/dist/clients/config-resolve.js +359 -0
- package/extensions/dm-lens/dist/clients/config-schema.js +230 -0
- package/extensions/dm-lens/dist/clients/config-warn.js +146 -0
- package/extensions/dm-lens/dist/clients/confirmed-delete.js +11 -0
- package/extensions/dm-lens/dist/clients/console-guard-install.js +4 -0
- package/extensions/dm-lens/dist/clients/content-stamp.js +16 -0
- package/extensions/dm-lens/dist/clients/context-injection-ledger.js +157 -0
- package/extensions/dm-lens/dist/clients/cooperative-budget.js +36 -0
- package/extensions/dm-lens/dist/clients/custom-rule-locations.js +28 -0
- package/extensions/dm-lens/dist/clients/dead-code-client.js +408 -0
- package/extensions/dm-lens/dist/clients/dead-code-logger.js +18 -0
- package/extensions/dm-lens/dist/clients/deadline-utils.js +117 -0
- package/extensions/dm-lens/dist/clients/debug-handles.js +121 -0
- package/extensions/dm-lens/dist/clients/debug-heap.js +80 -0
- package/extensions/dm-lens/dist/clients/deferred-lsp-work.js +33 -0
- package/extensions/dm-lens/dist/clients/deferred-runner-blockers.js +146 -0
- package/extensions/dm-lens/dist/clients/deferred-test-targets.js +31 -0
- package/extensions/dm-lens/dist/clients/degradation-ledger.js +306 -0
- package/extensions/dm-lens/dist/clients/demoted-finding-render.js +64 -0
- package/extensions/dm-lens/dist/clients/dependency-checker.js +534 -0
- package/extensions/dm-lens/dist/clients/deps/ast-grep-napi.js +27 -0
- package/extensions/dm-lens/dist/clients/deps/dm-host-deps.js +10 -0
- package/extensions/dm-lens/dist/clients/deps/dm-tui-compat.js +58 -0
- package/extensions/dm-lens/dist/clients/deps/js-yaml.js +7 -0
- package/extensions/dm-lens/dist/clients/deps/minimatch.js +6 -0
- package/extensions/dm-lens/dist/clients/deps/pidusage.js +5 -0
- package/extensions/dm-lens/dist/clients/deps/typebox.js +5 -0
- package/extensions/dm-lens/dist/clients/deps/vscode-jsonrpc.js +8 -0
- package/extensions/dm-lens/dist/clients/deps/web-tree-sitter.js +11 -0
- package/extensions/dm-lens/dist/clients/diagnostic-dispositions.js +334 -0
- package/extensions/dm-lens/dist/clients/diagnostic-line-freshness.js +142 -0
- package/extensions/dm-lens/dist/clients/diagnostic-logger.js +60 -0
- package/extensions/dm-lens/dist/clients/diagnostic-tracker.js +89 -0
- package/extensions/dm-lens/dist/clients/diagnostics-publish.js +134 -0
- package/extensions/dm-lens/dist/clients/disk-change-consumers.js +312 -0
- package/extensions/dm-lens/dist/clients/disk-change-subscribers.js +191 -0
- package/extensions/dm-lens/dist/clients/disk-changes.js +165 -0
- package/extensions/dm-lens/dist/clients/dispatch/adopted-root-runners.js +22 -0
- package/extensions/dm-lens/dist/clients/dispatch/ast-grep-catalog.js +16 -0
- package/extensions/dm-lens/dist/clients/dispatch/auxiliary-lsp.js +162 -0
- package/extensions/dm-lens/dist/clients/dispatch/collect-later-tier.js +25 -0
- package/extensions/dm-lens/dist/clients/dispatch/diagnostic-taxonomy.js +58 -0
- package/extensions/dm-lens/dist/clients/dispatch/dispatcher.js +1240 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-provider-types.js +1 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-rule-runner.js +17 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-runner.js +18 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-scheduler.js +52 -0
- package/extensions/dm-lens/dist/clients/dispatch/fact-store.js +193 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/comment-facts.js +23 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/file-content.js +18 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/function-facts.js +274 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/import-facts.js +169 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/tree-sitter-facts.js +19 -0
- package/extensions/dm-lens/dist/clients/dispatch/facts/try-catch-facts.js +95 -0
- package/extensions/dm-lens/dist/clients/dispatch/finding-policy.js +188 -0
- package/extensions/dm-lens/dist/clients/dispatch/indent-detect.js +227 -0
- package/extensions/dm-lens/dist/clients/dispatch/inline-suppressions.js +52 -0
- package/extensions/dm-lens/dist/clients/dispatch/integration.js +1698 -0
- package/extensions/dm-lens/dist/clients/dispatch/known-runner-ids.js +13 -0
- package/extensions/dm-lens/dist/clients/dispatch/lane-copies.js +23 -0
- package/extensions/dm-lens/dist/clients/dispatch/lazy.js +8 -0
- package/extensions/dm-lens/dist/clients/dispatch/pending-runner-findings.js +133 -0
- package/extensions/dm-lens/dist/clients/dispatch/plan.js +284 -0
- package/extensions/dm-lens/dist/clients/dispatch/pre-edit-seed.js +57 -0
- package/extensions/dm-lens/dist/clients/dispatch/priorities.js +14 -0
- package/extensions/dm-lens/dist/clients/dispatch/rule-id-normalize.js +54 -0
- package/extensions/dm-lens/dist/clients/dispatch/rule-ignores.js +21 -0
- package/extensions/dm-lens/dist/clients/dispatch/rule-policy.js +102 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/async-noise.js +31 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/async-unnecessary-wrapper.js +27 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/cors-wildcard.js +35 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/error-obscuring.js +29 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/error-swallowing.js +29 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/framework-call-noise.js +31 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-complexity.js +41 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-fan-out.js +37 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/high-import-coupling.js +31 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/missing-error-propagation.js +45 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/no-commented-credentials.js +46 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/pass-through-wrappers.js +38 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/placeholder-comments.js +40 -0
- package/extensions/dm-lens/dist/clients/dispatch/rules/unsafe-boundary.js +101 -0
- package/extensions/dm-lens/dist/clients/dispatch/runner-context.js +41 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/actionlint.js +98 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-literal-anchors.js +58 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ast-grep-napi.js +739 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/biome-check.js +196 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/cpp-check.js +190 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/credo.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/cue-vet.js +161 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/dart-analyze.js +151 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/detekt.js +158 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/dotnet-build.js +163 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/elixir-check.js +153 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/eslint.js +99 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/fact-rules.js +20 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/fish-indent.js +120 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/gleam-check.js +100 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/go-vet.js +52 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/golangci-lint.js +105 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/hadolint.js +83 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/helm-lint.js +147 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/helm-render.js +593 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/htmlhint.js +103 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/index.js +100 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/javac.js +82 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ktlint.js +115 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/lsp.js +275 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/markdownlint.js +129 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/mypy.js +70 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/oxlint.js +296 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/php-lint.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/phpstan.js +90 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/prisma-validate.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +307 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/pyright.js +118 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/rubocop.js +79 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/ruff.js +69 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/rust-clippy.js +166 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/shellcheck.js +168 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/shfmt.js +92 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/spellcheck.js +74 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/spotbugs.js +208 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/sqlfluff.js +136 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/stylelint.js +118 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/swiftlint.js +143 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/taplo.js +109 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/terragrunt.js +110 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/tflint.js +104 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/tree-sitter.js +534 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/trivy-config.js +155 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/availability-policy.js +313 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +66 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +62 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/lazy-installer.js +130 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +1143 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +40 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/tool-failure.js +110 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +88 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/utils.js +8 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/vale.js +92 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +170 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/yamllint.js +83 -0
- package/extensions/dm-lens/dist/clients/dispatch/runners/zig-check.js +72 -0
- package/extensions/dm-lens/dist/clients/dispatch/suppress-writer.js +57 -0
- package/extensions/dm-lens/dist/clients/dispatch/tool-profile.js +30 -0
- package/extensions/dm-lens/dist/clients/dispatch/types.js +72 -0
- package/extensions/dm-lens/dist/clients/dispatch/utils/format-utils.js +58 -0
- package/extensions/dm-lens/dist/clients/dispatch/utils/lsp-diagnostics.js +32 -0
- package/extensions/dm-lens/dist/clients/disposition-logger.js +19 -0
- package/extensions/dm-lens/dist/clients/disposition-publish.js +88 -0
- package/extensions/dm-lens/dist/clients/durable-store.js +77 -0
- package/extensions/dm-lens/dist/clients/effective-config.js +170 -0
- package/extensions/dm-lens/dist/clients/env-utils.js +26 -0
- package/extensions/dm-lens/dist/clients/ephemeral-root.js +55 -0
- package/extensions/dm-lens/dist/clients/error-class.js +3 -0
- package/extensions/dm-lens/dist/clients/eval-timestamp.js +2 -0
- package/extensions/dm-lens/dist/clients/event-loop-hold.js +119 -0
- package/extensions/dm-lens/dist/clients/event-loop-monitor.js +84 -0
- package/extensions/dm-lens/dist/clients/extension-log.js +230 -0
- package/extensions/dm-lens/dist/clients/extension-mode.js +20 -0
- package/extensions/dm-lens/dist/clients/feature-hints.js +88 -0
- package/extensions/dm-lens/dist/clients/file-kinds.js +317 -0
- package/extensions/dm-lens/dist/clients/file-mutation-queue.js +91 -0
- package/extensions/dm-lens/dist/clients/file-role.js +50 -0
- package/extensions/dm-lens/dist/clients/file-time.js +112 -0
- package/extensions/dm-lens/dist/clients/file-utils.js +840 -0
- package/extensions/dm-lens/dist/clients/finding-delivery-gate.js +146 -0
- package/extensions/dm-lens/dist/clients/finding-identity.js +79 -0
- package/extensions/dm-lens/dist/clients/fix-run-restore.js +423 -0
- package/extensions/dm-lens/dist/clients/fix-worklog.js +75 -0
- package/extensions/dm-lens/dist/clients/format-events-publish.js +310 -0
- package/extensions/dm-lens/dist/clients/format-service.js +177 -0
- package/extensions/dm-lens/dist/clients/formatters-lazy.js +8 -0
- package/extensions/dm-lens/dist/clients/formatters.js +1367 -0
- package/extensions/dm-lens/dist/clients/freshness-cadence.js +1 -0
- package/extensions/dm-lens/dist/clients/freshness.js +8 -0
- package/extensions/dm-lens/dist/clients/generated-artifacts.js +209 -0
- package/extensions/dm-lens/dist/clients/generation-guard.js +147 -0
- package/extensions/dm-lens/dist/clients/generation-lock.js +181 -0
- package/extensions/dm-lens/dist/clients/git-guard.js +1208 -0
- package/extensions/dm-lens/dist/clients/git-tracked-ignore.js +120 -0
- package/extensions/dm-lens/dist/clients/gitleaks-client.js +290 -0
- package/extensions/dm-lens/dist/clients/go-client.js +47 -0
- package/extensions/dm-lens/dist/clients/govulncheck-client.js +416 -0
- package/extensions/dm-lens/dist/clients/gradle-ktfmt-style.js +177 -0
- package/extensions/dm-lens/dist/clients/grammar-source.js +263 -0
- package/extensions/dm-lens/dist/clients/grammar-wasm-imports.js +48 -0
- package/extensions/dm-lens/dist/clients/gzip-stage-write.js +174 -0
- package/extensions/dm-lens/dist/clients/hard-failure-summary.js +28 -0
- package/extensions/dm-lens/dist/clients/hashline-anchor.js +222 -0
- package/extensions/dm-lens/dist/clients/hook-budgets.js +17 -0
- package/extensions/dm-lens/dist/clients/host-edit-normalize.js +87 -0
- package/extensions/dm-lens/dist/clients/host-ports.js +35 -0
- package/extensions/dm-lens/dist/clients/indent-retarget.js +102 -0
- package/extensions/dm-lens/dist/clients/inline-blocker-dispositions.js +103 -0
- package/extensions/dm-lens/dist/clients/inline-blocker-fields.js +8 -0
- package/extensions/dm-lens/dist/clients/install-diagnostics.js +135 -0
- package/extensions/dm-lens/dist/clients/installer/index.js +3928 -0
- package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh-session.js +17 -0
- package/extensions/dm-lens/dist/clients/installer/managed-tool-refresh.js +721 -0
- package/extensions/dm-lens/dist/clients/instance-reaper-state.js +3 -0
- package/extensions/dm-lens/dist/clients/instance-reaper.js +693 -0
- package/extensions/dm-lens/dist/clients/instance-registry-lock.js +166 -0
- package/extensions/dm-lens/dist/clients/instance-registry-tail.js +17 -0
- package/extensions/dm-lens/dist/clients/instance-registry.js +607 -0
- package/extensions/dm-lens/dist/clients/io-bridge-contract.js +7 -0
- package/extensions/dm-lens/dist/clients/io-bridge.js +357 -0
- package/extensions/dm-lens/dist/clients/jscpd-client.js +311 -0
- package/extensions/dm-lens/dist/clients/json-cache-read.js +25 -0
- package/extensions/dm-lens/dist/clients/knip-client.js +534 -0
- package/extensions/dm-lens/dist/clients/knip-scan-roots.js +26 -0
- package/extensions/dm-lens/dist/clients/language-policy.js +244 -0
- package/extensions/dm-lens/dist/clients/language-profile.js +259 -0
- package/extensions/dm-lens/dist/clients/language-registry.js +468 -0
- package/extensions/dm-lens/dist/clients/latency-logger.js +210 -0
- package/extensions/dm-lens/dist/clients/lazy-import.js +14 -0
- package/extensions/dm-lens/dist/clients/ledger-bounds.js +21 -0
- package/extensions/dm-lens/dist/clients/lens-config.js +254 -0
- package/extensions/dm-lens/dist/clients/lens-engine.js +188 -0
- package/extensions/dm-lens/dist/clients/lens-events.js +105 -0
- package/extensions/dm-lens/dist/clients/lens-flag-registry.js +308 -0
- package/extensions/dm-lens/dist/clients/lens-map.js +980 -0
- package/extensions/dm-lens/dist/clients/line-alignment.js +200 -0
- package/extensions/dm-lens/dist/clients/live-bus-emitter.js +53 -0
- package/extensions/dm-lens/dist/clients/log-cleanup.js +138 -0
- package/extensions/dm-lens/dist/clients/lsp/aggregation.js +89 -0
- package/extensions/dm-lens/dist/clients/lsp/auxiliary-lifecycle.js +23 -0
- package/extensions/dm-lens/dist/clients/lsp/capabilities.js +94 -0
- package/extensions/dm-lens/dist/clients/lsp/cascade-tier.js +318 -0
- package/extensions/dm-lens/dist/clients/lsp/client-registry.js +877 -0
- package/extensions/dm-lens/dist/clients/lsp/client.js +3232 -0
- package/extensions/dm-lens/dist/clients/lsp/config.js +571 -0
- package/extensions/dm-lens/dist/clients/lsp/content-limits.js +21 -0
- package/extensions/dm-lens/dist/clients/lsp/content-scan.js +69 -0
- package/extensions/dm-lens/dist/clients/lsp/created-import-targets.js +134 -0
- package/extensions/dm-lens/dist/clients/lsp/diagnostic-binding.js +113 -0
- package/extensions/dm-lens/dist/clients/lsp/document-drift.js +372 -0
- package/extensions/dm-lens/dist/clients/lsp/edits.js +1060 -0
- package/extensions/dm-lens/dist/clients/lsp/environment-gap.js +186 -0
- package/extensions/dm-lens/dist/clients/lsp/file-server-match.js +26 -0
- package/extensions/dm-lens/dist/clients/lsp/grouping.js +38 -0
- package/extensions/dm-lens/dist/clients/lsp/implicit-scope.js +205 -0
- package/extensions/dm-lens/dist/clients/lsp/index.js +4292 -0
- package/extensions/dm-lens/dist/clients/lsp/inferred-project.js +140 -0
- package/extensions/dm-lens/dist/clients/lsp/jvm-runtime.js +200 -0
- package/extensions/dm-lens/dist/clients/lsp/language.js +26 -0
- package/extensions/dm-lens/dist/clients/lsp/launch.js +606 -0
- package/extensions/dm-lens/dist/clients/lsp/lombok.js +133 -0
- package/extensions/dm-lens/dist/clients/lsp/path-utils.js +1 -0
- package/extensions/dm-lens/dist/clients/lsp/pending-aux-coverage.js +120 -0
- package/extensions/dm-lens/dist/clients/lsp/position-encoding.js +21 -0
- package/extensions/dm-lens/dist/clients/lsp/resolved-config.js +183 -0
- package/extensions/dm-lens/dist/clients/lsp/ruby-drive-dirs.js +42 -0
- package/extensions/dm-lens/dist/clients/lsp/server-config-files.js +11 -0
- package/extensions/dm-lens/dist/clients/lsp/server-covers.js +8 -0
- package/extensions/dm-lens/dist/clients/lsp/server-traits.js +45 -0
- package/extensions/dm-lens/dist/clients/lsp/server.js +2827 -0
- package/extensions/dm-lens/dist/clients/lsp/service-singleton.js +59 -0
- package/extensions/dm-lens/dist/clients/lsp/session-roots.js +83 -0
- package/extensions/dm-lens/dist/clients/lsp/spawn-history.js +15 -0
- package/extensions/dm-lens/dist/clients/lsp/sync-kind.js +30 -0
- package/extensions/dm-lens/dist/clients/lsp/tsserver-sync.js +156 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/capability-snapshot.js +1 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/classification.js +37 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/index.js +3 -0
- package/extensions/dm-lens/dist/clients/lsp/wait-policy/strategies.js +276 -0
- package/extensions/dm-lens/dist/clients/lsp/watch-queue.js +61 -0
- package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-cache.js +395 -0
- package/extensions/dm-lens/dist/clients/lsp/workspace-diagnostics-session.js +42 -0
- package/extensions/dm-lens/dist/clients/lsp/workspace-sweep-hold.js +93 -0
- package/extensions/dm-lens/dist/clients/lsp-budget.js +87 -0
- package/extensions/dm-lens/dist/clients/lsp-document-symbols.js +93 -0
- package/extensions/dm-lens/dist/clients/lsp-lazy.js +8 -0
- package/extensions/dm-lens/dist/clients/lsp-mutation.js +309 -0
- package/extensions/dm-lens/dist/clients/lsp-status.js +35 -0
- package/extensions/dm-lens/dist/clients/map-with-concurrency.js +20 -0
- package/extensions/dm-lens/dist/clients/mcp/analyze.js +302 -0
- package/extensions/dm-lens/dist/clients/mcp/host-shim.js +14 -0
- package/extensions/dm-lens/dist/clients/mcp/ipc.js +344 -0
- package/extensions/dm-lens/dist/clients/mcp/review.js +137 -0
- package/extensions/dm-lens/dist/clients/mcp/session.js +300 -0
- package/extensions/dm-lens/dist/clients/memory-sampler.js +163 -0
- package/extensions/dm-lens/dist/clients/message-end-attribution.js +18 -0
- package/extensions/dm-lens/dist/clients/metrics-client.js +80 -0
- package/extensions/dm-lens/dist/clients/metrics-history.js +242 -0
- package/extensions/dm-lens/dist/clients/middle-man-analysis.js +161 -0
- package/extensions/dm-lens/dist/clients/model-provider.js +31 -0
- package/extensions/dm-lens/dist/clients/module-report-lsp.js +140 -0
- package/extensions/dm-lens/dist/clients/module-report.js +1648 -0
- package/extensions/dm-lens/dist/clients/mutating-tool.js +388 -0
- package/extensions/dm-lens/dist/clients/mutation-attribution.js +173 -0
- package/extensions/dm-lens/dist/clients/mutation-bridge.js +231 -0
- package/extensions/dm-lens/dist/clients/ndjson-logger.js +504 -0
- package/extensions/dm-lens/dist/clients/observed-mutation-sources.js +43 -0
- package/extensions/dm-lens/dist/clients/observed-mutation.js +735 -0
- package/extensions/dm-lens/dist/clients/oldtext-autopatch.js +100 -0
- package/extensions/dm-lens/dist/clients/opaque-mutation-scan.js +541 -0
- package/extensions/dm-lens/dist/clients/opengrep-client.js +224 -0
- package/extensions/dm-lens/dist/clients/opengrep-config.js +57 -0
- package/extensions/dm-lens/dist/clients/opengrep-rule-pack.js +19 -0
- package/extensions/dm-lens/dist/clients/out-of-band-changes.js +329 -0
- package/extensions/dm-lens/dist/clients/package-manager.js +332 -0
- package/extensions/dm-lens/dist/clients/package-root.js +21 -0
- package/extensions/dm-lens/dist/clients/partial-edit-apply.js +341 -0
- package/extensions/dm-lens/dist/clients/path-attribution-telemetry.js +31 -0
- package/extensions/dm-lens/dist/clients/path-birth.js +58 -0
- package/extensions/dm-lens/dist/clients/path-keyed-map.js +57 -0
- package/extensions/dm-lens/dist/clients/path-utils.js +654 -0
- package/extensions/dm-lens/dist/clients/performance-report.js +291 -0
- package/extensions/dm-lens/dist/clients/persist-debounce.js +37 -0
- package/extensions/dm-lens/dist/clients/persist-worker-stats.js +16 -0
- package/extensions/dm-lens/dist/clients/persistent-reverify.js +167 -0
- package/extensions/dm-lens/dist/clients/php-cs-fixer-config.js +15 -0
- package/extensions/dm-lens/dist/clients/pipeline.js +1473 -0
- package/extensions/dm-lens/dist/clients/post-autofix-notice.js +19 -0
- package/extensions/dm-lens/dist/clients/print-mode.js +3 -0
- package/extensions/dm-lens/dist/clients/probe-home-state.js +73 -0
- package/extensions/dm-lens/dist/clients/process-bridge.js +48 -0
- package/extensions/dm-lens/dist/clients/process-singletons.js +69 -0
- package/extensions/dm-lens/dist/clients/process-snapshot.js +130 -0
- package/extensions/dm-lens/dist/clients/project-changes.js +180 -0
- package/extensions/dm-lens/dist/clients/project-conventions.js +152 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/cache.js +91 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/extractors.js +53 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/fresh-fetch.js +413 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +64 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +38 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/gitleaks.js +21 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/govulncheck.js +23 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/jscpd.js +28 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/knip.js +45 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +34 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/opengrep.js +32 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +79 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/runner-adapters/trivy.js +41 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/scanner.js +351 -0
- package/extensions/dm-lens/dist/clients/project-diagnostics/types.js +1 -0
- package/extensions/dm-lens/dist/clients/project-lens-config.js +462 -0
- package/extensions/dm-lens/dist/clients/project-report.js +527 -0
- package/extensions/dm-lens/dist/clients/project-root-markers.js +8 -0
- package/extensions/dm-lens/dist/clients/project-scale.js +60 -0
- package/extensions/dm-lens/dist/clients/project-scan-policy.js +4 -0
- package/extensions/dm-lens/dist/clients/project-snapshot-fingerprint.js +44 -0
- package/extensions/dm-lens/dist/clients/project-snapshot-persist-worker.js +31 -0
- package/extensions/dm-lens/dist/clients/project-snapshot.js +1355 -0
- package/extensions/dm-lens/dist/clients/project-trust.js +104 -0
- package/extensions/dm-lens/dist/clients/python-environment.js +388 -0
- package/extensions/dm-lens/dist/clients/python-provenance.js +551 -0
- package/extensions/dm-lens/dist/clients/quiet-window-config.js +16 -0
- package/extensions/dm-lens/dist/clients/quiet-window.js +129 -0
- package/extensions/dm-lens/dist/clients/read-bridge.js +53 -0
- package/extensions/dm-lens/dist/clients/read-expansion.js +218 -0
- package/extensions/dm-lens/dist/clients/read-guard-branch.js +126 -0
- package/extensions/dm-lens/dist/clients/read-guard-logger.js +186 -0
- package/extensions/dm-lens/dist/clients/read-guard-tool-lines.js +1044 -0
- package/extensions/dm-lens/dist/clients/read-guard.js +1517 -0
- package/extensions/dm-lens/dist/clients/recent-touches.js +126 -0
- package/extensions/dm-lens/dist/clients/redact/secrets.js +386 -0
- package/extensions/dm-lens/dist/clients/resource-sampler.js +344 -0
- package/extensions/dm-lens/dist/clients/reverse-deps.js +227 -0
- package/extensions/dm-lens/dist/clients/review-graph/builder.js +3780 -0
- package/extensions/dm-lens/dist/clients/review-graph/format.js +30 -0
- package/extensions/dm-lens/dist/clients/review-graph/git-identity.js +173 -0
- package/extensions/dm-lens/dist/clients/review-graph/import-resolvers.js +332 -0
- package/extensions/dm-lens/dist/clients/review-graph/persist-worker.js +8 -0
- package/extensions/dm-lens/dist/clients/review-graph/query.js +195 -0
- package/extensions/dm-lens/dist/clients/review-graph/revision-drift.js +3 -0
- package/extensions/dm-lens/dist/clients/review-graph/service.js +60 -0
- package/extensions/dm-lens/dist/clients/review-graph/shared-extraction-ir.js +54 -0
- package/extensions/dm-lens/dist/clients/review-graph/symbol-id.js +29 -0
- package/extensions/dm-lens/dist/clients/review-graph/tsconfig-paths.js +286 -0
- package/extensions/dm-lens/dist/clients/review-graph/types.js +1 -0
- package/extensions/dm-lens/dist/clients/review-graph/workspace-modules.js +374 -0
- package/extensions/dm-lens/dist/clients/review-graph-logger.js +51 -0
- package/extensions/dm-lens/dist/clients/ruff-client.js +107 -0
- package/extensions/dm-lens/dist/clients/rules-scanner.js +70 -0
- package/extensions/dm-lens/dist/clients/run-duration.js +9 -0
- package/extensions/dm-lens/dist/clients/runtime-agent-end.js +831 -0
- package/extensions/dm-lens/dist/clients/runtime-config.js +39 -0
- package/extensions/dm-lens/dist/clients/runtime-context.js +155 -0
- package/extensions/dm-lens/dist/clients/runtime-coordinator.js +1254 -0
- package/extensions/dm-lens/dist/clients/runtime-session.js +1806 -0
- package/extensions/dm-lens/dist/clients/runtime-tool-call.js +1026 -0
- package/extensions/dm-lens/dist/clients/runtime-tool-result.js +2068 -0
- package/extensions/dm-lens/dist/clients/runtime-turn.js +3198 -0
- package/extensions/dm-lens/dist/clients/rust-client.js +46 -0
- package/extensions/dm-lens/dist/clients/safe-spawn.js +1402 -0
- package/extensions/dm-lens/dist/clients/sanitize.js +5 -0
- package/extensions/dm-lens/dist/clients/scan-utils.js +7 -0
- package/extensions/dm-lens/dist/clients/scanner-temp-root.js +8 -0
- package/extensions/dm-lens/dist/clients/scratch-tree-policy.js +63 -0
- package/extensions/dm-lens/dist/clients/search-read-registration.js +76 -0
- package/extensions/dm-lens/dist/clients/secret-findings.js +69 -0
- package/extensions/dm-lens/dist/clients/security-scan-client.js +208 -0
- package/extensions/dm-lens/dist/clients/session-event-guard.js +111 -0
- package/extensions/dm-lens/dist/clients/session-lifecycle.js +309 -0
- package/extensions/dm-lens/dist/clients/session-repository.js +113 -0
- package/extensions/dm-lens/dist/clients/session-scope.js +451 -0
- package/extensions/dm-lens/dist/clients/session-start-observability.js +59 -0
- package/extensions/dm-lens/dist/clients/session-state-store.js +71 -0
- package/extensions/dm-lens/dist/clients/session-summary.js +8 -0
- package/extensions/dm-lens/dist/clients/sessionstart-logger.js +22 -0
- package/extensions/dm-lens/dist/clients/sg-runner.js +642 -0
- package/extensions/dm-lens/dist/clients/sgconfig.js +299 -0
- package/extensions/dm-lens/dist/clients/shared-checkout-guard.js +177 -0
- package/extensions/dm-lens/dist/clients/single-flight.js +53 -0
- package/extensions/dm-lens/dist/clients/situational-tool-telemetry.js +85 -0
- package/extensions/dm-lens/dist/clients/skills-resolver.js +38 -0
- package/extensions/dm-lens/dist/clients/slow-fs.js +77 -0
- package/extensions/dm-lens/dist/clients/smells-rollup.js +118 -0
- package/extensions/dm-lens/dist/clients/source-filter.js +323 -0
- package/extensions/dm-lens/dist/clients/source-walker.js +114 -0
- package/extensions/dm-lens/dist/clients/spawn-output-cap.js +35 -0
- package/extensions/dm-lens/dist/clients/spawn-timeout-cooldown.js +51 -0
- package/extensions/dm-lens/dist/clients/stale-marker.js +1 -0
- package/extensions/dm-lens/dist/clients/startup-scan.js +221 -0
- package/extensions/dm-lens/dist/clients/startup-timing.js +67 -0
- package/extensions/dm-lens/dist/clients/string-utils.js +6 -0
- package/extensions/dm-lens/dist/clients/subagent-mode.js +40 -0
- package/extensions/dm-lens/dist/clients/symbol-containment.js +16 -0
- package/extensions/dm-lens/dist/clients/symbol-types.js +1 -0
- package/extensions/dm-lens/dist/clients/test-runner-client.js +1686 -0
- package/extensions/dm-lens/dist/clients/test-runner-delivery.js +285 -0
- package/extensions/dm-lens/dist/clients/test-target-roots.js +17 -0
- package/extensions/dm-lens/dist/clients/todo-scanner.js +164 -0
- package/extensions/dm-lens/dist/clients/tool-agreement.js +640 -0
- package/extensions/dm-lens/dist/clients/tool-config.js +239 -0
- package/extensions/dm-lens/dist/clients/tool-cwd.js +236 -0
- package/extensions/dm-lens/dist/clients/tool-definition.js +22 -0
- package/extensions/dm-lens/dist/clients/tool-event.js +24 -0
- package/extensions/dm-lens/dist/clients/tool-policy.js +2386 -0
- package/extensions/dm-lens/dist/clients/tool-probe.js +13 -0
- package/extensions/dm-lens/dist/clients/tool-render.js +79 -0
- package/extensions/dm-lens/dist/clients/tool-set-policy.js +106 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-cache.js +206 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-client.js +3101 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-logger.js +77 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-navigator.js +198 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-query-loader.js +401 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-shared.js +87 -0
- package/extensions/dm-lens/dist/clients/tree-sitter-symbol-extractor.js +984 -0
- package/extensions/dm-lens/dist/clients/trivy-client.js +335 -0
- package/extensions/dm-lens/dist/clients/tui-fit.js +26 -0
- package/extensions/dm-lens/dist/clients/turn-context.js +48 -0
- package/extensions/dm-lens/dist/clients/turn-end/delivery-holds.js +59 -0
- package/extensions/dm-lens/dist/clients/turn-end/lane.js +1 -0
- package/extensions/dm-lens/dist/clients/turn-end/lanes/govulncheck.js +54 -0
- package/extensions/dm-lens/dist/clients/turn-end/lanes/secrets.js +131 -0
- package/extensions/dm-lens/dist/clients/turn-summary-render.js +56 -0
- package/extensions/dm-lens/dist/clients/turn-summary.js +84 -0
- package/extensions/dm-lens/dist/clients/typos-config.js +9 -0
- package/extensions/dm-lens/dist/clients/user-notify.js +15 -0
- package/extensions/dm-lens/dist/clients/vanished-instance-marker.js +18 -0
- package/extensions/dm-lens/dist/clients/warm-attach.js +232 -0
- package/extensions/dm-lens/dist/clients/widget-state.js +1014 -0
- package/extensions/dm-lens/dist/clients/word-index-logger.js +24 -0
- package/extensions/dm-lens/dist/clients/word-index-store.js +222 -0
- package/extensions/dm-lens/dist/clients/word-index.js +1503 -0
- package/extensions/dm-lens/dist/clients/workspace-topology.js +274 -0
- package/extensions/dm-lens/dist/clients/write-ordering-guard.js +28 -0
- package/extensions/dm-lens/dist/clients/zizmor-config.js +160 -0
- package/extensions/dm-lens/dist/i18n.js +67 -0
- package/extensions/dm-lens/dist/index.js +2144 -0
- package/extensions/dm-lens/dist/mcp/analyze-cli.js +205 -0
- package/extensions/dm-lens/dist/mcp/build-staleness.js +55 -0
- package/extensions/dm-lens/dist/mcp/cli.js +96 -0
- package/extensions/dm-lens/dist/mcp/server.js +1241 -0
- package/extensions/dm-lens/dist/mcp/tool-arguments.js +134 -0
- package/extensions/dm-lens/dist/mcp/worker.js +41 -0
- package/extensions/dm-lens/dist/scripts/lib/process-scan.mjs +375 -0
- package/extensions/dm-lens/dist/scripts/lib/skills-predicate.mjs +53 -0
- package/extensions/dm-lens/dist/scripts/lib/web-tree-sitter-dir.mjs +51 -0
- package/extensions/dm-lens/dist/tools/activate-tools.js +63 -0
- package/extensions/dm-lens/dist/tools/ast-grep-outline.js +128 -0
- package/extensions/dm-lens/dist/tools/ast-grep-replace.js +234 -0
- package/extensions/dm-lens/dist/tools/ast-grep-search.js +690 -0
- package/extensions/dm-lens/dist/tools/effective-config.js +59 -0
- package/extensions/dm-lens/dist/tools/lens-diagnostic-mark.js +251 -0
- package/extensions/dm-lens/dist/tools/lens-diagnostics.js +1693 -0
- package/extensions/dm-lens/dist/tools/lsp-diagnostics.js +1397 -0
- package/extensions/dm-lens/dist/tools/lsp-navigation.js +1301 -0
- package/extensions/dm-lens/dist/tools/lsp-structured-output.js +277 -0
- package/extensions/dm-lens/dist/tools/module-report.js +333 -0
- package/extensions/dm-lens/dist/tools/project-report.js +72 -0
- package/extensions/dm-lens/dist/tools/render-compact.js +272 -0
- package/extensions/dm-lens/dist/tools/scan-progress.js +31 -0
- package/extensions/dm-lens/dist/tools/shared.js +46 -0
- package/extensions/dm-lens/dist/tools/symbol-search.js +133 -0
- package/extensions/dm-mcp-adapter/dist/abort.js +35 -0
- package/extensions/dm-mcp-adapter/dist/agent-dir.js +45 -0
- package/extensions/dm-mcp-adapter/dist/agent-plugin-loader.js +392 -0
- package/extensions/dm-mcp-adapter/dist/agent-plugin-provenance.js +26 -0
- package/extensions/dm-mcp-adapter/dist/bearer-command-resolver.js +184 -0
- package/extensions/dm-mcp-adapter/dist/claude-plugin-loader.js +350 -0
- package/extensions/dm-mcp-adapter/dist/config.js +1984 -0
- package/extensions/dm-mcp-adapter/dist/consent-manager.js +84 -0
- package/extensions/dm-mcp-adapter/dist/elicitation-handler.js +374 -0
- package/extensions/dm-mcp-adapter/dist/errors.js +225 -0
- package/extensions/dm-mcp-adapter/dist/extraction-settings.js +43 -0
- package/extensions/dm-mcp-adapter/dist/http-ca.js +75 -0
- package/extensions/dm-mcp-adapter/dist/jev-client.js +359 -0
- package/extensions/dm-mcp-adapter/dist/jev-contracts.js +1 -0
- package/extensions/dm-mcp-adapter/dist/jev-key-store.js +189 -0
- package/extensions/dm-mcp-adapter/dist/json-schema-validator.js +70 -0
- package/extensions/dm-mcp-adapter/dist/lifecycle.js +387 -0
- package/extensions/dm-mcp-adapter/dist/logger.js +115 -0
- package/extensions/dm-mcp-adapter/dist/mcp-auth-fetch.js +86 -0
- package/extensions/dm-mcp-adapter/dist/mcp-auth-flow.js +956 -0
- package/extensions/dm-mcp-adapter/dist/mcp-auth.js +998 -0
- package/extensions/dm-mcp-adapter/dist/mcp-bearer-store.js +182 -0
- package/extensions/dm-mcp-adapter/dist/mcp-callback-server.js +380 -0
- package/extensions/dm-mcp-adapter/dist/mcp-oauth-provider.js +525 -0
- package/extensions/dm-mcp-adapter/dist/mcp-probe.js +151 -0
- package/extensions/dm-mcp-adapter/dist/mcp-tasks.js +339 -0
- package/extensions/dm-mcp-adapter/dist/mcp-trace.js +220 -0
- package/extensions/dm-mcp-adapter/dist/metadata-cache.js +411 -0
- package/extensions/dm-mcp-adapter/dist/npx-resolver.js +465 -0
- package/extensions/dm-mcp-adapter/dist/output-shape.js +312 -0
- package/extensions/dm-mcp-adapter/dist/package-mcp-loader.js +144 -0
- package/extensions/dm-mcp-adapter/dist/project-server-trust.js +274 -0
- package/extensions/dm-mcp-adapter/dist/request-headers-command.js +310 -0
- package/extensions/dm-mcp-adapter/dist/resource-tools.js +7 -0
- package/extensions/dm-mcp-adapter/dist/runtime-owner.js +95 -0
- package/extensions/dm-mcp-adapter/dist/sampling-handler.js +219 -0
- package/extensions/dm-mcp-adapter/dist/script-tools.js +72 -0
- package/extensions/dm-mcp-adapter/dist/secure-keyring.js +191 -0
- package/extensions/dm-mcp-adapter/dist/semantic-settings.js +51 -0
- package/extensions/dm-mcp-adapter/dist/server-log.js +19 -0
- package/extensions/dm-mcp-adapter/dist/server-manager.js +1635 -0
- package/extensions/dm-mcp-adapter/dist/session-approvals.js +127 -0
- package/extensions/dm-mcp-adapter/dist/session-recovery.js +83 -0
- package/extensions/dm-mcp-adapter/dist/state.js +1 -0
- package/extensions/dm-mcp-adapter/dist/task-entries.js +60 -0
- package/extensions/dm-mcp-adapter/dist/task-jobs.js +259 -0
- package/extensions/dm-mcp-adapter/dist/ts-shape.js +157 -0
- package/extensions/dm-mcp-adapter/dist/types.js +293 -0
- package/extensions/dm-mcp-adapter/dist/ui-app-bridge-helpers.js +36 -0
- package/extensions/dm-mcp-adapter/dist/ui-resource-handler.js +204 -0
- package/extensions/dm-mcp-adapter/dist/ui-stream-types.js +58 -0
- package/extensions/dm-mcp-adapter/dist/ui-tool-visibility.js +26 -0
- package/extensions/dm-mcp-adapter/dist/unix-socket-transport.js +83 -0
- package/extensions/dm-mcp-adapter/dist/utils.js +444 -0
- package/extensions/dm-mcp-adapter/mcp-keyring-helper.cjs +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-activate.js +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-instructions.js +1 -1
- package/extensions/dm-ponytail/hooks/ponytail-mode-tracker.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,4292 @@
|
|
|
1
|
+
import { CASCADE_DIAGNOSTICS_TTL_MS } from "../cascade-types.js";
|
|
2
|
+
import * as nodeFs from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { pathToFileURL, URL } from "node:url";
|
|
7
|
+
import { BoundedFifoMap } from "../bounded-cache.js";
|
|
8
|
+
import { CONTENT_HASH_MAX_BYTES, stampContentBytes } from "../content-stamp.js";
|
|
9
|
+
import { FILE_CHANGED, FILE_CREATED, watchedTypeForOpen } from "./watch-queue.js";
|
|
10
|
+
import { noteWorkspaceFilesChangedOnDisk, workspaceFileCreatedAtFor } from "./workspace-diagnostics-session.js";
|
|
11
|
+
import { emitCreatedImportScanRollupAtSessionEnd, goPackageFilesToAnnounce, importTargetsToAnnounce } from "./created-import-targets.js";
|
|
12
|
+
import { getProjectIgnoreMatcher, isExcludedDirName } from "../file-utils.js";
|
|
13
|
+
import { applyAuxiliarySuppressions } from "../dispatch/auxiliary-lsp.js";
|
|
14
|
+
import { detectFileRole } from "../file-role.js";
|
|
15
|
+
import { emitBounded } from "../bounded-telemetry.js";
|
|
16
|
+
import { logLatency, phaseFinished, phaseStarted } from "../latency-logger.js";
|
|
17
|
+
import { incrementDegradationCount, recordDegradationOnce } from "../degradation-ledger.js";
|
|
18
|
+
import { shouldPreferPullOnlyDiagnostics } from "../lsp-budget.js";
|
|
19
|
+
import { sampleProcessTreeCpuPercent } from "../resource-sampler.js";
|
|
20
|
+
import { bounded, withDeadline, withTimeout } from "../deadline-utils.js";
|
|
21
|
+
import { HOOK_WALL_BUDGET_MS } from "../hook-budgets.js";
|
|
22
|
+
import { getAmbientAbortSignal } from "../safe-spawn.js";
|
|
23
|
+
import { abortDeferredLspWork } from "../deferred-lsp-work.js";
|
|
24
|
+
import { acquireWorkspaceSweepHold, clearWorkspaceSweepHoldForSessionStart } from "./workspace-sweep-hold.js";
|
|
25
|
+
import { DocumentDriftTracker, fingerprintDocumentContent } from "./document-drift.js";
|
|
26
|
+
import { exceedsLspSyncLimits } from "./content-limits.js";
|
|
27
|
+
import { captureAuxPublicationBacklog, markPendingAuxiliaryCoverage, napiFallbackCoveredSince } from "./pending-aux-coverage.js";
|
|
28
|
+
import { isAtOrAboveHomeDir, normalizeMapKey, realpathOrResolve, uriToPath } from "../path-utils.js";
|
|
29
|
+
import { recordLspMutation } from "../lsp-mutation.js";
|
|
30
|
+
import { auxiliaryCoverageGap, auxiliaryPublicationEvidence, bindingStateLabel, composeBoundToCurrentDisk, createDiskBindingCache, hashDiagnosticContent, primaryUnavailableCause, resolveTouchVerdict, touchCoverageGap } from "./diagnostic-binding.js";
|
|
31
|
+
import { getServersForFileWithConfig } from "./config.js";
|
|
32
|
+
import { serverIdsForConfigFile } from "./server-config-files.js";
|
|
33
|
+
import { disabledPrimaries, getSessionRootsForTelemetry } from "./session-roots.js";
|
|
34
|
+
import { configureLspServiceLifecycle, getOwnedLspService, peekOwnedLspService, resetOwnedLspService } from "./service-singleton.js";
|
|
35
|
+
import { groupFilesByPrimaryServer, runPerServerGroups } from "./grouping.js";
|
|
36
|
+
export { groupFilesByPrimaryServer, runPerServerGroups } from "./grouping.js";
|
|
37
|
+
import { BROKEN_BASE_COOLDOWN_MS, ClientRegistry } from "./client-registry.js";
|
|
38
|
+
export { getLspClientCeiling, getLspIdleEvictMs, getLspIdleEvictMsForRoot, mergeInitializationOptions } from "./client-registry.js";
|
|
39
|
+
import { getLanguageId } from "./language.js";
|
|
40
|
+
import { getReverseDepsFromIndex, loadReverseDependencyIndexFromSnapshot } from "../reverse-deps.js";
|
|
41
|
+
import { declinesLooseFileRoot, getServerById, resetClassicTsRepairGuard, resetLspLaunchAvailabilityGeneration } from "./server.js";
|
|
42
|
+
import { isAuxiliary, serverTraits } from "./server-traits.js";
|
|
43
|
+
import { auxWaitBudgetMs, readEnvAuxGraceMs, DEFAULT_AUX_GRACE_CEILING_MS } from "./auxiliary-lifecycle.js";
|
|
44
|
+
import { classifyCascadeWaitTier, classifyServerWaitTier, getStrategy } from "./wait-policy/index.js";
|
|
45
|
+
function textDocumentSaveOf(client) {
|
|
46
|
+
if (typeof client.getSaveOptions !== "function")
|
|
47
|
+
return;
|
|
48
|
+
const save = client.getSaveOptions();
|
|
49
|
+
if (!save)
|
|
50
|
+
return "none";
|
|
51
|
+
return save.includeText ? "save+text" : "save";
|
|
52
|
+
}
|
|
53
|
+
const WORKSPACE_ATTRIBUTION_CLIENT_CAP = 16;
|
|
54
|
+
const AUX_WAIT_DEMOTION_THRESHOLD = 5;
|
|
55
|
+
const AUX_WAIT_DEMOTION_RATIO = 0.9;
|
|
56
|
+
const AUX_WAIT_REPROMOTION_THRESHOLD = 5;
|
|
57
|
+
const AUX_WAIT_REPROMOTION_RATIO = 0.5;
|
|
58
|
+
import { raceToCompletion } from "./aggregation.js";
|
|
59
|
+
import { applyWorkspaceEdit, captureRenameExpectedContent, mergeWorkspaceTextEditsByPriority, summarizeWorkspaceEdit, validateWorkspaceEdit } from "./edits.js";
|
|
60
|
+
import { buildScopeKey, createWorkspaceDiagnosticsCacheContext } from "./workspace-diagnostics-cache.js";
|
|
61
|
+
import { demoteInferredProjectDiagnostics } from "./inferred-project.js";
|
|
62
|
+
import { attemptTsserverSyncDiagnostics } from "./tsserver-sync.js";
|
|
63
|
+
import { isWarmAttached, tryWarmAttachedDiagnostics } from "../warm-attach.js";
|
|
64
|
+
import { getSuccessfulLspSpawnDurationMs } from "./spawn-history.js";
|
|
65
|
+
function destinationUriPreservingSpelling(oldUri, oldFilePath, newFilePath) {
|
|
66
|
+
const canonical = pathToFileURL(newFilePath);
|
|
67
|
+
try {
|
|
68
|
+
const original = new URL(oldUri);
|
|
69
|
+
const authority = /^file:\/\/([^/]*)/i.exec(oldUri)?.[1] ?? "";
|
|
70
|
+
if (original.protocol !== "file:" || original.host !== "" && original.hostname !== "localhost") {
|
|
71
|
+
return canonical.href;
|
|
72
|
+
}
|
|
73
|
+
const canonicalDestination = () => `${original.protocol}//${authority}${canonical.pathname}`;
|
|
74
|
+
const oldParent = path.resolve(path.dirname(oldFilePath));
|
|
75
|
+
const newParent = path.resolve(path.dirname(newFilePath));
|
|
76
|
+
if (normalizeMapKey(oldParent) !== normalizeMapKey(newParent)) {
|
|
77
|
+
return canonicalDestination();
|
|
78
|
+
}
|
|
79
|
+
const slash = original.pathname.lastIndexOf("/");
|
|
80
|
+
if (slash < 0)
|
|
81
|
+
return canonicalDestination();
|
|
82
|
+
let rawName = canonical.pathname.slice(canonical.pathname.lastIndexOf("/") + 1);
|
|
83
|
+
const oldRawName = original.pathname.slice(slash + 1);
|
|
84
|
+
const oldName = decodeURIComponent(oldRawName);
|
|
85
|
+
const expectedOldName = path.basename(oldFilePath);
|
|
86
|
+
if (oldName.toLowerCase() !== expectedOldName.toLowerCase()) {
|
|
87
|
+
return canonicalDestination();
|
|
88
|
+
}
|
|
89
|
+
for (const match of oldRawName.matchAll(/%([0-9a-f]{2})/gi)) {
|
|
90
|
+
const encoded = match[0];
|
|
91
|
+
const decoded = String.fromCharCode(Number.parseInt(match[1], 16));
|
|
92
|
+
rawName = rawName.split(decoded).join(encoded);
|
|
93
|
+
}
|
|
94
|
+
return `${original.protocol}//${authority}${original.pathname.slice(0, slash + 1)}${rawName}`;
|
|
95
|
+
} catch {
|
|
96
|
+
return canonical.href;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const NOTIFY_BACKPRESSURE_BROKEN_AFTER = 3;
|
|
100
|
+
const NAV_CLIENT_WAIT_TIMEOUT_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_NAV_CLIENT_WAIT_MS ?? "1500", 10) || 1500);
|
|
101
|
+
const TOUCH_DEBOUNCE_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_TOUCH_DEBOUNCE_MS ?? "1500", 10) || 1500);
|
|
102
|
+
const RECENT_TOUCH_CAP = 800;
|
|
103
|
+
const SCOPED_DEPENDENCY_TOUCH_MAX = 32;
|
|
104
|
+
const RENAME_NOTIFY_TIMEOUT_MS = Math.max(50, Number.parseInt(process.env.DM_LENS_LSP_RENAME_NOTIFY_TIMEOUT_MS ?? "1500", 10) || 1500);
|
|
105
|
+
async function runRenameNotify(send, timeoutMs) {
|
|
106
|
+
try {
|
|
107
|
+
await withTimeout(send(), timeoutMs);
|
|
108
|
+
return { ok: true };
|
|
109
|
+
} catch (err) {
|
|
110
|
+
const timedOut = err instanceof Error && err.message.startsWith("Timeout after");
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
error: err instanceof Error ? err.message : String(err),
|
|
114
|
+
disposition: timedOut ? "timedOut" : "rejected"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function documentIsOpenOn(client, filePath) {
|
|
119
|
+
const probe = client.isDocumentOpen;
|
|
120
|
+
if (typeof probe !== "function")
|
|
121
|
+
return false;
|
|
122
|
+
try {
|
|
123
|
+
return probe.call(client, filePath) === true;
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function tsserverSyncChannel(client) {
|
|
129
|
+
return {
|
|
130
|
+
getAdvertisedCommands: async () => client.getAdvertisedCommands(),
|
|
131
|
+
executeCommand: (_filePath, command, args) => client.executeCommand(command, args)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function warmupTimeoutMs() {
|
|
135
|
+
const raw = Number.parseInt(process.env.DM_LENS_LSP_WARMUP_TIMEOUT_MS ?? "", 10);
|
|
136
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 20000;
|
|
137
|
+
}
|
|
138
|
+
function warmupRetryBackoffMs() {
|
|
139
|
+
const raw = Number.parseInt(process.env.DM_LENS_LSP_WARMUP_RETRY_BACKOFF_MS ?? "", 10);
|
|
140
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : 500;
|
|
141
|
+
}
|
|
142
|
+
function readEnvDiagnosticsWaitMs() {
|
|
143
|
+
const raw = process.env.DM_LENS_LSP_DIAGNOSTICS_MAX_WAIT_MS;
|
|
144
|
+
if (raw === undefined)
|
|
145
|
+
return;
|
|
146
|
+
const parsed = Number.parseInt(raw, 10);
|
|
147
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
148
|
+
return;
|
|
149
|
+
return parsed;
|
|
150
|
+
}
|
|
151
|
+
function readTsserverSyncGraceMs() {
|
|
152
|
+
const raw = process.env.DM_LENS_TSSERVER_SYNC_GRACE_MS;
|
|
153
|
+
if (raw === undefined)
|
|
154
|
+
return 300;
|
|
155
|
+
const parsed = Number.parseInt(raw, 10);
|
|
156
|
+
if (!Number.isFinite(parsed) || parsed < 0)
|
|
157
|
+
return 300;
|
|
158
|
+
return parsed;
|
|
159
|
+
}
|
|
160
|
+
const MAX_TOUCH_CANDIDATES = 8;
|
|
161
|
+
const DIAGNOSTICS_SEMANTIC_SETTLE_THRESHOLD_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_DIAGNOSTICS_SEMANTIC_THRESHOLD_MS ?? "250", 10) || 250);
|
|
162
|
+
const DIAGNOSTICS_SEMANTIC_SETTLE_WAIT_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_DIAGNOSTICS_SEMANTIC_SETTLE_MS ?? "400", 10) || 400);
|
|
163
|
+
const EARLY_UNBLOCK_GRACE_MS = Math.max(0, Number.parseInt(process.env.DM_LENS_LSP_EARLY_UNBLOCK_GRACE_MS ?? "400", 10) || 400);
|
|
164
|
+
function unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath) {
|
|
165
|
+
if (spawned.some((entry) => !isAuxiliary(entry.info)))
|
|
166
|
+
return { serverIds: [], disabledServerIds: [], cause: "unstarted" };
|
|
167
|
+
const { disabledServerIds, fallbackServerIds } = disabledPrimaries(filePath);
|
|
168
|
+
const serverIds = [
|
|
169
|
+
...new Set([...resolvedPrimaryRoots.keys(), ...disabledServerIds])
|
|
170
|
+
];
|
|
171
|
+
return {
|
|
172
|
+
serverIds,
|
|
173
|
+
disabledServerIds,
|
|
174
|
+
cause: primaryUnavailableCause(serverIds, disabledServerIds, fallbackServerIds)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function mergeLspDiagnostics(diagnostics) {
|
|
178
|
+
const merged = [];
|
|
179
|
+
const seen = new Set;
|
|
180
|
+
for (const diagnostic of diagnostics) {
|
|
181
|
+
const key = [
|
|
182
|
+
diagnostic.range.start.line,
|
|
183
|
+
diagnostic.range.start.character,
|
|
184
|
+
diagnostic.message
|
|
185
|
+
].join(":");
|
|
186
|
+
if (seen.has(key))
|
|
187
|
+
continue;
|
|
188
|
+
seen.add(key);
|
|
189
|
+
merged.push(diagnostic);
|
|
190
|
+
}
|
|
191
|
+
return merged;
|
|
192
|
+
}
|
|
193
|
+
function attributeDiagnostics(serverId, diagnostics) {
|
|
194
|
+
return diagnostics.map((diagnostic) => ({ ...diagnostic, serverId }));
|
|
195
|
+
}
|
|
196
|
+
const SWEEP_REASON_FOR_CAUSE = {
|
|
197
|
+
unstarted: "primary_unavailable",
|
|
198
|
+
either: "primary_unavailable",
|
|
199
|
+
disabled: "primary_disabled",
|
|
200
|
+
disabledFallback: "primary_disabled_fallback"
|
|
201
|
+
};
|
|
202
|
+
export function createSweepIndexGate() {
|
|
203
|
+
const seen = new Set;
|
|
204
|
+
return {
|
|
205
|
+
consumeFirstTouch(serverId) {
|
|
206
|
+
if (seen.has(serverId))
|
|
207
|
+
return false;
|
|
208
|
+
seen.add(serverId);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const WORKSPACE_DIAGNOSTICS_CONCURRENCY = 8;
|
|
214
|
+
const WORKSPACE_SWEEP_PREOPEN_CHUNK_SIZE = (() => {
|
|
215
|
+
const raw = Number(process.env.DM_LENS_LSP_WORKSPACE_PREOPEN_CHUNK);
|
|
216
|
+
return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 8;
|
|
217
|
+
})();
|
|
218
|
+
const WORKSPACE_SWEEP_EXCLUDED_SERVER_IDS = new Set([
|
|
219
|
+
"opengrep"
|
|
220
|
+
]);
|
|
221
|
+
function notifyWriteBudgetMs() {
|
|
222
|
+
const raw = Number(process.env.DM_LENS_LSP_NOTIFY_BUDGET_MS);
|
|
223
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 2000;
|
|
224
|
+
}
|
|
225
|
+
function primaryServerWaitFloorMs(filePath, maxWaitMs) {
|
|
226
|
+
const serverWaitOverrideMs = getServersForFileWithConfig(filePath).filter((s) => !isAuxiliary(s)).reduce((max, server) => Math.max(max, server.clientWaitTimeoutMs ?? 0), 0);
|
|
227
|
+
return Math.max(maxWaitMs ?? 0, serverWaitOverrideMs);
|
|
228
|
+
}
|
|
229
|
+
const NOTIFY_WEDGED_BUDGET_MULTIPLIER = 5;
|
|
230
|
+
function notifyWedgedMs() {
|
|
231
|
+
return notifyWriteBudgetMs() * NOTIFY_WEDGED_BUDGET_MULTIPLIER;
|
|
232
|
+
}
|
|
233
|
+
const NOTIFY_WEDGED_EWMA_MULTIPLIER = 2;
|
|
234
|
+
const NOTIFY_WEDGED_CAP_MS = 60000;
|
|
235
|
+
function notifyWedgedCapMs() {
|
|
236
|
+
const raw = Number(process.env.DM_LENS_LSP_NOTIFY_WEDGED_CAP_MS);
|
|
237
|
+
return Number.isFinite(raw) && raw > 0 ? raw : NOTIFY_WEDGED_CAP_MS;
|
|
238
|
+
}
|
|
239
|
+
function notifyStallCpuSampleMs() {
|
|
240
|
+
const raw = Number(process.env.DM_LENS_LSP_NOTIFY_STALL_CPU_SAMPLE_MS);
|
|
241
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 1200;
|
|
242
|
+
}
|
|
243
|
+
const NOTIFY_STALL_CPU_BUSY_FLOOR_PERCENT = 10;
|
|
244
|
+
function workspacePullBudgetMs() {
|
|
245
|
+
const raw = Number(process.env.DM_LENS_LSP_WORKSPACE_PULL_MS);
|
|
246
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 30000;
|
|
247
|
+
}
|
|
248
|
+
const DEFAULT_MAX_WORKSPACE_DIAGNOSTIC_FILES = 5000;
|
|
249
|
+
function getMaxWorkspaceDiagnosticFiles() {
|
|
250
|
+
const override = Number.parseInt(process.env.DM_LENS_LSP_WORKSPACE_MAX_FILES ?? "", 10);
|
|
251
|
+
return Number.isFinite(override) && override > 0 ? override : DEFAULT_MAX_WORKSPACE_DIAGNOSTIC_FILES;
|
|
252
|
+
}
|
|
253
|
+
async function collectWorkspaceDiagnosticFiles(root, maxFiles = getMaxWorkspaceDiagnosticFiles(), signal, homeDir) {
|
|
254
|
+
const files = [];
|
|
255
|
+
if (isAtOrAboveHomeDir(realpathOrResolve(root), realpathOrResolve(homeDir ?? os.homedir())))
|
|
256
|
+
return files;
|
|
257
|
+
const ignoreMatcher = getProjectIgnoreMatcher(root);
|
|
258
|
+
await ignoreMatcher.ensureTrackedIndex();
|
|
259
|
+
async function walk(current) {
|
|
260
|
+
if (signal?.aborted || files.length >= maxFiles)
|
|
261
|
+
return;
|
|
262
|
+
let entries;
|
|
263
|
+
try {
|
|
264
|
+
entries = await nodeFs.promises.readdir(current, {
|
|
265
|
+
withFileTypes: true
|
|
266
|
+
});
|
|
267
|
+
} catch {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
for (const entry of entries) {
|
|
271
|
+
if (signal?.aborted || files.length >= maxFiles)
|
|
272
|
+
return;
|
|
273
|
+
if (entry.isSymbolicLink())
|
|
274
|
+
continue;
|
|
275
|
+
const full = path.join(current, entry.name);
|
|
276
|
+
if (entry.isDirectory()) {
|
|
277
|
+
if (isExcludedDirName(entry.name))
|
|
278
|
+
continue;
|
|
279
|
+
if (ignoreMatcher.isIgnored(full, true))
|
|
280
|
+
continue;
|
|
281
|
+
await walk(full);
|
|
282
|
+
} else if (entry.isFile() && getServersForFileWithConfig(full).length > 0 && !ignoreMatcher.isIgnored(full, false)) {
|
|
283
|
+
files.push(full);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
await walk(root);
|
|
288
|
+
return files;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export class LSPService {
|
|
292
|
+
static MAX_SIBLING_ANNOUNCEMENTS = 1024;
|
|
293
|
+
static MAX_UNHELD_STAMPS = 4096;
|
|
294
|
+
state;
|
|
295
|
+
unheldStamps = new BoundedFifoMap(LSPService.MAX_UNHELD_STAMPS);
|
|
296
|
+
siblingAnnouncementHashes = new BoundedFifoMap(LSPService.MAX_SIBLING_ANNOUNCEMENTS);
|
|
297
|
+
firstContactWaits = new Map;
|
|
298
|
+
auxWaitPressureStreak = new Map;
|
|
299
|
+
auxWaitFastAnswerStreak = new Map;
|
|
300
|
+
demotedAuxiliaryServerIds = new Set;
|
|
301
|
+
demotedAuxiliaryBudgets = new Map;
|
|
302
|
+
lastKnownDiagnostics = new Map;
|
|
303
|
+
lastKnownContentHash = new Map;
|
|
304
|
+
documentDrift = new DocumentDriftTracker({
|
|
305
|
+
holdsDocument: (filePath) => this.hasLiveClientHoldingDocument(filePath),
|
|
306
|
+
onCapOverflow: ({ tracked, cap }) => {
|
|
307
|
+
logLatency({
|
|
308
|
+
type: "phase",
|
|
309
|
+
phase: "lsp_document_drift_cap",
|
|
310
|
+
filePath: "",
|
|
311
|
+
durationMs: 0,
|
|
312
|
+
metadata: { tracked, cap }
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
diskBindingCache = createDiskBindingCache();
|
|
317
|
+
lastDiagnosticsHealth = new Map;
|
|
318
|
+
recentTouches = new Map;
|
|
319
|
+
notifyWriteBackpressureStreak = new Map;
|
|
320
|
+
auxNotifyDrainLatencyEwma = new Map;
|
|
321
|
+
auxNotifyInflight = new Map;
|
|
322
|
+
outstandingAuxNotifyWrites = new Map;
|
|
323
|
+
static MAX_NOTIFY_STALL_DEMOTIONS = 50;
|
|
324
|
+
notifyStallDemotions = new BoundedFifoMap(LSPService.MAX_NOTIFY_STALL_DEMOTIONS);
|
|
325
|
+
shutdownController = new AbortController;
|
|
326
|
+
clientRegistry;
|
|
327
|
+
constructor(generationHandoff, sessionCwd) {
|
|
328
|
+
this.clientRegistry = new ClientRegistry({
|
|
329
|
+
releaseNotifyWrite: (key) => this.releaseOutstandingAuxNotifyWrite(key),
|
|
330
|
+
forgetReadiness: (key) => this.forgetReadiness(key),
|
|
331
|
+
forgetNotifyBacklog: (key) => {
|
|
332
|
+
this.auxNotifyInflight.delete(key);
|
|
333
|
+
this.auxNotifyDrainLatencyEwma.delete(key);
|
|
334
|
+
},
|
|
335
|
+
clearStallDemotion: (key) => {
|
|
336
|
+
this.notifyStallDemotions.delete(key);
|
|
337
|
+
},
|
|
338
|
+
rearmFirstContact: (serverId) => {
|
|
339
|
+
this.state.diagnosticsPublished.delete(serverId);
|
|
340
|
+
this.state.diagnosticsUnsupported.delete(serverId);
|
|
341
|
+
this.firstContactWaits.delete(serverId);
|
|
342
|
+
},
|
|
343
|
+
noteDiagnosticsPublished: (serverId) => {
|
|
344
|
+
this.state.diagnosticsPublished.add(serverId);
|
|
345
|
+
}
|
|
346
|
+
}, generationHandoff, sessionCwd);
|
|
347
|
+
this.state = {
|
|
348
|
+
clients: this.clientRegistry.clients,
|
|
349
|
+
servers: new Map,
|
|
350
|
+
broken: this.clientRegistry.broken,
|
|
351
|
+
inFlight: this.clientRegistry.inFlight,
|
|
352
|
+
clientSpawnedAt: this.clientRegistry.clientSpawnedAt,
|
|
353
|
+
demonstratedReady: new Set,
|
|
354
|
+
demonstratedCold: new Set,
|
|
355
|
+
diagnosticsPublished: new Set,
|
|
356
|
+
diagnosticsUnsupported: new Set
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
isAuxiliaryWaitDemoted(serverId, root) {
|
|
360
|
+
return this.demotedAuxiliaryServerIds.has(`${serverId}:${normalizeMapKey(root ?? "")}`);
|
|
361
|
+
}
|
|
362
|
+
noteAuxiliaryWait(key, budgetMs, elapsedMs) {
|
|
363
|
+
if (this.demotedAuxiliaryServerIds.has(key))
|
|
364
|
+
return;
|
|
365
|
+
if (elapsedMs < AUX_WAIT_DEMOTION_RATIO * budgetMs) {
|
|
366
|
+
this.auxWaitPressureStreak.delete(key);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const streak = (this.auxWaitPressureStreak.get(key) ?? 0) + 1;
|
|
370
|
+
if (streak >= AUX_WAIT_DEMOTION_THRESHOLD) {
|
|
371
|
+
this.demotedAuxiliaryServerIds.add(key);
|
|
372
|
+
this.demotedAuxiliaryBudgets.set(key, budgetMs);
|
|
373
|
+
this.auxWaitPressureStreak.delete(key);
|
|
374
|
+
this.auxWaitFastAnswerStreak.delete(key);
|
|
375
|
+
recordDegradationOnce({
|
|
376
|
+
kind: "aux_wait_demoted",
|
|
377
|
+
subject: key,
|
|
378
|
+
reason: "auxiliary reached at least 90% of its declared wait budget for five consecutive dispatches"
|
|
379
|
+
});
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this.auxWaitPressureStreak.set(key, streak);
|
|
383
|
+
}
|
|
384
|
+
noteAuxiliaryLateAnswer(key, elapsedMs) {
|
|
385
|
+
if (!this.demotedAuxiliaryServerIds.has(key))
|
|
386
|
+
return;
|
|
387
|
+
const budgetMs = this.demotedAuxiliaryBudgets.get(key);
|
|
388
|
+
if (budgetMs === undefined || elapsedMs >= AUX_WAIT_REPROMOTION_RATIO * budgetMs) {
|
|
389
|
+
this.auxWaitFastAnswerStreak.delete(key);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const streak = (this.auxWaitFastAnswerStreak.get(key) ?? 0) + 1;
|
|
393
|
+
if (streak < AUX_WAIT_REPROMOTION_THRESHOLD) {
|
|
394
|
+
this.auxWaitFastAnswerStreak.set(key, streak);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
this.demotedAuxiliaryServerIds.delete(key);
|
|
398
|
+
this.demotedAuxiliaryBudgets.delete(key);
|
|
399
|
+
this.auxWaitFastAnswerStreak.delete(key);
|
|
400
|
+
recordDegradationOnce({
|
|
401
|
+
kind: "aux_wait_repromoted",
|
|
402
|
+
subject: key,
|
|
403
|
+
reason: "auxiliary produced five consecutive late answers below half its declared wait budget"
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
checkDestroyed() {
|
|
407
|
+
return this.clientRegistry.checkDestroyed();
|
|
408
|
+
}
|
|
409
|
+
announceToSiblings(filePath, content, contentHash = this.hashContent(content)) {
|
|
410
|
+
const normalizedPath = normalizeMapKey(filePath);
|
|
411
|
+
if (this.siblingAnnouncementHashes.get(normalizedPath) === contentHash) {
|
|
412
|
+
return Promise.resolve();
|
|
413
|
+
}
|
|
414
|
+
this.announceCreatedFiles([filePath]);
|
|
415
|
+
return Promise.all(getServersForFileWithConfig(filePath).map((server) => this.clientRegistry.resolveServerRoot(server, filePath).then((root) => {
|
|
416
|
+
if (!root)
|
|
417
|
+
return false;
|
|
418
|
+
const ownKey = `${server.id}:${normalizeMapKey(root)}`;
|
|
419
|
+
return this.notifyLiveClientsForServer(server.id, filePath, 2, ownKey, false);
|
|
420
|
+
}))).then(() => {
|
|
421
|
+
this.siblingAnnouncementHashes.set(normalizedPath, contentHash);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
notifyLiveClientsForServer(serverId, filePath, type, ownKey, includeOwn) {
|
|
425
|
+
let notified = false;
|
|
426
|
+
const prefix = `${serverId}:`;
|
|
427
|
+
for (const [key, client] of this.state.clients) {
|
|
428
|
+
if (!key.startsWith(prefix) || !includeOwn && key === ownKey || !client.isAlive()) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
client.notify.watchedFileChange(filePath, type);
|
|
432
|
+
notified = true;
|
|
433
|
+
}
|
|
434
|
+
return notified;
|
|
435
|
+
}
|
|
436
|
+
async withClientForFileUse(filePath, maxWaitMs, hardCapMs, use) {
|
|
437
|
+
while (!this.checkDestroyed()) {
|
|
438
|
+
const entry = await this.getClientForFile(filePath, maxWaitMs, hardCapMs);
|
|
439
|
+
if (!entry)
|
|
440
|
+
return;
|
|
441
|
+
const leaseKey = await this.clientRegistry.acquireClientLease(entry, filePath);
|
|
442
|
+
if (!leaseKey)
|
|
443
|
+
continue;
|
|
444
|
+
try {
|
|
445
|
+
return await use(entry);
|
|
446
|
+
} finally {
|
|
447
|
+
this.clientRegistry.releaseClientLease(leaseKey, entry.info);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
releaseOutstandingAuxNotifyWrite(key, token) {
|
|
453
|
+
const current = this.outstandingAuxNotifyWrites.get(key);
|
|
454
|
+
if (!current || token !== undefined && current !== token)
|
|
455
|
+
return;
|
|
456
|
+
clearTimeout(current.wedgeTimer);
|
|
457
|
+
this.outstandingAuxNotifyWrites.delete(key);
|
|
458
|
+
current.resolveSettled();
|
|
459
|
+
}
|
|
460
|
+
shouldSkipTouch(filePath, sentContentHash, waitForDiagnostics, spawned) {
|
|
461
|
+
if (waitForDiagnostics)
|
|
462
|
+
return false;
|
|
463
|
+
if (spawned.length === 0)
|
|
464
|
+
return false;
|
|
465
|
+
return spawned.every((entry) => this.shouldSkipNotify(filePath, sentContentHash, entry.info.id, entry.client));
|
|
466
|
+
}
|
|
467
|
+
shouldSkipNotify(filePath, sentContentHash, serverId, client) {
|
|
468
|
+
if (TOUCH_DEBOUNCE_MS <= 0)
|
|
469
|
+
return false;
|
|
470
|
+
const previous = this.recentTouches.get(this.recentTouchKey(filePath, serverId));
|
|
471
|
+
if (!previous)
|
|
472
|
+
return false;
|
|
473
|
+
if (previous.client.deref() !== client)
|
|
474
|
+
return false;
|
|
475
|
+
if (workspaceFileCreatedAtFor((id) => id === client.serverId, (root) => root === client.root) >= previous.touchedAt) {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
const sentContent = client.getSentContent?.(filePath);
|
|
479
|
+
if (sentContent === undefined || sentContent.hash !== sentContentHash) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
return client.hasNotifyInFlight?.(filePath) === false;
|
|
483
|
+
}
|
|
484
|
+
saveDebouncedPush(filePath, entry, saved, sentContentHash, retryOnFailure = true) {
|
|
485
|
+
if (!saved)
|
|
486
|
+
return;
|
|
487
|
+
const previous = this.recentTouches.get(this.recentTouchKey(filePath, entry.info.id));
|
|
488
|
+
if (!previous || entry.client.getSentContent?.(filePath)?.savedHash === sentContentHash)
|
|
489
|
+
return;
|
|
490
|
+
if (entry.client.getSaveOptions?.() === undefined)
|
|
491
|
+
return;
|
|
492
|
+
const save = entry.client.notify.save;
|
|
493
|
+
if (!save)
|
|
494
|
+
return;
|
|
495
|
+
const recover = () => {
|
|
496
|
+
if (retryOnFailure) {
|
|
497
|
+
this.saveDebouncedPush(filePath, entry, true, sentContentHash, false);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
recordDegradationOnce({
|
|
501
|
+
kind: "lsp-did-save-recovery-exhausted",
|
|
502
|
+
subject: entry.info.id,
|
|
503
|
+
reason: "a standalone didSave and its one retry both sent nothing",
|
|
504
|
+
metadata: { filePath }
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
save.call(entry.client.notify, filePath, true).then((sent) => {
|
|
508
|
+
if (sent === false)
|
|
509
|
+
recover();
|
|
510
|
+
}, recover);
|
|
511
|
+
return entry.info.id;
|
|
512
|
+
}
|
|
513
|
+
recentTouchKey(filePath, serverId) {
|
|
514
|
+
return `${normalizeMapKey(filePath)}:${serverId}`;
|
|
515
|
+
}
|
|
516
|
+
markTouched(filePath, serverId, client) {
|
|
517
|
+
const key = this.recentTouchKey(filePath, serverId);
|
|
518
|
+
this.recentTouches.delete(key);
|
|
519
|
+
this.recentTouches.set(key, {
|
|
520
|
+
touchedAt: Date.now(),
|
|
521
|
+
client: new WeakRef(client)
|
|
522
|
+
});
|
|
523
|
+
while (this.recentTouches.size > RECENT_TOUCH_CAP) {
|
|
524
|
+
const oldest = this.recentTouches.keys().next();
|
|
525
|
+
if (oldest.done)
|
|
526
|
+
break;
|
|
527
|
+
this.recentTouches.delete(oldest.value);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async demonstratedReadyKeyFor(server, filePath) {
|
|
531
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
532
|
+
if (!root)
|
|
533
|
+
return;
|
|
534
|
+
return `${server.id}:${normalizeMapKey(root)}`;
|
|
535
|
+
}
|
|
536
|
+
forgetReadiness(key) {
|
|
537
|
+
this.state.demonstratedReady.delete(key);
|
|
538
|
+
this.state.demonstratedCold.delete(key);
|
|
539
|
+
this.notifyWriteBackpressureStreak.delete(key);
|
|
540
|
+
}
|
|
541
|
+
markDemonstratedReadyKey(key) {
|
|
542
|
+
this.state.demonstratedReady.add(key);
|
|
543
|
+
this.state.demonstratedCold.delete(key);
|
|
544
|
+
}
|
|
545
|
+
recordNotifyWriteBackpressure(key, entry, filePath) {
|
|
546
|
+
if (!key)
|
|
547
|
+
return;
|
|
548
|
+
if (this.state.clients.get(key) !== entry.client)
|
|
549
|
+
return;
|
|
550
|
+
const streak = (this.notifyWriteBackpressureStreak.get(key) ?? 0) + 1;
|
|
551
|
+
if (streak < NOTIFY_BACKPRESSURE_BROKEN_AFTER) {
|
|
552
|
+
this.notifyWriteBackpressureStreak.set(key, streak);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
this.notifyWriteBackpressureStreak.delete(key);
|
|
556
|
+
this.demoteNotifyStallCpuGuarded(key, entry, filePath, {
|
|
557
|
+
consecutiveTimeouts: NOTIFY_BACKPRESSURE_BROKEN_AFTER
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
async demoteNotifyStallCpuGuarded(key, entry, filePath, reason) {
|
|
561
|
+
if (this.state.clients.get(key) !== entry.client)
|
|
562
|
+
return;
|
|
563
|
+
this.clientRegistry.clearIdleEvictionTimer(key);
|
|
564
|
+
const verdict = await this.notifyStallCpuVerdict(entry);
|
|
565
|
+
if (verdict.cpuVerdict === "busy") {
|
|
566
|
+
if (this.state.clients.get(key) === entry.client) {
|
|
567
|
+
this.clientRegistry.scheduleIdleEviction(key, entry.info);
|
|
568
|
+
}
|
|
569
|
+
this.logNotifyStallCpuBusy(key, entry, filePath, 0, verdict);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (this.state.clients.get(key) !== entry.client)
|
|
573
|
+
return;
|
|
574
|
+
this.demoteForNotifyStall(key, entry, filePath, {
|
|
575
|
+
...reason,
|
|
576
|
+
discriminator: "consecutive-timeouts",
|
|
577
|
+
cpuVerdict: verdict.cpuVerdict
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
async notifyStallCpuVerdict(entry) {
|
|
581
|
+
const pid = entry.client.getProcessPid?.();
|
|
582
|
+
if (pid === undefined || !(Number.isFinite(pid) && pid > 0)) {
|
|
583
|
+
return { cpuVerdict: "unmeasured", cpuPercent: null };
|
|
584
|
+
}
|
|
585
|
+
const sample = await sampleProcessTreeCpuPercent(pid, notifyStallCpuSampleMs(), NOTIFY_STALL_CPU_BUSY_FLOOR_PERCENT);
|
|
586
|
+
if (!sample.measured) {
|
|
587
|
+
return { cpuVerdict: "unmeasured", cpuPercent: null };
|
|
588
|
+
}
|
|
589
|
+
if (sample.busy) {
|
|
590
|
+
return { cpuVerdict: "busy", cpuPercent: sample.cpuPercent };
|
|
591
|
+
}
|
|
592
|
+
return { cpuVerdict: "flat", cpuPercent: sample.cpuPercent };
|
|
593
|
+
}
|
|
594
|
+
logNotifyStallCpuBusy(key, entry, filePath, outstandingMs, verdict, extra = {}) {
|
|
595
|
+
emitBounded("lsp_notify_stall_cpu_busy", `${key}:${normalizeMapKey(filePath)}`, {
|
|
596
|
+
type: "phase",
|
|
597
|
+
durationMs: outstandingMs,
|
|
598
|
+
metadata: {
|
|
599
|
+
serverId: entry.info.id,
|
|
600
|
+
clientKey: key,
|
|
601
|
+
outstandingMs,
|
|
602
|
+
cpuPercent: verdict.cpuPercent ?? null,
|
|
603
|
+
...extra
|
|
604
|
+
}
|
|
605
|
+
}, {
|
|
606
|
+
ledgerKind: "lsp-notify-stall-cpu-busy",
|
|
607
|
+
risingEdgePer: "identity"
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
auxNotifyWedgeBudgetMs(key) {
|
|
611
|
+
let budgetMs = notifyWedgedMs();
|
|
612
|
+
const ewma = this.auxNotifyDrainLatencyEwma.get(key);
|
|
613
|
+
if (ewma !== undefined && ewma > 0) {
|
|
614
|
+
const unacked = this.auxNotifyInflight.get(key)?.unacked ?? 0;
|
|
615
|
+
budgetMs = Math.max(budgetMs, NOTIFY_WEDGED_EWMA_MULTIPLIER * ewma * unacked);
|
|
616
|
+
}
|
|
617
|
+
return Math.min(budgetMs, notifyWedgedCapMs());
|
|
618
|
+
}
|
|
619
|
+
demoteForNotifyStall(key, entry, filePath, reason) {
|
|
620
|
+
if (this.state.clients.get(key) !== entry.client)
|
|
621
|
+
return;
|
|
622
|
+
this.clientRegistry.coolDown(key, BROKEN_BASE_COOLDOWN_MS);
|
|
623
|
+
this.notifyStallDemotions.set(key, Date.now());
|
|
624
|
+
entry.client.shutdown().catch(() => {});
|
|
625
|
+
this.clientRegistry.retireClient(key);
|
|
626
|
+
logLatency({
|
|
627
|
+
type: "phase",
|
|
628
|
+
phase: "lsp_notify_backpressure_broken",
|
|
629
|
+
filePath: normalizeMapKey(filePath),
|
|
630
|
+
durationMs: 0,
|
|
631
|
+
metadata: {
|
|
632
|
+
serverId: entry.info.id,
|
|
633
|
+
cooldownMs: BROKEN_BASE_COOLDOWN_MS,
|
|
634
|
+
...reason
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
retractNotifyWriteBackpressure(key, serverId, filePath, outstandingMs, client) {
|
|
639
|
+
if (this.state.clients.get(key) !== client)
|
|
640
|
+
return;
|
|
641
|
+
const streak = this.notifyWriteBackpressureStreak.get(key);
|
|
642
|
+
if (!streak)
|
|
643
|
+
return;
|
|
644
|
+
const streakAfter = streak - 1;
|
|
645
|
+
if (streakAfter <= 0)
|
|
646
|
+
this.notifyWriteBackpressureStreak.delete(key);
|
|
647
|
+
else
|
|
648
|
+
this.notifyWriteBackpressureStreak.set(key, streakAfter);
|
|
649
|
+
logLatency({
|
|
650
|
+
type: "phase",
|
|
651
|
+
phase: "lsp_notify_write_late_landed",
|
|
652
|
+
filePath: normalizeMapKey(filePath),
|
|
653
|
+
durationMs: outstandingMs,
|
|
654
|
+
metadata: { serverId, outstandingMs, streakAfter }
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
noteAuxNotifyIssued(key, client) {
|
|
658
|
+
const record = this.auxNotifyInflight.get(key);
|
|
659
|
+
if (record && record.client === client) {
|
|
660
|
+
record.unacked += 1;
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
this.auxNotifyInflight.set(key, { client, unacked: 1 });
|
|
664
|
+
}
|
|
665
|
+
noteAuxNotifyDrainLatency(key, durationMs, outstanding, record) {
|
|
666
|
+
if (!(outstanding > 0 && durationMs > 0))
|
|
667
|
+
return;
|
|
668
|
+
if (record && this.auxNotifyInflight.get(key) !== record)
|
|
669
|
+
return;
|
|
670
|
+
const perWriteMs = durationMs / outstanding;
|
|
671
|
+
const prev = this.auxNotifyDrainLatencyEwma.get(key);
|
|
672
|
+
this.auxNotifyDrainLatencyEwma.set(key, prev === undefined ? perWriteMs : 0.5 * perWriteMs + 0.5 * prev);
|
|
673
|
+
}
|
|
674
|
+
async decideNotifyStallTeardown(key, entry, filePath, token) {
|
|
675
|
+
if (this.state.clients.get(key) !== entry.client || this.outstandingAuxNotifyWrites.get(key) !== token) {
|
|
676
|
+
throw new Error("stale notify generation");
|
|
677
|
+
}
|
|
678
|
+
const outstandingMs = Date.now() - token.startedAt;
|
|
679
|
+
const armedBudgetMs = token.armedBudgetMs;
|
|
680
|
+
if (outstandingMs >= notifyWedgedCapMs()) {
|
|
681
|
+
return {
|
|
682
|
+
action: "demote",
|
|
683
|
+
reason: {
|
|
684
|
+
outstandingMs,
|
|
685
|
+
discriminator: "cap-exceeded",
|
|
686
|
+
budgetMs: armedBudgetMs
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
const verdict = await this.notifyStallCpuVerdict(entry);
|
|
691
|
+
if (this.state.clients.get(key) !== entry.client || this.outstandingAuxNotifyWrites.get(key) !== token) {
|
|
692
|
+
throw new Error("stale notify generation");
|
|
693
|
+
}
|
|
694
|
+
if (verdict.cpuVerdict === "busy") {
|
|
695
|
+
this.logNotifyStallCpuBusy(key, entry, filePath, outstandingMs, verdict, {
|
|
696
|
+
budgetMs: armedBudgetMs
|
|
697
|
+
});
|
|
698
|
+
return { action: "rearm", budgetMs: this.auxNotifyWedgeBudgetMs(key) };
|
|
699
|
+
}
|
|
700
|
+
return {
|
|
701
|
+
action: "demote",
|
|
702
|
+
reason: {
|
|
703
|
+
outstandingMs,
|
|
704
|
+
discriminator: verdict.cpuVerdict === "unmeasured" ? "budget-exceeded" : "budget-exceeded-cpu-flat",
|
|
705
|
+
budgetMs: armedBudgetMs,
|
|
706
|
+
ewmaInputMs: this.auxNotifyDrainLatencyEwma.get(key),
|
|
707
|
+
unackedDepth: this.auxNotifyInflight.get(key)?.unacked ?? 0,
|
|
708
|
+
cpuVerdict: verdict.cpuVerdict,
|
|
709
|
+
cpuPercent: verdict.cpuPercent ?? null
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
auxNotifyBacklogAtCeiling(key, entry) {
|
|
714
|
+
const record = this.auxNotifyInflight.get(key);
|
|
715
|
+
if (!record || record.client !== entry.client)
|
|
716
|
+
return false;
|
|
717
|
+
if (record.gateOpen)
|
|
718
|
+
return false;
|
|
719
|
+
return record.unacked >= serverTraits(entry.info).notifyInflightLimit;
|
|
720
|
+
}
|
|
721
|
+
async paceAuxNotify(key, entry, filePath, waitMs, context) {
|
|
722
|
+
const record = this.auxNotifyInflight.get(key);
|
|
723
|
+
if (!record)
|
|
724
|
+
return;
|
|
725
|
+
if (record.client !== entry.client) {
|
|
726
|
+
this.auxNotifyInflight.delete(key);
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
if (record.gateOpen)
|
|
730
|
+
return;
|
|
731
|
+
const traits = serverTraits(entry.info);
|
|
732
|
+
const limit = traits.notifyInflightLimit;
|
|
733
|
+
if (record.unacked < limit)
|
|
734
|
+
return;
|
|
735
|
+
const ping = traits.replyOrdering === "threaded" ? undefined : entry.client.pingLiveness;
|
|
736
|
+
if (!ping) {
|
|
737
|
+
record.unacked = 0;
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (waitMs <= 0) {
|
|
741
|
+
this.openAuxNotifyGate(key, entry, filePath, context, {
|
|
742
|
+
unacked: record.unacked,
|
|
743
|
+
limit,
|
|
744
|
+
waitMs,
|
|
745
|
+
durationMs: 0
|
|
746
|
+
});
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
if (!record.drain) {
|
|
750
|
+
const startedAt = Date.now();
|
|
751
|
+
const outstanding = record.unacked;
|
|
752
|
+
const client = entry.client;
|
|
753
|
+
const barrier = (async () => {
|
|
754
|
+
let drained = false;
|
|
755
|
+
try {
|
|
756
|
+
drained = await ping.call(client, waitMs);
|
|
757
|
+
} catch {
|
|
758
|
+
drained = false;
|
|
759
|
+
}
|
|
760
|
+
const current = this.auxNotifyInflight.get(key);
|
|
761
|
+
if (current === record && current.client === client) {
|
|
762
|
+
current.drain = undefined;
|
|
763
|
+
if (drained)
|
|
764
|
+
current.unacked = Math.max(0, current.unacked - outstanding);
|
|
765
|
+
}
|
|
766
|
+
const durationMs = Date.now() - startedAt;
|
|
767
|
+
if (drained)
|
|
768
|
+
this.noteAuxNotifyDrainLatency(key, durationMs, outstanding, record);
|
|
769
|
+
this.noteDrainBarrierOutcome(key, entry, filePath, context, {
|
|
770
|
+
unacked: outstanding,
|
|
771
|
+
limit,
|
|
772
|
+
waitMs,
|
|
773
|
+
durationMs,
|
|
774
|
+
outcome: drained ? "drained" : "stalled"
|
|
775
|
+
});
|
|
776
|
+
return drained;
|
|
777
|
+
})();
|
|
778
|
+
barrier.catch(() => {});
|
|
779
|
+
record.drain = barrier;
|
|
780
|
+
record.stallLogged = false;
|
|
781
|
+
}
|
|
782
|
+
const waitStartedAt = Date.now();
|
|
783
|
+
const drained = await withDeadline(record.drain, {
|
|
784
|
+
ms: waitMs,
|
|
785
|
+
onTimeout: "undefined",
|
|
786
|
+
onReject: "undefined"
|
|
787
|
+
});
|
|
788
|
+
if (drained !== true) {
|
|
789
|
+
this.openAuxNotifyGate(key, entry, filePath, context, {
|
|
790
|
+
unacked: record.unacked,
|
|
791
|
+
limit,
|
|
792
|
+
waitMs,
|
|
793
|
+
durationMs: Date.now() - waitStartedAt
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
openAuxNotifyGate(key, entry, filePath, context, detail) {
|
|
798
|
+
const record = this.auxNotifyInflight.get(key);
|
|
799
|
+
if (record && record.client === entry.client) {
|
|
800
|
+
record.gateOpen = true;
|
|
801
|
+
}
|
|
802
|
+
this.noteDrainBarrierOutcome(key, entry, filePath, context, {
|
|
803
|
+
...detail,
|
|
804
|
+
outcome: "stalled"
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
noteDrainBarrierOutcome(key, entry, filePath, context, detail) {
|
|
808
|
+
const record = this.auxNotifyInflight.get(key);
|
|
809
|
+
if (detail.outcome === "stalled" && record) {
|
|
810
|
+
if (record.stallLogged)
|
|
811
|
+
return;
|
|
812
|
+
record.stallLogged = true;
|
|
813
|
+
}
|
|
814
|
+
this.logDrainBarrier(key, entry, filePath, context, detail);
|
|
815
|
+
}
|
|
816
|
+
logDrainBarrier(key, entry, filePath, context, detail) {
|
|
817
|
+
if (detail.outcome === "stalled") {
|
|
818
|
+
incrementDegradationCount({
|
|
819
|
+
kind: "lsp-notify-inflight-stall",
|
|
820
|
+
subject: `${entry.info.id}:${normalizeMapKey(filePath)}`,
|
|
821
|
+
reason: `notify barrier stalled with ${detail.unacked} unacknowledged writes`
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
logLatency({
|
|
825
|
+
type: "phase",
|
|
826
|
+
phase: "lsp_notify_inflight_barrier",
|
|
827
|
+
filePath: normalizeMapKey(filePath),
|
|
828
|
+
durationMs: detail.durationMs,
|
|
829
|
+
metadata: {
|
|
830
|
+
serverId: entry.info.id,
|
|
831
|
+
clientKey: key,
|
|
832
|
+
source: context.source,
|
|
833
|
+
clientScope: context.clientScope,
|
|
834
|
+
...detail
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
async claimAuxNotifySlot(clientKey, entry, filePath, budgetMs) {
|
|
839
|
+
const deadline = Date.now() + budgetMs;
|
|
840
|
+
for (;; ) {
|
|
841
|
+
const outstanding = this.outstandingAuxNotifyWrites.get(clientKey);
|
|
842
|
+
if (outstanding && outstanding.client !== entry.client) {
|
|
843
|
+
this.releaseOutstandingAuxNotifyWrite(clientKey, outstanding);
|
|
844
|
+
} else if (outstanding) {
|
|
845
|
+
const outstandingMs = Date.now() - outstanding.startedAt;
|
|
846
|
+
const remainingMs = deadline - Date.now();
|
|
847
|
+
if (remainingMs <= 0)
|
|
848
|
+
return { outstandingMs };
|
|
849
|
+
await withDeadline(outstanding.settled, {
|
|
850
|
+
ms: remainingMs,
|
|
851
|
+
onTimeout: "undefined",
|
|
852
|
+
onReject: "undefined"
|
|
853
|
+
});
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
const current = this.state.clients.get(clientKey);
|
|
857
|
+
if (current !== entry.client) {
|
|
858
|
+
return { outstandingMs: 0 };
|
|
859
|
+
}
|
|
860
|
+
let resolveSettled;
|
|
861
|
+
const settled = new Promise((resolve) => {
|
|
862
|
+
resolveSettled = resolve;
|
|
863
|
+
});
|
|
864
|
+
const token = {
|
|
865
|
+
startedAt: Date.now(),
|
|
866
|
+
client: entry.client,
|
|
867
|
+
settled,
|
|
868
|
+
armedBudgetMs: 0,
|
|
869
|
+
wedgeTimer: undefined,
|
|
870
|
+
resolveSettled: () => resolveSettled?.()
|
|
871
|
+
};
|
|
872
|
+
const fireWedge = async () => {
|
|
873
|
+
if (this.outstandingAuxNotifyWrites.get(clientKey) !== token || this.state.clients.get(clientKey) !== entry.client) {
|
|
874
|
+
this.releaseOutstandingAuxNotifyWrite(clientKey, token);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
let decision;
|
|
878
|
+
try {
|
|
879
|
+
decision = await this.decideNotifyStallTeardown(clientKey, entry, filePath, token);
|
|
880
|
+
} catch {
|
|
881
|
+
decision = {
|
|
882
|
+
action: "demote",
|
|
883
|
+
reason: {
|
|
884
|
+
outstandingMs: Date.now() - token.startedAt,
|
|
885
|
+
discriminator: "budget-exceeded",
|
|
886
|
+
budgetMs: token.armedBudgetMs
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
if (this.outstandingAuxNotifyWrites.get(clientKey) !== token || this.state.clients.get(clientKey) !== entry.client) {
|
|
891
|
+
this.releaseOutstandingAuxNotifyWrite(clientKey, token);
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
if (decision.action === "demote") {
|
|
895
|
+
this.demoteForNotifyStall(clientKey, entry, filePath, decision.reason);
|
|
896
|
+
resolveSettled?.();
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
token.wedgeTimer = setTimeout(() => void fireWedge(), decision.budgetMs);
|
|
900
|
+
token.wedgeTimer.unref?.();
|
|
901
|
+
};
|
|
902
|
+
token.armedBudgetMs = this.auxNotifyWedgeBudgetMs(clientKey);
|
|
903
|
+
token.wedgeTimer = setTimeout(() => void fireWedge(), token.armedBudgetMs);
|
|
904
|
+
token.wedgeTimer.unref?.();
|
|
905
|
+
this.outstandingAuxNotifyWrites.set(clientKey, token);
|
|
906
|
+
return {
|
|
907
|
+
release: () => {
|
|
908
|
+
this.releaseOutstandingAuxNotifyWrite(clientKey, token);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
async skippedAuxiliaryServerIds(filePath, clientScope, options, spawned) {
|
|
914
|
+
if (clientScope === "primary")
|
|
915
|
+
return { brokenSkippedServerIds: [], policySkippedServerIds: [] };
|
|
916
|
+
const enabledAuxiliaries = clientScope === "with-auxiliary" ? new Set(options.auxiliaryServerIds ?? []) : undefined;
|
|
917
|
+
const attached = new Set(spawned.map((entry) => entry.info.id));
|
|
918
|
+
const brokenSkippedServerIds = [];
|
|
919
|
+
const policySkippedServerIds = [];
|
|
920
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
921
|
+
if (!isAuxiliary(server))
|
|
922
|
+
continue;
|
|
923
|
+
if (attached.has(server.id))
|
|
924
|
+
continue;
|
|
925
|
+
if (options.excludeServerIds?.has(server.id))
|
|
926
|
+
continue;
|
|
927
|
+
if (enabledAuxiliaries && !enabledAuxiliaries.has(server.id))
|
|
928
|
+
continue;
|
|
929
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
930
|
+
if (!root)
|
|
931
|
+
continue;
|
|
932
|
+
if (declinesLooseFileRoot(server, root)) {
|
|
933
|
+
policySkippedServerIds.push(server.id);
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
const key = `${server.id}:${normalizeMapKey(root)}`;
|
|
937
|
+
const brokenUntil = this.state.broken.get(key);
|
|
938
|
+
if (this.clientRegistry.permanentlyBroken.has(key) || typeof brokenUntil === "number" && brokenUntil > Date.now()) {
|
|
939
|
+
brokenSkippedServerIds.push(server.id);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return { brokenSkippedServerIds, policySkippedServerIds };
|
|
943
|
+
}
|
|
944
|
+
activeClientsForCwd(cwd, priorityServerIds = []) {
|
|
945
|
+
const normalizedCwd = normalizeMapKey(cwd);
|
|
946
|
+
const priority = new Map(priorityServerIds.map((serverId, index) => [serverId, index]));
|
|
947
|
+
const entries = [];
|
|
948
|
+
for (const [key, client] of this.state.clients) {
|
|
949
|
+
if (!client.isAlive())
|
|
950
|
+
continue;
|
|
951
|
+
const separator = key.indexOf(":");
|
|
952
|
+
const serverId = separator >= 0 ? key.slice(0, separator) : key;
|
|
953
|
+
const root = normalizeMapKey(client.root);
|
|
954
|
+
const sameOrNested = root === normalizedCwd || root.startsWith(`${normalizedCwd}/`) || normalizedCwd.startsWith(`${root}/`);
|
|
955
|
+
if (!sameOrNested)
|
|
956
|
+
continue;
|
|
957
|
+
entries.push({ clientKey: key, serverId, client });
|
|
958
|
+
}
|
|
959
|
+
return entries.sort((a, b) => (priority.get(a.serverId) ?? Number.MAX_SAFE_INTEGER) - (priority.get(b.serverId) ?? Number.MAX_SAFE_INTEGER));
|
|
960
|
+
}
|
|
961
|
+
getOpenDocumentPaths(cwd) {
|
|
962
|
+
const paths = new Set;
|
|
963
|
+
for (const { client } of this.activeClientsForCwd(cwd)) {
|
|
964
|
+
try {
|
|
965
|
+
for (const filePath of client.openDocumentPaths?.() ?? [])
|
|
966
|
+
paths.add(filePath);
|
|
967
|
+
} catch {}
|
|
968
|
+
}
|
|
969
|
+
return [...paths];
|
|
970
|
+
}
|
|
971
|
+
getTrackedContent(filePath, cwd, sourceClientKeys) {
|
|
972
|
+
const priorityServerIds = getServersForFileWithConfig(filePath).map((server) => server.id);
|
|
973
|
+
const clients = this.activeClientsForCwd(cwd, priorityServerIds);
|
|
974
|
+
if (sourceClientKeys !== undefined) {
|
|
975
|
+
const sourceSet = new Set(sourceClientKeys);
|
|
976
|
+
const sends = clients.filter(({ clientKey }) => sourceSet.has(clientKey)).flatMap(({ clientKey, client }) => {
|
|
977
|
+
const sent = client.getSentContent?.(filePath);
|
|
978
|
+
return sent === undefined ? [] : [{ ...sent, clientKey }];
|
|
979
|
+
});
|
|
980
|
+
return sends;
|
|
981
|
+
}
|
|
982
|
+
for (const { client } of clients) {
|
|
983
|
+
const sent = client.getSentContent?.(filePath);
|
|
984
|
+
if (sent !== undefined)
|
|
985
|
+
return sent;
|
|
986
|
+
}
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
async getClientForFile(filePath, maxWaitMs, hardCapMs, resolvedRoots, waitSkipReasons) {
|
|
990
|
+
if (this.checkDestroyed())
|
|
991
|
+
return;
|
|
992
|
+
const servers = getServersForFileWithConfig(filePath).filter((s) => !isAuxiliary(s));
|
|
993
|
+
const rootMemo = new Map;
|
|
994
|
+
const partitionCandidates = async () => {
|
|
995
|
+
const resolved = await Promise.all(servers.map(async (server) => {
|
|
996
|
+
let rootFailureReason;
|
|
997
|
+
try {
|
|
998
|
+
return {
|
|
999
|
+
server,
|
|
1000
|
+
root: await this.clientRegistry.resolveServerRootOnce(server, filePath, rootMemo, (reason) => {
|
|
1001
|
+
rootFailureReason = reason;
|
|
1002
|
+
}),
|
|
1003
|
+
reason: rootFailureReason
|
|
1004
|
+
};
|
|
1005
|
+
} catch (error) {
|
|
1006
|
+
return {
|
|
1007
|
+
server,
|
|
1008
|
+
root: undefined,
|
|
1009
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
}));
|
|
1013
|
+
const unrootedReasons = {};
|
|
1014
|
+
for (const entry of resolved) {
|
|
1015
|
+
if (entry.root === undefined && entry.reason !== undefined) {
|
|
1016
|
+
unrootedReasons[entry.server.id] = entry.reason;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return {
|
|
1020
|
+
rooted: resolved.filter((entry) => entry.root !== undefined).map(({ server, root }) => ({ server, root })),
|
|
1021
|
+
unrootedIds: resolved.filter((entry) => entry.root === undefined).map((entry) => entry.server.id),
|
|
1022
|
+
unrootedReasons
|
|
1023
|
+
};
|
|
1024
|
+
};
|
|
1025
|
+
const serverBaseMs = primaryServerWaitFloorMs(filePath, maxWaitMs);
|
|
1026
|
+
const effectiveMaxWaitMs = hardCapMs !== undefined ? serverBaseMs > 0 ? Math.min(serverBaseMs, hardCapMs) : hardCapMs : serverBaseMs;
|
|
1027
|
+
let knownSlowResolve;
|
|
1028
|
+
const knownSlowSentinel = Symbol("lsp-client-wait-known-slow");
|
|
1029
|
+
const knownSlow = new Promise((resolve) => {
|
|
1030
|
+
knownSlowResolve = () => resolve(knownSlowSentinel);
|
|
1031
|
+
});
|
|
1032
|
+
const noteSpawnInFlight = (serverId) => {
|
|
1033
|
+
const knownDurationMs = getSuccessfulLspSpawnDurationMs(serverId);
|
|
1034
|
+
if (knownDurationMs !== undefined && knownDurationMs > effectiveMaxWaitMs * 2) {
|
|
1035
|
+
queueMicrotask(() => knownSlowResolve?.());
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
const withBudget = async () => {
|
|
1039
|
+
if (servers.length === 0)
|
|
1040
|
+
return;
|
|
1041
|
+
let erroredServerId;
|
|
1042
|
+
let erroredOutcome;
|
|
1043
|
+
for (const server of servers) {
|
|
1044
|
+
const acquisition = {
|
|
1045
|
+
outcome: "declined"
|
|
1046
|
+
};
|
|
1047
|
+
const spawned = await this.clientRegistry.ensureClientForServer(filePath, server, resolvedRoots, noteSpawnInFlight, (reported) => {
|
|
1048
|
+
acquisition.outcome = reported;
|
|
1049
|
+
}, rootMemo);
|
|
1050
|
+
if (spawned) {
|
|
1051
|
+
logLatency({
|
|
1052
|
+
type: "phase",
|
|
1053
|
+
phase: "lsp_client_selected",
|
|
1054
|
+
filePath,
|
|
1055
|
+
durationMs: 0,
|
|
1056
|
+
metadata: {
|
|
1057
|
+
serverId: server.id,
|
|
1058
|
+
candidateCount: servers.length,
|
|
1059
|
+
outcome: acquisition.outcome
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
return spawned;
|
|
1063
|
+
}
|
|
1064
|
+
if (acquisition.outcome === "spawn-failure" || acquisition.outcome === "spawn-failure-joined") {
|
|
1065
|
+
if (erroredServerId === undefined) {
|
|
1066
|
+
erroredServerId = server.id;
|
|
1067
|
+
erroredOutcome = acquisition.outcome;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (erroredServerId !== undefined) {
|
|
1072
|
+
logLatency({
|
|
1073
|
+
type: "phase",
|
|
1074
|
+
phase: "lsp_client_selected",
|
|
1075
|
+
filePath,
|
|
1076
|
+
durationMs: 0,
|
|
1077
|
+
metadata: {
|
|
1078
|
+
serverId: erroredServerId,
|
|
1079
|
+
candidateCount: servers.length,
|
|
1080
|
+
outcome: erroredOutcome ?? "spawn-failure"
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
const unavailable = (await Promise.all(servers.map(async (server) => {
|
|
1085
|
+
const root = await this.clientRegistry.resolveServerRootOnce(server, filePath, rootMemo);
|
|
1086
|
+
return {
|
|
1087
|
+
server,
|
|
1088
|
+
key: `${server.id}:${root ? normalizeMapKey(root) : "<unresolved>"}`
|
|
1089
|
+
};
|
|
1090
|
+
}))).filter(({ key }) => !this.clientRegistry.unavailableLogged.has(key));
|
|
1091
|
+
for (const { key } of unavailable)
|
|
1092
|
+
this.clientRegistry.unavailableLogged.add(key);
|
|
1093
|
+
if (unavailable.length === 0)
|
|
1094
|
+
return;
|
|
1095
|
+
logLatency({
|
|
1096
|
+
type: "phase",
|
|
1097
|
+
phase: "lsp_client_unavailable",
|
|
1098
|
+
filePath,
|
|
1099
|
+
durationMs: 0,
|
|
1100
|
+
metadata: {
|
|
1101
|
+
candidateCount: unavailable.length,
|
|
1102
|
+
servers: unavailable.map(({ server }) => server.id)
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
return;
|
|
1106
|
+
};
|
|
1107
|
+
if (!effectiveMaxWaitMs || effectiveMaxWaitMs <= 0) {
|
|
1108
|
+
return withBudget();
|
|
1109
|
+
}
|
|
1110
|
+
const timeoutSentinel = Symbol("lsp-client-wait-timeout");
|
|
1111
|
+
let waitTimer;
|
|
1112
|
+
let waitResult;
|
|
1113
|
+
try {
|
|
1114
|
+
waitResult = await Promise.race([
|
|
1115
|
+
withBudget(),
|
|
1116
|
+
knownSlow,
|
|
1117
|
+
new Promise((resolve) => {
|
|
1118
|
+
waitTimer = setTimeout(() => resolve(timeoutSentinel), effectiveMaxWaitMs);
|
|
1119
|
+
})
|
|
1120
|
+
]);
|
|
1121
|
+
} finally {
|
|
1122
|
+
if (waitTimer)
|
|
1123
|
+
clearTimeout(waitTimer);
|
|
1124
|
+
}
|
|
1125
|
+
if (waitResult === knownSlowSentinel) {
|
|
1126
|
+
const { rooted, unrootedIds, unrootedReasons } = await partitionCandidates();
|
|
1127
|
+
for (const { server, root } of rooted) {
|
|
1128
|
+
const client = this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`);
|
|
1129
|
+
if (client?.isAlive())
|
|
1130
|
+
return { client, info: server };
|
|
1131
|
+
}
|
|
1132
|
+
waitSkipReasons?.add("budget_skipped_known_slow");
|
|
1133
|
+
logLatency({
|
|
1134
|
+
type: "phase",
|
|
1135
|
+
phase: "lsp_client_wait_skipped",
|
|
1136
|
+
filePath,
|
|
1137
|
+
durationMs: 0,
|
|
1138
|
+
metadata: {
|
|
1139
|
+
maxWaitMs: effectiveMaxWaitMs,
|
|
1140
|
+
serverIds: rooted.map(({ server }) => server.id),
|
|
1141
|
+
unrootedCandidates: {
|
|
1142
|
+
count: unrootedIds.length,
|
|
1143
|
+
ids: unrootedIds,
|
|
1144
|
+
...Object.keys(unrootedReasons).length > 0 ? { reasons: unrootedReasons } : {}
|
|
1145
|
+
},
|
|
1146
|
+
reason: "budget_skipped_known_slow"
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
if (waitResult === timeoutSentinel) {
|
|
1152
|
+
const partitionBudgetMs = hardCapMs !== undefined ? Math.min(250, hardCapMs / 4) : 250;
|
|
1153
|
+
const partitioned = await withDeadline(partitionCandidates(), {
|
|
1154
|
+
ms: partitionBudgetMs,
|
|
1155
|
+
onTimeout: "undefined"
|
|
1156
|
+
});
|
|
1157
|
+
const { rooted, unrootedIds, unrootedReasons } = partitioned ?? {
|
|
1158
|
+
rooted: [],
|
|
1159
|
+
unrootedIds: [],
|
|
1160
|
+
unrootedReasons: {}
|
|
1161
|
+
};
|
|
1162
|
+
const knownHealth = [...this.state.clients.entries()].filter(([k]) => rooted.some(({ server }) => k.startsWith(`${server.id}:`))).map(([k, c]) => ({
|
|
1163
|
+
serverId: k.split(":")[0],
|
|
1164
|
+
alive: c.isAlive(),
|
|
1165
|
+
spawnedAt: this.state.clientSpawnedAt.get(k) ?? null
|
|
1166
|
+
}));
|
|
1167
|
+
logLatency({
|
|
1168
|
+
type: "phase",
|
|
1169
|
+
phase: "lsp_client_wait_timeout",
|
|
1170
|
+
filePath,
|
|
1171
|
+
durationMs: effectiveMaxWaitMs,
|
|
1172
|
+
metadata: {
|
|
1173
|
+
maxWaitMs: effectiveMaxWaitMs,
|
|
1174
|
+
serverIds: rooted.map(({ server }) => server.id),
|
|
1175
|
+
unrootedCandidates: {
|
|
1176
|
+
count: unrootedIds.length,
|
|
1177
|
+
ids: unrootedIds,
|
|
1178
|
+
...Object.keys(unrootedReasons).length > 0 ? { reasons: unrootedReasons } : {}
|
|
1179
|
+
},
|
|
1180
|
+
knownClientHealth: knownHealth,
|
|
1181
|
+
...partitioned === undefined ? { partition: "timed-out" } : {}
|
|
1182
|
+
}
|
|
1183
|
+
});
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
return waitResult;
|
|
1187
|
+
}
|
|
1188
|
+
async getClientsForFile(filePath, excludeServerIds, resolvedRoots, auxiliaryRoots) {
|
|
1189
|
+
const allServers = getServersForFileWithConfig(filePath);
|
|
1190
|
+
const servers = excludeServerIds && excludeServerIds.size > 0 ? allServers.filter((s) => !excludeServerIds.has(s.id)) : allServers;
|
|
1191
|
+
if (servers.length === 0)
|
|
1192
|
+
return { clients: [], serverCountAttempted: 0 };
|
|
1193
|
+
const rootedServers = (await Promise.all(servers.map(async (server) => ({
|
|
1194
|
+
server,
|
|
1195
|
+
root: await this.clientRegistry.resolveServerRoot(server, filePath)
|
|
1196
|
+
})))).filter((entry) => entry.root !== undefined);
|
|
1197
|
+
for (const { server, root } of rootedServers)
|
|
1198
|
+
if (isAuxiliary(server))
|
|
1199
|
+
auxiliaryRoots?.set(server.id, normalizeMapKey(root));
|
|
1200
|
+
let serverCountAttempted = 0;
|
|
1201
|
+
const acquisitions = new Map;
|
|
1202
|
+
const acquire = (server) => {
|
|
1203
|
+
serverCountAttempted += 1;
|
|
1204
|
+
return this.clientRegistry.ensureClientForServer(filePath, server, resolvedRoots);
|
|
1205
|
+
};
|
|
1206
|
+
for (const { server } of rootedServers) {
|
|
1207
|
+
const preferred = server.fallbackFor ? acquisitions.get(server.fallbackFor) : undefined;
|
|
1208
|
+
const acquisition = preferred ? preferred.then((entry) => entry === undefined ? acquire(server) : undefined) : acquire(server);
|
|
1209
|
+
acquisitions.set(server.id, acquisition);
|
|
1210
|
+
}
|
|
1211
|
+
const results = await Promise.all(acquisitions.values());
|
|
1212
|
+
const clients = results.filter((entry) => entry !== undefined);
|
|
1213
|
+
return { clients, serverCountAttempted };
|
|
1214
|
+
}
|
|
1215
|
+
async getAuxiliaryClientsForFile(filePath, enabledIds, onOutcome, maxWaitMs, signal, hook) {
|
|
1216
|
+
if (this.checkDestroyed() || enabledIds.size === 0)
|
|
1217
|
+
return [];
|
|
1218
|
+
const servers = getServersForFileWithConfig(filePath).filter((s) => isAuxiliary(s) && enabledIds.has(s.id));
|
|
1219
|
+
if (servers.length === 0)
|
|
1220
|
+
return [];
|
|
1221
|
+
const rootMemo = new Map;
|
|
1222
|
+
const effectiveSignal = signal ?? getAmbientAbortSignal();
|
|
1223
|
+
const effectiveHook = hook ?? "tool_result_edit";
|
|
1224
|
+
const spawned = await Promise.all(servers.map(async (server) => {
|
|
1225
|
+
const acquisition = this.clientRegistry.ensureClientForServer(filePath, server, undefined, undefined, (reported) => onOutcome?.(server.id, reported), rootMemo);
|
|
1226
|
+
if (!maxWaitMs || maxWaitMs <= 0) {
|
|
1227
|
+
return acquisition;
|
|
1228
|
+
}
|
|
1229
|
+
return bounded(acquisition, {
|
|
1230
|
+
ms: maxWaitMs,
|
|
1231
|
+
signal: effectiveSignal,
|
|
1232
|
+
hook: effectiveHook,
|
|
1233
|
+
label: `auxiliary-spawn:${server.id}`
|
|
1234
|
+
});
|
|
1235
|
+
}));
|
|
1236
|
+
return spawned.filter((entry) => Boolean(entry));
|
|
1237
|
+
}
|
|
1238
|
+
async getWarmClientForFile(filePath) {
|
|
1239
|
+
if (this.checkDestroyed())
|
|
1240
|
+
return;
|
|
1241
|
+
const servers = getServersForFileWithConfig(filePath);
|
|
1242
|
+
const missed = [];
|
|
1243
|
+
for (const server of servers) {
|
|
1244
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1245
|
+
if (!root)
|
|
1246
|
+
continue;
|
|
1247
|
+
const key = `${server.id}:${normalizeMapKey(root)}`;
|
|
1248
|
+
const existing = this.state.clients.get(key);
|
|
1249
|
+
if (existing?.isAlive()) {
|
|
1250
|
+
return { client: existing, info: server };
|
|
1251
|
+
}
|
|
1252
|
+
missed.push(key);
|
|
1253
|
+
}
|
|
1254
|
+
if (missed.length > 0) {
|
|
1255
|
+
emitBounded("lsp_warm_client_missing", missed.join(","), {
|
|
1256
|
+
filePath,
|
|
1257
|
+
durationMs: 0,
|
|
1258
|
+
metadata: {
|
|
1259
|
+
serverIds: missed.map((key) => key.slice(0, key.indexOf(":"))),
|
|
1260
|
+
roots: missed.map((key) => key.slice(key.indexOf(":") + 1))
|
|
1261
|
+
}
|
|
1262
|
+
}, {
|
|
1263
|
+
ledgerKind: "lsp-warm-client-missing",
|
|
1264
|
+
risingEdgePer: "identity",
|
|
1265
|
+
reason: `no warm client for ${missed.join(",")}`
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
async hasServerPublishedForFileRoot(serverId, filePath) {
|
|
1271
|
+
if (this.checkDestroyed())
|
|
1272
|
+
return false;
|
|
1273
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
1274
|
+
if (server.id !== serverId)
|
|
1275
|
+
continue;
|
|
1276
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1277
|
+
if (!root)
|
|
1278
|
+
continue;
|
|
1279
|
+
const key = `${server.id}:${normalizeMapKey(root)}`;
|
|
1280
|
+
const client = this.state.clients.get(key);
|
|
1281
|
+
if (client?.isAlive() && client.getDiagnosticsVersionForPath(filePath) > 0) {
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
async readCachedDiagnosticsForServers(filePath, serverIds) {
|
|
1288
|
+
const out = new Map;
|
|
1289
|
+
if (this.checkDestroyed() || serverIds.size === 0)
|
|
1290
|
+
return out;
|
|
1291
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
1292
|
+
if (!serverIds.has(server.id) || out.has(server.id))
|
|
1293
|
+
continue;
|
|
1294
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1295
|
+
if (!root)
|
|
1296
|
+
continue;
|
|
1297
|
+
const key = `${server.id}:${normalizeMapKey(root)}`;
|
|
1298
|
+
const client = this.state.clients.get(key);
|
|
1299
|
+
if (!client?.isAlive()) {
|
|
1300
|
+
const demotedAt = this.notifyStallDemotions.get(key);
|
|
1301
|
+
if (demotedAt !== undefined) {
|
|
1302
|
+
out.set(server.id, {
|
|
1303
|
+
diags: [],
|
|
1304
|
+
notifyStallDemoted: true,
|
|
1305
|
+
demotedAt
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
this.notifyStallDemotions.delete(key);
|
|
1311
|
+
const entry = client.getAllDiagnostics().get(normalizeMapKey(filePath));
|
|
1312
|
+
out.set(server.id, {
|
|
1313
|
+
diags: entry?.diags ?? [],
|
|
1314
|
+
publishedAt: entry?.ts
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
return out;
|
|
1318
|
+
}
|
|
1319
|
+
async observeLateAuxiliaryAnswer(filePath, serverId, elapsedMs) {
|
|
1320
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
1321
|
+
if (server.id !== serverId)
|
|
1322
|
+
continue;
|
|
1323
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1324
|
+
if (root === undefined)
|
|
1325
|
+
return;
|
|
1326
|
+
this.noteAuxiliaryLateAnswer(`${serverId}:${normalizeMapKey(root)}`, elapsedMs);
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
async notifyExternalFileChange(filePath, type) {
|
|
1331
|
+
if (this.checkDestroyed())
|
|
1332
|
+
return;
|
|
1333
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
1334
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1335
|
+
if (!root)
|
|
1336
|
+
continue;
|
|
1337
|
+
this.notifyLiveClientsForServer(server.id, filePath, type, `${server.id}:${normalizeMapKey(root)}`, true);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
notifyOutOfBandFileChanges(changes) {
|
|
1341
|
+
if (this.checkDestroyed() || changes.length === 0)
|
|
1342
|
+
return;
|
|
1343
|
+
for (const { filePath, type } of changes) {
|
|
1344
|
+
const serverIds = new Set([
|
|
1345
|
+
...serverIdsForConfigFile(filePath) ?? [],
|
|
1346
|
+
...getServersForFileWithConfig(filePath).map((server) => server.id)
|
|
1347
|
+
]);
|
|
1348
|
+
for (const serverId of serverIds)
|
|
1349
|
+
this.notifyLiveClientsForServer(serverId, filePath, type, "", true);
|
|
1350
|
+
this.noteUnheldSent(filePath);
|
|
1351
|
+
}
|
|
1352
|
+
for (const client of this.state.clients.values())
|
|
1353
|
+
if (client.isAlive())
|
|
1354
|
+
client.notify.flushWatched?.();
|
|
1355
|
+
}
|
|
1356
|
+
noteUnheldSent(filePath) {
|
|
1357
|
+
const key = normalizeMapKey(filePath);
|
|
1358
|
+
let stat;
|
|
1359
|
+
try {
|
|
1360
|
+
stat = nodeFs.statSync(filePath, { throwIfNoEntry: false });
|
|
1361
|
+
} catch {
|
|
1362
|
+
stat = undefined;
|
|
1363
|
+
}
|
|
1364
|
+
if (stat === undefined) {
|
|
1365
|
+
this.unheldStamps.delete(key);
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1368
|
+
const seen = this.unheldStamps.get(key);
|
|
1369
|
+
if (seen?.size === stat.size && seen.mtimeMs === stat.mtimeMs)
|
|
1370
|
+
return;
|
|
1371
|
+
this.unheldStamps.set(key, { size: stat.size, mtimeMs: stat.mtimeMs });
|
|
1372
|
+
}
|
|
1373
|
+
async restartPrimaryClientsUnder(root) {
|
|
1374
|
+
if (this.checkDestroyed())
|
|
1375
|
+
return 0;
|
|
1376
|
+
return (await this.clientRegistry.restartPrimaryClientsUnder(root)).length;
|
|
1377
|
+
}
|
|
1378
|
+
livePrimaryClientRoots() {
|
|
1379
|
+
if (this.checkDestroyed())
|
|
1380
|
+
return [];
|
|
1381
|
+
return this.clientRegistry.livePrimaryClientRoots();
|
|
1382
|
+
}
|
|
1383
|
+
announceCreatedFiles(filePaths, importTargets = []) {
|
|
1384
|
+
if (this.checkDestroyed() || this.state.clients.size === 0)
|
|
1385
|
+
return;
|
|
1386
|
+
this.sendUnheldChanges(importTargets);
|
|
1387
|
+
const byServer = new Map;
|
|
1388
|
+
for (const filePath of [...filePaths, ...importTargets]) {
|
|
1389
|
+
let stat;
|
|
1390
|
+
try {
|
|
1391
|
+
stat = nodeFs.statSync(filePath);
|
|
1392
|
+
} catch {
|
|
1393
|
+
continue;
|
|
1394
|
+
}
|
|
1395
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
1396
|
+
const entries = byServer.get(server.id) ?? [];
|
|
1397
|
+
entries.push({ filePath, stat });
|
|
1398
|
+
byServer.set(server.id, entries);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
for (const [key, client] of this.state.clients) {
|
|
1402
|
+
if (!client.isAlive())
|
|
1403
|
+
continue;
|
|
1404
|
+
const entries = [...byServer].flatMap(([serverId, list]) => key.startsWith(`${serverId}:`) ? list : []);
|
|
1405
|
+
client.notify.announceCreated(entries);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
sendUnheldChanges(filePaths) {
|
|
1409
|
+
const changed = [];
|
|
1410
|
+
const at = Date.now();
|
|
1411
|
+
for (const filePath of filePaths) {
|
|
1412
|
+
let stat;
|
|
1413
|
+
try {
|
|
1414
|
+
stat = nodeFs.statSync(filePath);
|
|
1415
|
+
} catch {
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
const servers = getServersForFileWithConfig(filePath);
|
|
1419
|
+
if (!this.unheldBytesMoved(filePath, stat, servers))
|
|
1420
|
+
continue;
|
|
1421
|
+
changed.push({ filePath, type: FILE_CHANGED });
|
|
1422
|
+
for (const client of this.liveClientsOf(servers, filePath))
|
|
1423
|
+
noteWorkspaceFilesChangedOnDisk(client.root, [normalizeMapKey(filePath)], at);
|
|
1424
|
+
}
|
|
1425
|
+
if (changed.length === 0)
|
|
1426
|
+
return;
|
|
1427
|
+
this.notifyOutOfBandFileChanges(changed);
|
|
1428
|
+
logLatency({
|
|
1429
|
+
type: "phase",
|
|
1430
|
+
phase: "lsp_unheld_dependency_changed",
|
|
1431
|
+
filePath: changed[0]?.filePath ?? "",
|
|
1432
|
+
durationMs: Date.now() - at,
|
|
1433
|
+
result: `changed:${changed.length}`,
|
|
1434
|
+
metadata: {
|
|
1435
|
+
changed: changed.length,
|
|
1436
|
+
paths: changed.slice(0, 5).map((change) => change.filePath)
|
|
1437
|
+
}
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
unheldBytesMoved(filePath, stat, servers) {
|
|
1441
|
+
const live = this.liveClientsOf(servers, filePath);
|
|
1442
|
+
if (live.every((client) => client.holds))
|
|
1443
|
+
return false;
|
|
1444
|
+
const key = normalizeMapKey(filePath);
|
|
1445
|
+
const seen = this.unheldStamps.get(key);
|
|
1446
|
+
if (seen?.size === stat.size && seen.mtimeMs === stat.mtimeMs)
|
|
1447
|
+
return false;
|
|
1448
|
+
let stamp = { size: stat.size, mtimeMs: stat.mtimeMs };
|
|
1449
|
+
if (stat.size <= CONTENT_HASH_MAX_BYTES) {
|
|
1450
|
+
try {
|
|
1451
|
+
stamp = stampContentBytes(nodeFs.readFileSync(filePath), stat.mtimeMs);
|
|
1452
|
+
} catch (cause) {
|
|
1453
|
+
recordDegradationOnce({
|
|
1454
|
+
kind: "lsp-unheld-dependency-unreadable",
|
|
1455
|
+
subject: key,
|
|
1456
|
+
reason: `could not read a closed module to compare its bytes; a change of its stat is sent as a change: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
this.unheldStamps.set(key, stamp);
|
|
1461
|
+
if (seen === undefined)
|
|
1462
|
+
return live.some((client) => watchedTypeForOpen(stat.mtimeMs, client.launchedAt) === FILE_CREATED);
|
|
1463
|
+
return seen.sha256 === undefined || seen.sha256 !== stamp.sha256;
|
|
1464
|
+
}
|
|
1465
|
+
liveClientsOf(servers, filePath) {
|
|
1466
|
+
const live = [];
|
|
1467
|
+
for (const [key, client] of this.state.clients) {
|
|
1468
|
+
if (!client.isAlive())
|
|
1469
|
+
continue;
|
|
1470
|
+
if (!servers.some((server) => key.startsWith(`${server.id}:`)))
|
|
1471
|
+
continue;
|
|
1472
|
+
live.push({
|
|
1473
|
+
root: client.root,
|
|
1474
|
+
launchedAt: this.clientRegistry.clientLaunchStartedAt.get(key) ?? 0,
|
|
1475
|
+
holds: documentIsOpenOn(client, filePath)
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
return live;
|
|
1479
|
+
}
|
|
1480
|
+
async resyncHeldPrimaries(filePaths, drainMs) {
|
|
1481
|
+
let sent = 0;
|
|
1482
|
+
const sentTo = new Map;
|
|
1483
|
+
for (const filePath of filePaths) {
|
|
1484
|
+
if (this.checkDestroyed())
|
|
1485
|
+
break;
|
|
1486
|
+
const servers = getServersForFileWithConfig(filePath);
|
|
1487
|
+
const exclude = await this.serverIdsNotHoldingDocument(filePath);
|
|
1488
|
+
for (const server of servers)
|
|
1489
|
+
if (isAuxiliary(server))
|
|
1490
|
+
exclude.add(server.id);
|
|
1491
|
+
if (servers.every((server) => exclude.has(server.id)))
|
|
1492
|
+
continue;
|
|
1493
|
+
const readStamp = performance.now();
|
|
1494
|
+
let content;
|
|
1495
|
+
try {
|
|
1496
|
+
content = await fs.readFile(filePath, "utf8");
|
|
1497
|
+
} catch {
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
await this.touchFile(filePath, content, {
|
|
1501
|
+
diagnostics: "none",
|
|
1502
|
+
source: "head_move_primary",
|
|
1503
|
+
clientScope: "all",
|
|
1504
|
+
excludeServerIds: exclude,
|
|
1505
|
+
readStamp
|
|
1506
|
+
});
|
|
1507
|
+
sent += 1;
|
|
1508
|
+
for (const server of servers) {
|
|
1509
|
+
if (exclude.has(server.id))
|
|
1510
|
+
continue;
|
|
1511
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1512
|
+
const key = root ? `${server.id}:${normalizeMapKey(root)}` : undefined;
|
|
1513
|
+
const client = key ? this.state.clients.get(key) : undefined;
|
|
1514
|
+
if (key && client) {
|
|
1515
|
+
const traits = serverTraits(server);
|
|
1516
|
+
const documents = sentTo.get(key)?.documents ?? [];
|
|
1517
|
+
documents.push({ filePath, content, readStamp });
|
|
1518
|
+
sentTo.set(key, {
|
|
1519
|
+
client,
|
|
1520
|
+
ordered: traits.replyOrdering === "single-task-ordered",
|
|
1521
|
+
rechecks: traits.resendRecheck === "rechecks",
|
|
1522
|
+
documents
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
if (sentTo.size === 0)
|
|
1528
|
+
return { sent, drained: true };
|
|
1529
|
+
await Promise.all([...sentTo.values()].flatMap(({ client, rechecks, documents }) => (rechecks ? documents : []).slice(0, -1).map(({ filePath, content, readStamp }) => client.notify.open(filePath, content, getLanguageId(filePath) ?? "plaintext", undefined, undefined, undefined, readStamp))));
|
|
1530
|
+
const answers = await Promise.all([...sentTo.values()].map(async ({ client, ordered }) => {
|
|
1531
|
+
if (!ordered)
|
|
1532
|
+
return false;
|
|
1533
|
+
try {
|
|
1534
|
+
return await client.pingLiveness?.(drainMs) ?? true;
|
|
1535
|
+
} catch {
|
|
1536
|
+
return false;
|
|
1537
|
+
}
|
|
1538
|
+
}));
|
|
1539
|
+
return { sent, drained: answers.every(Boolean) };
|
|
1540
|
+
}
|
|
1541
|
+
async resyncGitChangedFiles(changedPaths, options = {}) {
|
|
1542
|
+
const dispositions = new Map;
|
|
1543
|
+
if (this.checkDestroyed() || changedPaths.length === 0) {
|
|
1544
|
+
return dispositions;
|
|
1545
|
+
}
|
|
1546
|
+
const targets = new Set;
|
|
1547
|
+
const changed = new Map;
|
|
1548
|
+
for (const changedPath of changedPaths) {
|
|
1549
|
+
const resolved = path.resolve(changedPath);
|
|
1550
|
+
for (const server of getServersForFileWithConfig(resolved)) {
|
|
1551
|
+
const root = await this.clientRegistry.resolveServerRoot(server, resolved);
|
|
1552
|
+
if (!root)
|
|
1553
|
+
continue;
|
|
1554
|
+
const index = loadReverseDependencyIndexFromSnapshot({ cwd: root });
|
|
1555
|
+
for (const importer of index ? getReverseDepsFromIndex(index, resolved) : []) {
|
|
1556
|
+
targets.add(importer);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
targets.add(resolved);
|
|
1560
|
+
changed.set(changedPath, resolved);
|
|
1561
|
+
}
|
|
1562
|
+
const openTargets = [...targets].filter((filePath) => this.hasLiveClientHoldingDocument(filePath));
|
|
1563
|
+
const written = new Set(changed.values());
|
|
1564
|
+
this.documentDrift.enqueueResync(openTargets.filter((filePath) => !written.has(filePath)));
|
|
1565
|
+
this.documentDrift.enqueueResync(openTargets.filter((filePath) => written.has(filePath)), { saved: options.saved === true });
|
|
1566
|
+
let pass;
|
|
1567
|
+
let passes = 0;
|
|
1568
|
+
const reached = new Map;
|
|
1569
|
+
const waiting = (filePath) => {
|
|
1570
|
+
const disposition = reached.get(normalizeMapKey(filePath));
|
|
1571
|
+
return disposition === undefined || disposition === "deferred";
|
|
1572
|
+
};
|
|
1573
|
+
for (let n = 0;n < Math.max(1, options.maxPasses ?? 1); n++) {
|
|
1574
|
+
pass = await this.sweepDocumentDrift({ force: true });
|
|
1575
|
+
passes += 1;
|
|
1576
|
+
for (const [key, disposition] of pass?.queued ?? [])
|
|
1577
|
+
reached.set(key, disposition);
|
|
1578
|
+
if (!pass || !openTargets.some(waiting))
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
logLatency({
|
|
1582
|
+
type: "phase",
|
|
1583
|
+
phase: "lsp_external_change_resync",
|
|
1584
|
+
filePath: changedPaths[0] ?? "",
|
|
1585
|
+
durationMs: 0,
|
|
1586
|
+
metadata: {
|
|
1587
|
+
changedCount: changedPaths.length,
|
|
1588
|
+
enqueued: openTargets.length,
|
|
1589
|
+
deferred: pass?.deferred ?? this.documentDrift.pendingResyncCount,
|
|
1590
|
+
passes
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
for (const [changedPath, resolved] of changed) {
|
|
1594
|
+
dispositions.set(changedPath, openTargets.includes(resolved) ? reached.get(normalizeMapKey(resolved)) ?? "deferred" : "unheld");
|
|
1595
|
+
}
|
|
1596
|
+
return dispositions;
|
|
1597
|
+
}
|
|
1598
|
+
async sweepDocumentDrift(options = {}) {
|
|
1599
|
+
if (this.checkDestroyed())
|
|
1600
|
+
return;
|
|
1601
|
+
return this.documentDrift.sweep({
|
|
1602
|
+
resync: async (filePath, content, _driftAgeMs, readStamp, saved) => {
|
|
1603
|
+
if (exceedsLspSyncLimits(content).tooLarge)
|
|
1604
|
+
return false;
|
|
1605
|
+
await this.touchFile(filePath, content, {
|
|
1606
|
+
diagnostics: "none",
|
|
1607
|
+
source: "drift_resync",
|
|
1608
|
+
clientScope: "all",
|
|
1609
|
+
excludeServerIds: await this.serverIdsNotHoldingDocument(filePath),
|
|
1610
|
+
readStamp,
|
|
1611
|
+
saved: saved === true
|
|
1612
|
+
});
|
|
1613
|
+
return this.documentDrift.peek(filePath)?.fingerprint === fingerprintDocumentContent(content);
|
|
1614
|
+
},
|
|
1615
|
+
onDrift: (event) => {
|
|
1616
|
+
if (event.disposition === "unchanged" || event.disposition === "vanished" || event.disposition === "unheld") {
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
incrementDegradationCount({
|
|
1620
|
+
kind: "lsp-document-drift",
|
|
1621
|
+
subject: event.filePath,
|
|
1622
|
+
reason: event.disposition === "deferred" ? `disk drift deferred by resync pacing after ${event.driftAgeMs}ms` : event.disposition === "failed" ? `resync FAILED after ${event.driftAgeMs}ms of untracked disk drift; view still stale (${event.syncedSize}->${event.diskSize} bytes)` : `resynced after ${event.driftAgeMs}ms of untracked disk drift (${event.syncedSize}->${event.diskSize} bytes)`
|
|
1623
|
+
});
|
|
1624
|
+
logLatency({
|
|
1625
|
+
type: "phase",
|
|
1626
|
+
phase: "lsp_document_drift",
|
|
1627
|
+
filePath: event.filePath,
|
|
1628
|
+
durationMs: event.driftAgeMs,
|
|
1629
|
+
metadata: {
|
|
1630
|
+
disposition: event.disposition,
|
|
1631
|
+
driftAgeMs: event.driftAgeMs,
|
|
1632
|
+
syncedSize: event.syncedSize,
|
|
1633
|
+
diskSize: event.diskSize
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
}, options);
|
|
1638
|
+
}
|
|
1639
|
+
_driftTrackedCountForTests() {
|
|
1640
|
+
return this.documentDrift.size;
|
|
1641
|
+
}
|
|
1642
|
+
hasLiveClientHoldingDocument(filePath) {
|
|
1643
|
+
for (const client of this.state.clients.values()) {
|
|
1644
|
+
if (!client.isAlive())
|
|
1645
|
+
continue;
|
|
1646
|
+
if (documentIsOpenOn(client, filePath))
|
|
1647
|
+
return true;
|
|
1648
|
+
}
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
async serverIdsNotHoldingDocument(filePath) {
|
|
1652
|
+
const exclude = new Set;
|
|
1653
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
1654
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
1655
|
+
const existing = root ? this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`) : undefined;
|
|
1656
|
+
if (existing?.isAlive() && documentIsOpenOn(existing, filePath))
|
|
1657
|
+
continue;
|
|
1658
|
+
exclude.add(server.id);
|
|
1659
|
+
}
|
|
1660
|
+
return exclude;
|
|
1661
|
+
}
|
|
1662
|
+
recordFullyCoveredSync(filePath, content, targeted, allWritesLanded, at, contentFingerprint) {
|
|
1663
|
+
if (!allWritesLanded || targeted.length === 0)
|
|
1664
|
+
return;
|
|
1665
|
+
const targetedClients = new Set(targeted.map((entry) => entry.client));
|
|
1666
|
+
for (const client of this.state.clients.values()) {
|
|
1667
|
+
if (targetedClients.has(client))
|
|
1668
|
+
continue;
|
|
1669
|
+
if (!client.isAlive())
|
|
1670
|
+
continue;
|
|
1671
|
+
if (documentIsOpenOn(client, filePath))
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
this.documentDrift.recordSynced(filePath, content, at, contentFingerprint?.() ?? fingerprintDocumentContent(content));
|
|
1675
|
+
}
|
|
1676
|
+
async openFile(filePath, content, options) {
|
|
1677
|
+
if (this.checkDestroyed())
|
|
1678
|
+
return;
|
|
1679
|
+
const startedAt = Date.now();
|
|
1680
|
+
await this.withClientForFileUse(filePath, undefined, options?.spawnBudgetMs, async (spawned) => {
|
|
1681
|
+
const languageId = getLanguageId(filePath) ?? "plaintext";
|
|
1682
|
+
const sent = await spawned.client.notify.open(filePath, content, languageId, options?.preserveDiagnostics);
|
|
1683
|
+
this.recordFullyCoveredSync(filePath, content, [spawned], sent !== false, startedAt);
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
async updateFile(filePath, content) {
|
|
1687
|
+
if (this.checkDestroyed())
|
|
1688
|
+
return;
|
|
1689
|
+
await this.withClientForFileUse(filePath, undefined, undefined, (spawned) => spawned.client.notify.change(filePath, content));
|
|
1690
|
+
}
|
|
1691
|
+
async touchFile(filePath, content, options = {}) {
|
|
1692
|
+
if (this.checkDestroyed()) {
|
|
1693
|
+
const destroyedDiagnosticsMode = options.collectDiagnostics ? options.diagnostics ?? "document" : options.diagnostics ?? "none";
|
|
1694
|
+
logLatency({
|
|
1695
|
+
type: "phase",
|
|
1696
|
+
phase: "lsp_touch_file",
|
|
1697
|
+
filePath: normalizeMapKey(filePath),
|
|
1698
|
+
durationMs: 0,
|
|
1699
|
+
metadata: {
|
|
1700
|
+
serverCountAttempted: 0,
|
|
1701
|
+
serverCountReady: 0,
|
|
1702
|
+
clientScope: options.clientScope ?? (destroyedDiagnosticsMode === "full" ? "all" : "primary"),
|
|
1703
|
+
diagnosticsMode: destroyedDiagnosticsMode,
|
|
1704
|
+
source: options.source ?? "unknown",
|
|
1705
|
+
failureKind: "destroyed"
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
const contentHash = this.hashContent(content);
|
|
1711
|
+
if (typeof content === "string") {
|
|
1712
|
+
this.announceToSiblings(filePath, content, contentHash).catch((cause) => {
|
|
1713
|
+
incrementDegradationCount({
|
|
1714
|
+
kind: "lsp-sibling-announcement",
|
|
1715
|
+
subject: normalizeMapKey(filePath),
|
|
1716
|
+
reason: `sibling notification failed: ${String(cause)}`
|
|
1717
|
+
});
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
const startedAt = Date.now();
|
|
1721
|
+
let fingerprintMemo;
|
|
1722
|
+
const contentFingerprint = () => fingerprintMemo ??= fingerprintDocumentContent(content);
|
|
1723
|
+
const hookDeadlineAt = options.hook !== undefined && Object.hasOwn(HOOK_WALL_BUDGET_MS, options.hook) ? startedAt + HOOK_WALL_BUDGET_MS[options.hook] : undefined;
|
|
1724
|
+
const normalizedPath = normalizeMapKey(filePath);
|
|
1725
|
+
const outsideRoot = await this.findOutsideProjectRoot(filePath);
|
|
1726
|
+
if (outsideRoot) {
|
|
1727
|
+
this.recordOutsideRootDecline(filePath, outsideRoot, "touchFile");
|
|
1728
|
+
return { diags: [], skipReason: "outside-project-root" };
|
|
1729
|
+
}
|
|
1730
|
+
this.sweepDocumentDrift().catch(() => {});
|
|
1731
|
+
const diagnosticsMode = options.collectDiagnostics ? options.diagnostics ?? "document" : options.diagnostics ?? "none";
|
|
1732
|
+
const source = options.source ?? "unknown";
|
|
1733
|
+
const clientScope = options.clientScope ?? (diagnosticsMode === "full" ? "all" : "primary");
|
|
1734
|
+
const useAllClients = clientScope === "all";
|
|
1735
|
+
const resolvedPrimaryRoots = new Map;
|
|
1736
|
+
const attemptedAuxiliaryRoots = new Map;
|
|
1737
|
+
const waitSkipReasons = new Set;
|
|
1738
|
+
const coldAuxiliaryServerIds = new Set;
|
|
1739
|
+
const noteColdAuxiliary = (serverId, outcome) => {
|
|
1740
|
+
if (outcome === "cold-spawn" || outcome === "cold-spawn-joined") {
|
|
1741
|
+
coldAuxiliaryServerIds.add(serverId);
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
let spawned;
|
|
1745
|
+
let serverCountAttempted;
|
|
1746
|
+
if (useAllClients) {
|
|
1747
|
+
const result = await this.getClientsForFile(filePath, options.excludeServerIds, resolvedPrimaryRoots, attemptedAuxiliaryRoots);
|
|
1748
|
+
spawned = result.clients;
|
|
1749
|
+
serverCountAttempted = result.serverCountAttempted;
|
|
1750
|
+
} else if (clientScope === "with-auxiliary") {
|
|
1751
|
+
const auxStartedAt = Date.now();
|
|
1752
|
+
const [entry, aux] = await Promise.all([
|
|
1753
|
+
this.getClientForFile(filePath, options.maxClientWaitMs, undefined, resolvedPrimaryRoots, waitSkipReasons),
|
|
1754
|
+
this.getAuxiliaryClientsForFile(filePath, new Set(options.auxiliaryServerIds ?? []), noteColdAuxiliary, options.maxClientWaitMs, undefined, options.hook)
|
|
1755
|
+
]);
|
|
1756
|
+
const auxDurationMs = Date.now() - auxStartedAt;
|
|
1757
|
+
if (options.auxiliaryServerIds && options.auxiliaryServerIds.length > 0) {
|
|
1758
|
+
logLatency({
|
|
1759
|
+
type: "phase",
|
|
1760
|
+
phase: "auxiliary_readiness",
|
|
1761
|
+
filePath: normalizedPath,
|
|
1762
|
+
durationMs: auxDurationMs,
|
|
1763
|
+
metadata: {
|
|
1764
|
+
serverIds: aux.map((s) => s.info.id),
|
|
1765
|
+
attemptedCount: options.auxiliaryServerIds.length,
|
|
1766
|
+
readyCount: aux.length,
|
|
1767
|
+
coldServerIds: [...coldAuxiliaryServerIds],
|
|
1768
|
+
source
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
spawned = entry ? [entry, ...aux] : aux;
|
|
1773
|
+
serverCountAttempted = spawned.length;
|
|
1774
|
+
} else {
|
|
1775
|
+
const entry = await this.getClientForFile(filePath, options.maxClientWaitMs, undefined, resolvedPrimaryRoots, waitSkipReasons);
|
|
1776
|
+
spawned = entry ? [entry] : [];
|
|
1777
|
+
serverCountAttempted = spawned.length > 0 ? 1 : getServersForFileWithConfig(filePath).length > 0 ? 1 : 0;
|
|
1778
|
+
}
|
|
1779
|
+
if (spawned.length === 0) {
|
|
1780
|
+
const failureKind = this.isSpawnInFlight(filePath, resolvedPrimaryRoots) ? "spawn_in_flight_budget_elapsed" : "no_clients_none_spawning";
|
|
1781
|
+
const unanswered = diagnosticsMode === "none" ? undefined : unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
|
|
1782
|
+
const disabledPrimaryServerIds = unanswered?.disabledServerIds ?? [];
|
|
1783
|
+
logLatency({
|
|
1784
|
+
type: "phase",
|
|
1785
|
+
phase: "lsp_touch_file",
|
|
1786
|
+
filePath: normalizedPath,
|
|
1787
|
+
durationMs: Date.now() - startedAt,
|
|
1788
|
+
metadata: {
|
|
1789
|
+
serverCountAttempted,
|
|
1790
|
+
serverCountReady: 0,
|
|
1791
|
+
clientScope,
|
|
1792
|
+
diagnosticsMode,
|
|
1793
|
+
source,
|
|
1794
|
+
maxClientWaitMs: options.maxClientWaitMs,
|
|
1795
|
+
failureKind,
|
|
1796
|
+
...waitSkipReasons.size > 0 ? { reason: [...waitSkipReasons][0] } : {},
|
|
1797
|
+
...disabledPrimaryServerIds.length > 0 && {
|
|
1798
|
+
disabledPrimaryServerIds
|
|
1799
|
+
},
|
|
1800
|
+
candidates: this.describeTouchCandidates(filePath, resolvedPrimaryRoots, attemptedAuxiliaryRoots)
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
if (unanswered !== undefined && (disabledPrimaryServerIds.length > 0 || options.nameUnansweredPrimaries === true && unanswered.serverIds.length > 0)) {
|
|
1804
|
+
return {
|
|
1805
|
+
diags: [],
|
|
1806
|
+
...resolveTouchVerdict({
|
|
1807
|
+
unavailablePrimaryServerIds: unanswered.serverIds,
|
|
1808
|
+
disabledPrimaryServerIds,
|
|
1809
|
+
primaryUnavailableCause: unanswered.cause,
|
|
1810
|
+
primaryNotifyWriteTimedOutServerIds: [],
|
|
1811
|
+
diagnosticsTimedOut: false,
|
|
1812
|
+
diagnosticsUnansweredServerIds: []
|
|
1813
|
+
})
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
const unanswered = unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
|
|
1819
|
+
const unavailablePrimaryServerIds = unanswered.serverIds;
|
|
1820
|
+
const leaseKeys = await this.clientRegistry.acquireClientLeases(spawned, filePath);
|
|
1821
|
+
if (!leaseKeys) {
|
|
1822
|
+
if (this.checkDestroyed()) {
|
|
1823
|
+
const primaryServerIds = spawned.filter((entry) => !isAuxiliary(entry.info)).map((entry) => entry.info.id);
|
|
1824
|
+
return {
|
|
1825
|
+
diags: [],
|
|
1826
|
+
inconclusive: true,
|
|
1827
|
+
...primaryServerIds.length > 0 && {
|
|
1828
|
+
inconclusiveServerIds: primaryServerIds
|
|
1829
|
+
},
|
|
1830
|
+
inconclusiveReason: "diagnostics-wait"
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
return this.touchFile(filePath, content, options);
|
|
1834
|
+
}
|
|
1835
|
+
try {
|
|
1836
|
+
if (this.shouldSkipTouch(filePath, contentHash, diagnosticsMode !== "none", spawned)) {
|
|
1837
|
+
const savedServerIds = spawned.flatMap((entry) => this.saveDebouncedPush(filePath, entry, options.saved === true, contentHash) ?? []);
|
|
1838
|
+
logLatency({
|
|
1839
|
+
type: "phase",
|
|
1840
|
+
phase: "lsp_touch_file",
|
|
1841
|
+
filePath: normalizedPath,
|
|
1842
|
+
durationMs: Date.now() - startedAt,
|
|
1843
|
+
metadata: {
|
|
1844
|
+
serverCountReady: spawned.length,
|
|
1845
|
+
clientScope,
|
|
1846
|
+
diagnosticsMode,
|
|
1847
|
+
source,
|
|
1848
|
+
failureKind: "success",
|
|
1849
|
+
skipped: true,
|
|
1850
|
+
reason: "debounced_unchanged_content",
|
|
1851
|
+
...savedServerIds.length > 0 && { savedServerIds }
|
|
1852
|
+
}
|
|
1853
|
+
});
|
|
1854
|
+
return { diags: [] };
|
|
1855
|
+
}
|
|
1856
|
+
const languageId = getLanguageId(filePath) ?? "plaintext";
|
|
1857
|
+
const silent = options.silent ?? false;
|
|
1858
|
+
const notifySkippedServerIds = new Set(spawned.filter((entry) => this.shouldSkipNotify(filePath, contentHash, entry.info.id, entry.client)).map((entry) => entry.info.id));
|
|
1859
|
+
const notifySkipped = spawned.length > 0 && notifySkippedServerIds.size === spawned.length;
|
|
1860
|
+
const savedServerIds = spawned.flatMap((entry) => notifySkippedServerIds.has(entry.info.id) ? this.saveDebouncedPush(filePath, entry, options.saved === true, contentHash) ?? [] : []);
|
|
1861
|
+
const readPathVersion = (client) => client.getDiagnosticsVersionForPath?.(filePath);
|
|
1862
|
+
const diagnosticBaselines = new Map(spawned.map((entry) => [entry.client, readPathVersion(entry.client)]));
|
|
1863
|
+
const markedAtMs = Date.now();
|
|
1864
|
+
const touchContentHash = contentHash;
|
|
1865
|
+
const bindingMatchesTouchContent = (binding) => binding?.contentHash === touchContentHash;
|
|
1866
|
+
const carriedAuxiliary = options.collectDiagnostics ? spawned.flatMap((entry) => {
|
|
1867
|
+
if (!isAuxiliary(entry.info))
|
|
1868
|
+
return [];
|
|
1869
|
+
const binding = entry.client.getDiagnosticBinding?.(filePath);
|
|
1870
|
+
if (!bindingMatchesTouchContent(binding))
|
|
1871
|
+
return [];
|
|
1872
|
+
const diags = entry.client.getDiagnostics(filePath);
|
|
1873
|
+
return diags.length > 0 ? [{ serverId: entry.info.id, diags, binding }] : [];
|
|
1874
|
+
}) : [];
|
|
1875
|
+
const auxPublishedThisContent = new Set(spawned.flatMap((entry) => isAuxiliary(entry.info) && bindingMatchesTouchContent(entry.client.getDiagnosticBinding?.(filePath)) ? [entry.info.id] : []));
|
|
1876
|
+
const spawnedByServerId = new Map(spawned.map((entry) => [entry.info.id, entry]));
|
|
1877
|
+
const auxCoversThisContent = (serverId) => {
|
|
1878
|
+
const entry = spawnedByServerId.get(serverId);
|
|
1879
|
+
if (!entry || !isAuxiliary(entry.info))
|
|
1880
|
+
return false;
|
|
1881
|
+
return auxPublishedThisContent.has(serverId) || bindingMatchesTouchContent(entry.client.getDiagnosticBinding?.(filePath));
|
|
1882
|
+
};
|
|
1883
|
+
const auxPublishedCount = (client, published) => published ? client.getDiagnostics?.(filePath)?.length ?? 0 : 0;
|
|
1884
|
+
const notifyWriteTimedOutServerIds = [];
|
|
1885
|
+
const notifyDeferredServerIds = [];
|
|
1886
|
+
const supersededServerIds = [];
|
|
1887
|
+
if (!notifySkipped) {
|
|
1888
|
+
const budget = notifyWriteBudgetMs();
|
|
1889
|
+
const queueWaitMs = options.maxClientWaitMs !== undefined ? Math.min(budget, Math.max(0, primaryServerWaitFloorMs(filePath, options.maxClientWaitMs) - (Date.now() - startedAt))) : budget;
|
|
1890
|
+
await Promise.all(spawned.map(async (entry) => {
|
|
1891
|
+
if (notifySkippedServerIds.has(entry.info.id))
|
|
1892
|
+
return;
|
|
1893
|
+
const clientKey = await this.demonstratedReadyKeyFor(entry.info, filePath);
|
|
1894
|
+
const gated = isAuxiliary(entry.info) && clientKey !== undefined;
|
|
1895
|
+
let slot;
|
|
1896
|
+
if (gated && clientKey) {
|
|
1897
|
+
const barrierStartedAt = Date.now();
|
|
1898
|
+
await this.paceAuxNotify(clientKey, entry, filePath, queueWaitMs, {
|
|
1899
|
+
source,
|
|
1900
|
+
clientScope
|
|
1901
|
+
});
|
|
1902
|
+
const slotWaitMs = Math.max(0, queueWaitMs - (Date.now() - barrierStartedAt));
|
|
1903
|
+
const claim = await this.claimAuxNotifySlot(clientKey, entry, filePath, slotWaitMs);
|
|
1904
|
+
if ("outstandingMs" in claim) {
|
|
1905
|
+
notifyDeferredServerIds.push(entry.info.id);
|
|
1906
|
+
logLatency({
|
|
1907
|
+
type: "phase",
|
|
1908
|
+
phase: "lsp_notify_resync_deferred",
|
|
1909
|
+
filePath: normalizedPath,
|
|
1910
|
+
durationMs: claim.outstandingMs,
|
|
1911
|
+
metadata: {
|
|
1912
|
+
serverId: entry.info.id,
|
|
1913
|
+
source,
|
|
1914
|
+
clientScope,
|
|
1915
|
+
reason: "outstanding_write",
|
|
1916
|
+
outstandingMs: claim.outstandingMs,
|
|
1917
|
+
queueWaitMs
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
slot = claim;
|
|
1923
|
+
}
|
|
1924
|
+
let wrote;
|
|
1925
|
+
let rejected = false;
|
|
1926
|
+
try {
|
|
1927
|
+
const writeStartedAt = Date.now();
|
|
1928
|
+
const writePromise = entry.client.notify.open(filePath, content, languageId, undefined, silent, options.saved === true, options.readStamp, contentHash).then((sent) => sent !== false);
|
|
1929
|
+
if (gated && clientKey) {
|
|
1930
|
+
this.noteAuxNotifyIssued(clientKey, entry.client);
|
|
1931
|
+
}
|
|
1932
|
+
if (slot && clientKey) {
|
|
1933
|
+
const client = entry.client;
|
|
1934
|
+
const release = slot.release;
|
|
1935
|
+
writePromise.then(() => {
|
|
1936
|
+
release();
|
|
1937
|
+
const outstandingMs = Date.now() - writeStartedAt;
|
|
1938
|
+
if (outstandingMs > budget && outstandingMs <= this.auxNotifyWedgeBudgetMs(clientKey)) {
|
|
1939
|
+
this.retractNotifyWriteBackpressure(clientKey, entry.info.id, filePath, outstandingMs, client);
|
|
1940
|
+
}
|
|
1941
|
+
}, release);
|
|
1942
|
+
}
|
|
1943
|
+
wrote = await withDeadline(writePromise, {
|
|
1944
|
+
ms: budget,
|
|
1945
|
+
onTimeout: "undefined",
|
|
1946
|
+
onReject: "propagate"
|
|
1947
|
+
});
|
|
1948
|
+
} catch {
|
|
1949
|
+
rejected = true;
|
|
1950
|
+
slot?.release();
|
|
1951
|
+
}
|
|
1952
|
+
if (wrote === true) {
|
|
1953
|
+
if (clientKey)
|
|
1954
|
+
this.notifyWriteBackpressureStreak.delete(clientKey);
|
|
1955
|
+
this.markTouched(filePath, entry.info.id, entry.client);
|
|
1956
|
+
} else if (wrote === false) {
|
|
1957
|
+
supersededServerIds.push(entry.info.id);
|
|
1958
|
+
} else {
|
|
1959
|
+
notifyWriteTimedOutServerIds.push(entry.info.id);
|
|
1960
|
+
if (!rejected) {
|
|
1961
|
+
this.recordNotifyWriteBackpressure(clientKey, entry, filePath);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
}));
|
|
1965
|
+
this.recordFullyCoveredSync(filePath, content, spawned, notifyWriteTimedOutServerIds.length === 0 && notifyDeferredServerIds.length === 0 && supersededServerIds.length === 0, startedAt, contentFingerprint);
|
|
1966
|
+
if (notifyWriteTimedOutServerIds.length > 0) {
|
|
1967
|
+
logLatency({
|
|
1968
|
+
type: "phase",
|
|
1969
|
+
phase: "lsp_notify_timeout",
|
|
1970
|
+
filePath: normalizedPath,
|
|
1971
|
+
durationMs: Date.now() - startedAt,
|
|
1972
|
+
metadata: {
|
|
1973
|
+
source,
|
|
1974
|
+
clientScope,
|
|
1975
|
+
serverCount: spawned.length,
|
|
1976
|
+
timedOutServerIds: notifyWriteTimedOutServerIds
|
|
1977
|
+
}
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
const notifyWriteTimedOut = notifyWriteTimedOutServerIds.length > 0;
|
|
1982
|
+
const primaryEntries = spawned.filter((entry) => !isAuxiliary(entry.info));
|
|
1983
|
+
const primaryServerIds = new Set(primaryEntries.map((e) => e.info.id));
|
|
1984
|
+
const primaryNotifyWriteTimedOutServerIds = notifyWriteTimedOutServerIds.filter((id) => primaryServerIds.has(id));
|
|
1985
|
+
const primaryNotifyWriteTimedOut = primaryNotifyWriteTimedOutServerIds.length > 0;
|
|
1986
|
+
const deferredResyncServerIds = new Set(notifyDeferredServerIds);
|
|
1987
|
+
let diagnosticsTimedOut = false;
|
|
1988
|
+
let diagnosticsUnansweredServerIds = [];
|
|
1989
|
+
let diagnosticsUnansweredPrimaryServerIds = [];
|
|
1990
|
+
const retractPrimaryTimeoutAttribution = () => {
|
|
1991
|
+
diagnosticsUnansweredPrimaryServerIds = [];
|
|
1992
|
+
diagnosticsUnansweredServerIds = diagnosticsUnansweredServerIds.filter((id) => !primaryServerIds.has(id));
|
|
1993
|
+
};
|
|
1994
|
+
let auxCutOffServerIds;
|
|
1995
|
+
let auxUnconfirmedServerIds;
|
|
1996
|
+
let lateDeliveryServerIds;
|
|
1997
|
+
let tsserverSyncEligible = false;
|
|
1998
|
+
const isWarmupTouch = source === "lsp_sweep_warmup";
|
|
1999
|
+
let tsserverSyncConfirmed;
|
|
2000
|
+
let diagnosticsUnsupportedServerIds = [];
|
|
2001
|
+
if (diagnosticsMode !== "none") {
|
|
2002
|
+
const envWait = readEnvDiagnosticsWaitMs();
|
|
2003
|
+
const callerCap = options.maxDiagnosticsWaitMs ?? options.maxClientWaitMs;
|
|
2004
|
+
const modeFloor = diagnosticsMode === "full" ? 3000 : 1200;
|
|
2005
|
+
const sweepFirstTouch = new Map;
|
|
2006
|
+
if (options.sweepIndexGate) {
|
|
2007
|
+
for (const entry of spawned) {
|
|
2008
|
+
const strategy = getStrategy(entry.client.serverId, entry.client.getLaunchVariant?.());
|
|
2009
|
+
if (strategy.workspaceIndexing) {
|
|
2010
|
+
sweepFirstTouch.set(entry.client.serverId, options.sweepIndexGate.consumeFirstTouch(entry.client.serverId));
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
const silentCleanWarmupServers = new Set;
|
|
2015
|
+
if (options.warmupOverride && (options.warmupAttempt ?? 1) <= 1) {
|
|
2016
|
+
for (const entry of spawned) {
|
|
2017
|
+
const strategy = getStrategy(entry.client.serverId, entry.client.getLaunchVariant?.());
|
|
2018
|
+
if (strategy.workspaceIndexing !== true)
|
|
2019
|
+
continue;
|
|
2020
|
+
try {
|
|
2021
|
+
const snapshot = {
|
|
2022
|
+
serverId: entry.client.serverId,
|
|
2023
|
+
root: entry.client.root,
|
|
2024
|
+
operationSupport: entry.client.getOperationSupport(),
|
|
2025
|
+
workspaceDiagnosticsSupport: entry.client.getWorkspaceDiagnosticsSupport(),
|
|
2026
|
+
customServer: entry.info.custom,
|
|
2027
|
+
diagnosticsPublished: this.state.diagnosticsPublished.has(entry.info.id),
|
|
2028
|
+
diagnosticsUnsupported: this.state.diagnosticsUnsupported.has(entry.info.id),
|
|
2029
|
+
advertisedCommands: entry.client.getAdvertisedCommands(),
|
|
2030
|
+
rawCapabilityKeys: entry.client.getRawCapabilityKeys?.() ?? [],
|
|
2031
|
+
launchVariant: entry.client.getLaunchVariant?.()
|
|
2032
|
+
};
|
|
2033
|
+
if (classifyServerWaitTier(entry.client.serverId, snapshot) === "tier3-silent") {
|
|
2034
|
+
silentCleanWarmupServers.add(entry.client.serverId);
|
|
2035
|
+
}
|
|
2036
|
+
} catch {}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
const perServerTimeout = (serverId) => {
|
|
2040
|
+
const launchVariant = spawned.find((entry) => entry.client.serverId === serverId)?.client.getLaunchVariant?.();
|
|
2041
|
+
const strategy = getStrategy(serverId, launchVariant);
|
|
2042
|
+
let strategyWait = strategy.aggregateWaitMs;
|
|
2043
|
+
const isFirstTouch = sweepFirstTouch.get(serverId);
|
|
2044
|
+
if (isFirstTouch === false && strategy.workspaceIndexing) {
|
|
2045
|
+
strategyWait = strategy.workspaceIndexingWarmWaitMs ?? Math.min(300, strategyWait);
|
|
2046
|
+
}
|
|
2047
|
+
if (callerCap !== undefined) {
|
|
2048
|
+
if (options.warmupOverride) {
|
|
2049
|
+
if (silentCleanWarmupServers.has(serverId)) {
|
|
2050
|
+
return Math.min(callerCap, strategyWait > 0 ? strategyWait : callerCap);
|
|
2051
|
+
}
|
|
2052
|
+
if ((options.warmupAttempt ?? 1) > 1) {
|
|
2053
|
+
return Math.min(callerCap, strategyWait > 0 ? strategyWait : callerCap);
|
|
2054
|
+
}
|
|
2055
|
+
return Math.max(callerCap, strategyWait > 0 ? strategyWait : 0);
|
|
2056
|
+
}
|
|
2057
|
+
return Math.min(callerCap, strategyWait > 0 ? strategyWait : callerCap);
|
|
2058
|
+
}
|
|
2059
|
+
return strategyWait > 0 ? strategyWait : modeFloor;
|
|
2060
|
+
};
|
|
2061
|
+
let timeoutFor;
|
|
2062
|
+
if (envWait !== undefined) {
|
|
2063
|
+
timeoutFor = () => envWait;
|
|
2064
|
+
} else if (!useAllClients && spawned.length === 1 || clientScope === "with-auxiliary" || clientScope === "all") {
|
|
2065
|
+
timeoutFor = perServerTimeout;
|
|
2066
|
+
} else {
|
|
2067
|
+
timeoutFor = () => callerCap ?? modeFloor;
|
|
2068
|
+
}
|
|
2069
|
+
const timeoutMs = Math.max(0, ...spawned.filter((e) => !deferredResyncServerIds.has(e.info.id)).map((e) => timeoutFor(e.client.serverId)));
|
|
2070
|
+
if (!notifyWriteTimedOut && (options.collectDiagnostics === true || isWarmupTouch) && clientScope === "primary" && spawned.length === 1 && spawned[0].client.serverId === "typescript" && getStrategy(spawned[0].client.serverId, spawned[0].client.getLaunchVariant?.()).silentOnClean === true) {
|
|
2071
|
+
try {
|
|
2072
|
+
const snapshots = await this.getCapabilitySnapshots(filePath);
|
|
2073
|
+
tsserverSyncEligible = classifyCascadeWaitTier(this, filePath, snapshots) === "tier3-silent";
|
|
2074
|
+
} catch {}
|
|
2075
|
+
}
|
|
2076
|
+
const waitStartedAt = Date.now();
|
|
2077
|
+
const hasTouchAuxiliaries = clientScope === "with-auxiliary" && options.collectDiagnostics === true && spawned.some((e) => isAuxiliary(e.info));
|
|
2078
|
+
if (spawned.some((entry) => entry.info.custom === true)) {
|
|
2079
|
+
try {
|
|
2080
|
+
const snapshotHook = options.hook ?? "tool_result_edit";
|
|
2081
|
+
const snapshotBudget = hookDeadlineAt === undefined ? HOOK_WALL_BUDGET_MS.tool_result_edit : Math.max(0, hookDeadlineAt - Date.now());
|
|
2082
|
+
const snapshots = await bounded(this.getCapabilitySnapshots(filePath), {
|
|
2083
|
+
ms: snapshotBudget,
|
|
2084
|
+
signal: getAmbientAbortSignal(),
|
|
2085
|
+
shutdownSignal: this.shutdownController.signal,
|
|
2086
|
+
hook: snapshotHook,
|
|
2087
|
+
label: `getCapabilitySnapshots:${filePath}`
|
|
2088
|
+
});
|
|
2089
|
+
if (snapshots !== undefined) {
|
|
2090
|
+
diagnosticsUnsupportedServerIds = spawned.filter((entry) => classifyServerWaitTier(entry.info.id, snapshots.find((s) => s.serverId === entry.info.id)) === "diagnostics-unsupported").map((entry) => entry.info.id);
|
|
2091
|
+
}
|
|
2092
|
+
} catch {}
|
|
2093
|
+
}
|
|
2094
|
+
let pressureSnapshots = [];
|
|
2095
|
+
if (shouldPreferPullOnlyDiagnostics()) {
|
|
2096
|
+
try {
|
|
2097
|
+
pressureSnapshots = await this.getCapabilitySnapshots(filePath);
|
|
2098
|
+
} catch {}
|
|
2099
|
+
}
|
|
2100
|
+
const configuredAuxCeilingMs = readEnvAuxGraceMs();
|
|
2101
|
+
const perServerDeclaredTimeouts = spawned.map((entry) => timeoutFor(entry.client.serverId));
|
|
2102
|
+
const perServerWaitTimeouts = spawned.map((entry, entryIndex) => {
|
|
2103
|
+
const declaredServerTimeout = perServerDeclaredTimeouts[entryIndex];
|
|
2104
|
+
const observedSpawnMs = getSuccessfulLspSpawnDurationMs(entry.client.serverId);
|
|
2105
|
+
return hasTouchAuxiliaries && isAuxiliary(entry.info) && coldAuxiliaryServerIds.has(entry.client.serverId) && (configuredAuxCeilingMs !== undefined || observedSpawnMs !== undefined && observedSpawnMs > 0) ? auxWaitBudgetMs(entry.client.serverId, true, configuredAuxCeilingMs, declaredServerTimeout) : perServerDeclaredTimeouts[entryIndex];
|
|
2106
|
+
});
|
|
2107
|
+
const firstContactCutOffServerIds = new Set;
|
|
2108
|
+
const firstContactErroredServerIds = new Set;
|
|
2109
|
+
const answeredForThisTouch = (entry) => {
|
|
2110
|
+
const baseline = diagnosticBaselines.get(entry.client);
|
|
2111
|
+
const currentPathVersion = readPathVersion(entry.client);
|
|
2112
|
+
if (auxiliaryPublicationEvidence({
|
|
2113
|
+
bindingMatchesContent: false,
|
|
2114
|
+
baseline,
|
|
2115
|
+
currentPathVersion
|
|
2116
|
+
})) {
|
|
2117
|
+
return true;
|
|
2118
|
+
}
|
|
2119
|
+
try {
|
|
2120
|
+
return entry.client.getAllDiagnostics?.().has(normalizedPath) === true;
|
|
2121
|
+
} catch {
|
|
2122
|
+
return false;
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2125
|
+
const perServerRaceBudgets = spawned.map((entry, entryIndex) => {
|
|
2126
|
+
return hasTouchAuxiliaries && isAuxiliary(entry.info) ? auxWaitBudgetMs(entry.client.serverId, coldAuxiliaryServerIds.has(entry.client.serverId), configuredAuxCeilingMs, perServerDeclaredTimeouts[entryIndex]) : perServerDeclaredTimeouts[entryIndex];
|
|
2127
|
+
});
|
|
2128
|
+
const perServerWaits = spawned.map((entry, entryIndex) => {
|
|
2129
|
+
if (hasTouchAuxiliaries && isAuxiliary(entry.info) && this.isAuxiliaryWaitDemoted(entry.info.id, entry.client.root ?? filePath)) {
|
|
2130
|
+
return Promise.resolve(undefined);
|
|
2131
|
+
}
|
|
2132
|
+
if (this.state.diagnosticsUnsupported.has(entry.info.id) || diagnosticsUnsupportedServerIds.includes(entry.info.id)) {
|
|
2133
|
+
return Promise.resolve(undefined);
|
|
2134
|
+
}
|
|
2135
|
+
if (deferredResyncServerIds.has(entry.info.id)) {
|
|
2136
|
+
return Promise.resolve(undefined);
|
|
2137
|
+
}
|
|
2138
|
+
const serverTimeout = perServerWaitTimeouts[entryIndex];
|
|
2139
|
+
const baseline = diagnosticBaselines.get(entry.client);
|
|
2140
|
+
const pullOnly = classifyServerWaitTier(entry.client.serverId, pressureSnapshots.find((snapshot) => snapshot.serverId === entry.client.serverId)) === "pull-capable";
|
|
2141
|
+
const waitForDiagnostics = () => !notifySkippedServerIds.has(entry.info.id) && Number.isFinite(baseline) ? entry.client.waitForDiagnostics(filePath, serverTimeout, {
|
|
2142
|
+
minVersion: baseline,
|
|
2143
|
+
...pullOnly && { pullOnly: true },
|
|
2144
|
+
...isWarmupTouch && { pullSettleSource: "pull-warmup" }
|
|
2145
|
+
}) : pullOnly ? entry.client.waitForDiagnostics(filePath, serverTimeout, {
|
|
2146
|
+
pullOnly: true,
|
|
2147
|
+
...isWarmupTouch && { pullSettleSource: "pull-warmup" }
|
|
2148
|
+
}) : isWarmupTouch ? entry.client.waitForDiagnostics(filePath, serverTimeout, {
|
|
2149
|
+
pullSettleSource: "pull-warmup"
|
|
2150
|
+
}) : entry.client.waitForDiagnostics(filePath, serverTimeout);
|
|
2151
|
+
const firstContact = entry.info.custom === true && !this.state.diagnosticsPublished.has(entry.info.id) && !this.state.diagnosticsUnsupported.has(entry.info.id) && entry.client.getWorkspaceDiagnosticsSupport().mode !== "pull";
|
|
2152
|
+
if (!firstContact)
|
|
2153
|
+
return waitForDiagnostics().catch(() => {
|
|
2154
|
+
return;
|
|
2155
|
+
});
|
|
2156
|
+
let shared = this.firstContactWaits.get(entry.info.id);
|
|
2157
|
+
if (!shared) {
|
|
2158
|
+
let removeShutdownListener;
|
|
2159
|
+
const shutdown = new Promise((resolve) => {
|
|
2160
|
+
const onShutdown = () => resolve("shutdown");
|
|
2161
|
+
if (this.shutdownController.signal.aborted) {
|
|
2162
|
+
onShutdown();
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
this.shutdownController.signal.addEventListener("abort", onShutdown, {
|
|
2166
|
+
once: true
|
|
2167
|
+
});
|
|
2168
|
+
removeShutdownListener = () => this.shutdownController.signal.removeEventListener("abort", onShutdown);
|
|
2169
|
+
});
|
|
2170
|
+
const probe = Promise.race([
|
|
2171
|
+
waitForDiagnostics().then(() => "completed", () => "errored"),
|
|
2172
|
+
shutdown
|
|
2173
|
+
]);
|
|
2174
|
+
const completed = withDeadline(probe, {
|
|
2175
|
+
ms: serverTimeout,
|
|
2176
|
+
onTimeout: "undefined"
|
|
2177
|
+
});
|
|
2178
|
+
shared = completed.then((outcome) => {
|
|
2179
|
+
if (outcome === "errored" || outcome === "shutdown") {
|
|
2180
|
+
return "errored";
|
|
2181
|
+
}
|
|
2182
|
+
if (answeredForThisTouch(entry))
|
|
2183
|
+
return "answered";
|
|
2184
|
+
this.state.diagnosticsUnsupported.add(entry.info.id);
|
|
2185
|
+
recordDegradationOnce({
|
|
2186
|
+
kind: "lsp-diagnostics-unsupported",
|
|
2187
|
+
subject: entry.info.id,
|
|
2188
|
+
reason: "custom server has no pull provider and no publish evidence after first contact wait"
|
|
2189
|
+
});
|
|
2190
|
+
return "silent";
|
|
2191
|
+
}).catch(() => "errored").finally(() => {
|
|
2192
|
+
removeShutdownListener?.();
|
|
2193
|
+
if (this.firstContactWaits.get(entry.info.id) === shared) {
|
|
2194
|
+
this.firstContactWaits.delete(entry.info.id);
|
|
2195
|
+
}
|
|
2196
|
+
});
|
|
2197
|
+
this.firstContactWaits.set(entry.info.id, shared);
|
|
2198
|
+
}
|
|
2199
|
+
const callerWait = hookDeadlineAt === undefined ? shared : withDeadline(shared, {
|
|
2200
|
+
ms: Math.max(0, hookDeadlineAt - Date.now()),
|
|
2201
|
+
onTimeout: "undefined"
|
|
2202
|
+
});
|
|
2203
|
+
return callerWait.then((outcome) => {
|
|
2204
|
+
if (outcome === undefined) {
|
|
2205
|
+
firstContactCutOffServerIds.add(entry.info.id);
|
|
2206
|
+
} else if (outcome === "errored") {
|
|
2207
|
+
firstContactErroredServerIds.add(entry.info.id);
|
|
2208
|
+
}
|
|
2209
|
+
return;
|
|
2210
|
+
});
|
|
2211
|
+
});
|
|
2212
|
+
let pushWaitSettled = false;
|
|
2213
|
+
const pushWait = hasTouchAuxiliaries ? (() => {
|
|
2214
|
+
const primaryWaits = perServerWaits.filter((_, i) => !isAuxiliary(spawned[i].info));
|
|
2215
|
+
const auxWaits = perServerWaits.map((p, i) => isAuxiliary(spawned[i].info) ? {
|
|
2216
|
+
promise: p,
|
|
2217
|
+
serverId: spawned[i].info.id,
|
|
2218
|
+
client: spawned[i].client,
|
|
2219
|
+
baseline: diagnosticBaselines.get(spawned[i].client),
|
|
2220
|
+
budgetMs: perServerRaceBudgets[i],
|
|
2221
|
+
demoted: this.isAuxiliaryWaitDemoted(spawned[i].info.id, spawned[i].client.root ?? filePath),
|
|
2222
|
+
root: spawned[i].client.root ?? filePath
|
|
2223
|
+
} : null).filter((x) => x !== null);
|
|
2224
|
+
return Promise.all(primaryWaits).then(async () => {
|
|
2225
|
+
if (auxWaits.length === 0)
|
|
2226
|
+
return;
|
|
2227
|
+
const auxWaitStartedAt = Date.now();
|
|
2228
|
+
const outcomes = await Promise.all(auxWaits.map(async (aux) => {
|
|
2229
|
+
const { budgetMs } = aux;
|
|
2230
|
+
if (aux.demoted) {
|
|
2231
|
+
const demotedPublished = auxiliaryPublicationEvidence({
|
|
2232
|
+
bindingMatchesContent: auxCoversThisContent(aux.serverId),
|
|
2233
|
+
baseline: aux.baseline,
|
|
2234
|
+
currentPathVersion: readPathVersion(aux.client)
|
|
2235
|
+
});
|
|
2236
|
+
return {
|
|
2237
|
+
serverId: aux.serverId,
|
|
2238
|
+
outcome: deferredResyncServerIds.has(aux.serverId) ? "deferred" : "demoted",
|
|
2239
|
+
publishedThisContent: demotedPublished,
|
|
2240
|
+
publishedCount: auxPublishedCount(aux.client, demotedPublished),
|
|
2241
|
+
budgetMs,
|
|
2242
|
+
elapsedMs: 0,
|
|
2243
|
+
elapsedSinceNotifyMs: 0
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2246
|
+
let timer;
|
|
2247
|
+
const timeout = new Promise((resolve) => {
|
|
2248
|
+
timer = setTimeout(() => resolve(false), budgetMs);
|
|
2249
|
+
if (typeof timer === "object" && "unref" in timer) {
|
|
2250
|
+
timer.unref?.();
|
|
2251
|
+
}
|
|
2252
|
+
});
|
|
2253
|
+
const raced = await Promise.race([
|
|
2254
|
+
aux.promise.then(() => true),
|
|
2255
|
+
timeout
|
|
2256
|
+
]);
|
|
2257
|
+
if (timer)
|
|
2258
|
+
clearTimeout(timer);
|
|
2259
|
+
const currentPathVersion = readPathVersion(aux.client);
|
|
2260
|
+
const publishedEvidence = auxiliaryPublicationEvidence({
|
|
2261
|
+
bindingMatchesContent: false,
|
|
2262
|
+
baseline: aux.baseline,
|
|
2263
|
+
currentPathVersion,
|
|
2264
|
+
raced
|
|
2265
|
+
});
|
|
2266
|
+
const outcome = deferredResyncServerIds.has(aux.serverId) ? "deferred" : !raced ? "cut_off" : publishedEvidence ? "answered" : "silent";
|
|
2267
|
+
const elapsedMs = Date.now() - auxWaitStartedAt;
|
|
2268
|
+
if (outcome !== "deferred") {
|
|
2269
|
+
this.noteAuxiliaryWait(`${aux.serverId}:${normalizeMapKey(aux.root)}`, budgetMs, elapsedMs);
|
|
2270
|
+
}
|
|
2271
|
+
return {
|
|
2272
|
+
serverId: aux.serverId,
|
|
2273
|
+
outcome,
|
|
2274
|
+
publishedThisContent: auxCoversThisContent(aux.serverId),
|
|
2275
|
+
publishedCount: auxPublishedCount(aux.client, publishedEvidence || auxCoversThisContent(aux.serverId)),
|
|
2276
|
+
budgetMs,
|
|
2277
|
+
elapsedMs,
|
|
2278
|
+
elapsedSinceNotifyMs: Date.now() - waitStartedAt
|
|
2279
|
+
};
|
|
2280
|
+
}));
|
|
2281
|
+
const unfinished = outcomes.filter((outcome) => outcome.outcome === "cut_off").map((outcome) => outcome.serverId);
|
|
2282
|
+
if (unfinished.length > 0)
|
|
2283
|
+
auxCutOffServerIds = unfinished;
|
|
2284
|
+
const uncovered = auxiliaryCoverageGap(outcomes);
|
|
2285
|
+
if (uncovered.length > 0)
|
|
2286
|
+
auxUnconfirmedServerIds = uncovered;
|
|
2287
|
+
const collectLaterServerIds = outcomes.filter((o) => !o.publishedThisContent && (o.outcome === "cut_off" || o.outcome === "silent" || o.outcome === "demoted") && !(o.serverId === "ast-grep" && napiFallbackCoveredSince(filePath, startedAt))).map((o) => o.serverId);
|
|
2288
|
+
if (collectLaterServerIds.length > 0) {
|
|
2289
|
+
lateDeliveryServerIds = collectLaterServerIds;
|
|
2290
|
+
for (const serverId of collectLaterServerIds) {
|
|
2291
|
+
markPendingAuxiliaryCoverage(filePath, [serverId], startedAt, undefined, undefined, captureAuxPublicationBacklog(auxWaits.find((aux) => aux.serverId === serverId)?.client, filePath));
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
logLatency({
|
|
2295
|
+
type: "phase",
|
|
2296
|
+
phase: "lsp_aux_wait_outcome",
|
|
2297
|
+
filePath: normalizedPath,
|
|
2298
|
+
durationMs: Date.now() - auxWaitStartedAt,
|
|
2299
|
+
metadata: { clientScope, waitShape: "aux_grace", outcomes }
|
|
2300
|
+
});
|
|
2301
|
+
});
|
|
2302
|
+
})() : Promise.all(perServerWaits).then(() => {});
|
|
2303
|
+
const markPushWaitSettled = () => {
|
|
2304
|
+
pushWaitSettled = true;
|
|
2305
|
+
};
|
|
2306
|
+
pushWait.then(markPushWaitSettled, markPushWaitSettled);
|
|
2307
|
+
if (tsserverSyncEligible) {
|
|
2308
|
+
const graceMs = readTsserverSyncGraceMs();
|
|
2309
|
+
const primaryClient = spawned[0].client;
|
|
2310
|
+
const syncRacer = (async () => {
|
|
2311
|
+
await new Promise((resolve) => {
|
|
2312
|
+
const timer = setTimeout(resolve, graceMs);
|
|
2313
|
+
timer.unref?.();
|
|
2314
|
+
});
|
|
2315
|
+
const publishedAt = primaryClient.getAllDiagnostics?.().get(normalizedPath)?.ts;
|
|
2316
|
+
if (pushWaitSettled || publishedAt !== undefined && publishedAt > markedAtMs) {
|
|
2317
|
+
return new Promise(() => {});
|
|
2318
|
+
}
|
|
2319
|
+
try {
|
|
2320
|
+
const result = await attemptTsserverSyncDiagnostics(filePath, tsserverSyncChannel(primaryClient));
|
|
2321
|
+
if (result === undefined || pushWaitSettled) {
|
|
2322
|
+
return new Promise(() => {});
|
|
2323
|
+
}
|
|
2324
|
+
return result;
|
|
2325
|
+
} catch {
|
|
2326
|
+
return new Promise(() => {});
|
|
2327
|
+
}
|
|
2328
|
+
})();
|
|
2329
|
+
const raceOutcome = await Promise.race([
|
|
2330
|
+
pushWait.then(() => {
|
|
2331
|
+
return;
|
|
2332
|
+
}),
|
|
2333
|
+
syncRacer
|
|
2334
|
+
]);
|
|
2335
|
+
if (raceOutcome !== undefined) {
|
|
2336
|
+
tsserverSyncConfirmed = raceOutcome;
|
|
2337
|
+
}
|
|
2338
|
+
} else {
|
|
2339
|
+
await pushWait;
|
|
2340
|
+
}
|
|
2341
|
+
const waitedMs = Date.now() - waitStartedAt;
|
|
2342
|
+
const firstContactCustomServerIds = spawned.filter((entry) => entry.info.custom === true && !this.state.diagnosticsPublished.has(entry.info.id) && !this.state.diagnosticsUnsupported.has(entry.info.id) && !firstContactCutOffServerIds.has(entry.info.id) && !firstContactErroredServerIds.has(entry.info.id) && entry.client.getWorkspaceDiagnosticsSupport().mode !== "pull").map((entry) => entry.info.id);
|
|
2343
|
+
for (const serverId of firstContactCustomServerIds) {
|
|
2344
|
+
const entry = spawned.find((candidate) => candidate.info.id === serverId);
|
|
2345
|
+
if (!entry || answeredForThisTouch(entry))
|
|
2346
|
+
continue;
|
|
2347
|
+
this.state.diagnosticsUnsupported.add(serverId);
|
|
2348
|
+
diagnosticsUnsupportedServerIds.push(serverId);
|
|
2349
|
+
recordDegradationOnce({
|
|
2350
|
+
kind: "lsp-diagnostics-unsupported",
|
|
2351
|
+
subject: serverId,
|
|
2352
|
+
reason: "custom server has no pull provider and no publish evidence after first contact wait"
|
|
2353
|
+
});
|
|
2354
|
+
}
|
|
2355
|
+
for (const entry of spawned) {
|
|
2356
|
+
if (entry.info.custom === true && this.state.diagnosticsUnsupported.has(entry.info.id)) {
|
|
2357
|
+
diagnosticsUnsupportedServerIds.push(entry.info.id);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
diagnosticsUnsupportedServerIds = [
|
|
2361
|
+
...new Set(diagnosticsUnsupportedServerIds)
|
|
2362
|
+
];
|
|
2363
|
+
if (!hasTouchAuxiliaries && options.collectDiagnostics === true) {
|
|
2364
|
+
const auxEntries = spawned.filter((entry) => isAuxiliary(entry.info));
|
|
2365
|
+
if (auxEntries.length > 0) {
|
|
2366
|
+
const outcomes = auxEntries.map((entry) => {
|
|
2367
|
+
const baseline = diagnosticBaselines.get(entry.client);
|
|
2368
|
+
const currentPathVersion = readPathVersion(entry.client);
|
|
2369
|
+
const publishedEvidence = auxiliaryPublicationEvidence({
|
|
2370
|
+
bindingMatchesContent: false,
|
|
2371
|
+
baseline,
|
|
2372
|
+
currentPathVersion
|
|
2373
|
+
});
|
|
2374
|
+
return {
|
|
2375
|
+
serverId: entry.info.id,
|
|
2376
|
+
outcome: deferredResyncServerIds.has(entry.info.id) ? "deferred" : publishedEvidence ? "answered" : "silent",
|
|
2377
|
+
publishedThisContent: auxCoversThisContent(entry.info.id),
|
|
2378
|
+
publishedCount: auxPublishedCount(entry.client, publishedEvidence || auxCoversThisContent(entry.info.id)),
|
|
2379
|
+
budgetMs: timeoutFor(entry.client.serverId),
|
|
2380
|
+
elapsedMs: waitedMs,
|
|
2381
|
+
elapsedSinceNotifyMs: waitedMs
|
|
2382
|
+
};
|
|
2383
|
+
});
|
|
2384
|
+
const uncovered = auxiliaryCoverageGap(outcomes);
|
|
2385
|
+
if (uncovered.length > 0)
|
|
2386
|
+
auxUnconfirmedServerIds = uncovered;
|
|
2387
|
+
logLatency({
|
|
2388
|
+
type: "phase",
|
|
2389
|
+
phase: "lsp_aux_wait_outcome",
|
|
2390
|
+
filePath: normalizedPath,
|
|
2391
|
+
durationMs: waitedMs,
|
|
2392
|
+
metadata: { clientScope, waitShape: "aggregate", outcomes }
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
if (tsserverSyncConfirmed !== undefined) {
|
|
2397
|
+
logLatency({
|
|
2398
|
+
type: "phase",
|
|
2399
|
+
phase: "lsp_tsserver_sync_confirm",
|
|
2400
|
+
filePath: normalizedPath,
|
|
2401
|
+
durationMs: waitedMs,
|
|
2402
|
+
metadata: {
|
|
2403
|
+
source,
|
|
2404
|
+
serverId: spawned[0]?.client.serverId,
|
|
2405
|
+
clientScope,
|
|
2406
|
+
diagnosticsMode,
|
|
2407
|
+
mode: "race",
|
|
2408
|
+
confirmedDiagnosticCount: tsserverSyncConfirmed.length,
|
|
2409
|
+
budgetMs: timeoutMs,
|
|
2410
|
+
savedVsBudgetMs: Math.max(0, timeoutMs - waitedMs)
|
|
2411
|
+
}
|
|
2412
|
+
});
|
|
2413
|
+
} else if (waitedMs + 20 >= timeoutMs || firstContactErroredServerIds.size > 0) {
|
|
2414
|
+
const waited = spawned.filter((entry) => !deferredResyncServerIds.has(entry.info.id) && !diagnosticsUnsupportedServerIds.includes(entry.info.id));
|
|
2415
|
+
const unanswered = waited.filter((entry) => !answeredForThisTouch(entry));
|
|
2416
|
+
diagnosticsUnansweredServerIds = unanswered.map((e) => e.info.id);
|
|
2417
|
+
diagnosticsUnansweredPrimaryServerIds = unanswered.filter((entry) => !isAuxiliary(entry.info)).map((e) => e.info.id);
|
|
2418
|
+
const hasWaitedPrimary = waited.some((entry) => !isAuxiliary(entry.info));
|
|
2419
|
+
const hasUnsupportedPrimary = diagnosticsUnsupportedServerIds.some((serverId) => spawned.some((entry) => entry.info.id === serverId && !isAuxiliary(entry.info)));
|
|
2420
|
+
diagnosticsTimedOut = !hasWaitedPrimary && !hasUnsupportedPrimary || diagnosticsUnansweredPrimaryServerIds.length > 0;
|
|
2421
|
+
for (const entry of unanswered) {
|
|
2422
|
+
incrementDegradationCount({
|
|
2423
|
+
kind: "lsp-diagnostics-timeout",
|
|
2424
|
+
subject: entry.info.id,
|
|
2425
|
+
reason: "diagnostics wait timed out"
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
logLatency({
|
|
2429
|
+
type: "phase",
|
|
2430
|
+
phase: "lsp_diagnostics_timeout",
|
|
2431
|
+
filePath: normalizedPath,
|
|
2432
|
+
durationMs: waitedMs,
|
|
2433
|
+
metadata: {
|
|
2434
|
+
source,
|
|
2435
|
+
serverIds: spawned.map((e) => e.info.id),
|
|
2436
|
+
clientScope,
|
|
2437
|
+
diagnosticsMode,
|
|
2438
|
+
timeoutMs,
|
|
2439
|
+
unansweredServerIds: diagnosticsUnansweredServerIds,
|
|
2440
|
+
attributedToPrimary: diagnosticsTimedOut
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
if (diagnosticsTimedOut && !primaryNotifyWriteTimedOut && clientScope === "all") {
|
|
2445
|
+
try {
|
|
2446
|
+
const outstanding = primaryEntries.filter((entry) => !notifyWriteTimedOutServerIds.includes(entry.info.id) && !entry.client.getAllDiagnostics().has(normalizedPath));
|
|
2447
|
+
if (outstanding.length > 0) {
|
|
2448
|
+
const snapshots = await this.getCapabilitySnapshots(filePath);
|
|
2449
|
+
const allSilent = outstanding.every((entry) => classifyServerWaitTier(entry.client.serverId, snapshots.find((s) => s.serverId === entry.client.serverId)) === "tier3-silent");
|
|
2450
|
+
if (allSilent) {
|
|
2451
|
+
const liveness = await Promise.all(outstanding.map((entry) => (entry.client.pingLiveness?.() ?? Promise.resolve(true)).catch(() => false)));
|
|
2452
|
+
if (liveness.every(Boolean)) {
|
|
2453
|
+
diagnosticsTimedOut = false;
|
|
2454
|
+
retractPrimaryTimeoutAttribution();
|
|
2455
|
+
logLatency({
|
|
2456
|
+
type: "phase",
|
|
2457
|
+
phase: "lsp_silent_clean_confirm",
|
|
2458
|
+
filePath: normalizedPath,
|
|
2459
|
+
durationMs: Date.now() - startedAt,
|
|
2460
|
+
metadata: {
|
|
2461
|
+
source,
|
|
2462
|
+
clientScope,
|
|
2463
|
+
diagnosticsMode,
|
|
2464
|
+
aggregate: true,
|
|
2465
|
+
serverIds: outstanding.map((entry) => entry.client.serverId)
|
|
2466
|
+
}
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
} catch {}
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
const auxCoveredAtMerge = new Set(spawned.filter((entry) => auxCoversThisContent(entry.info.id)).map((entry) => entry.info.id));
|
|
2475
|
+
const uncoveredDeferredServerIds = notifyDeferredServerIds.filter((serverId) => !auxCoveredAtMerge.has(serverId));
|
|
2476
|
+
const staleWriteAuxiliaryServerIds = spawned.filter((entry) => isAuxiliary(entry.info) && notifyWriteTimedOutServerIds.includes(entry.info.id) && !auxCoveredAtMerge.has(entry.info.id)).map((entry) => entry.info.id);
|
|
2477
|
+
const droppedAuxiliaryServerIds = new Set([
|
|
2478
|
+
...uncoveredDeferredServerIds,
|
|
2479
|
+
...staleWriteAuxiliaryServerIds
|
|
2480
|
+
]);
|
|
2481
|
+
let collected = options.collectDiagnostics ? tsserverSyncConfirmed !== undefined ? mergeLspDiagnostics(attributeDiagnostics(spawned[0]?.info.id ?? "unknown", tsserverSyncConfirmed)) : mergeLspDiagnostics([
|
|
2482
|
+
...spawned.flatMap((entry) => droppedAuxiliaryServerIds.has(entry.info.id) ? [] : attributeDiagnostics(entry.info.id, entry.client.getDiagnostics(filePath))),
|
|
2483
|
+
...carriedAuxiliary.flatMap((entry) => attributeDiagnostics(entry.serverId, entry.diags))
|
|
2484
|
+
]) : undefined;
|
|
2485
|
+
let syncConfirmed = tsserverSyncConfirmed !== undefined;
|
|
2486
|
+
const syncClient = spawned[0]?.client;
|
|
2487
|
+
if (diagnosticsTimedOut && tsserverSyncEligible && syncClient !== undefined && collected !== undefined && collected.length === 0) {
|
|
2488
|
+
try {
|
|
2489
|
+
const syncResult = await attemptTsserverSyncDiagnostics(filePath, tsserverSyncChannel(syncClient));
|
|
2490
|
+
if (syncResult !== undefined) {
|
|
2491
|
+
diagnosticsTimedOut = false;
|
|
2492
|
+
retractPrimaryTimeoutAttribution();
|
|
2493
|
+
syncConfirmed = true;
|
|
2494
|
+
collected = syncResult.length > 0 ? mergeLspDiagnostics(attributeDiagnostics(spawned[0]?.info.id ?? "unknown", syncResult)) : [];
|
|
2495
|
+
logLatency({
|
|
2496
|
+
type: "phase",
|
|
2497
|
+
phase: "lsp_tsserver_sync_confirm",
|
|
2498
|
+
filePath: normalizedPath,
|
|
2499
|
+
durationMs: Date.now() - startedAt,
|
|
2500
|
+
metadata: {
|
|
2501
|
+
source,
|
|
2502
|
+
clientScope,
|
|
2503
|
+
diagnosticsMode,
|
|
2504
|
+
mode: "end-of-wait",
|
|
2505
|
+
confirmedDiagnosticCount: collected.length
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
} catch {}
|
|
2510
|
+
}
|
|
2511
|
+
if (diagnosticsTimedOut && !primaryNotifyWriteTimedOut && (!tsserverSyncEligible || isWarmupTouch) && clientScope === "primary" && spawned.length === 1 && getStrategy(spawned[0].client.serverId, spawned[0].client.getLaunchVariant?.()).silentOnClean === true) {
|
|
2512
|
+
try {
|
|
2513
|
+
const snapshots = await this.getCapabilitySnapshots(filePath);
|
|
2514
|
+
if (classifyCascadeWaitTier(this, filePath, snapshots) === "tier3-silent") {
|
|
2515
|
+
const alive = await (spawned[0].client.pingLiveness?.() ?? Promise.resolve(true)).catch(() => false);
|
|
2516
|
+
if (alive) {
|
|
2517
|
+
diagnosticsTimedOut = false;
|
|
2518
|
+
retractPrimaryTimeoutAttribution();
|
|
2519
|
+
if (collected !== undefined)
|
|
2520
|
+
collected = mergeLspDiagnostics([]);
|
|
2521
|
+
logLatency({
|
|
2522
|
+
type: "phase",
|
|
2523
|
+
phase: "lsp_silent_clean_confirm",
|
|
2524
|
+
filePath: normalizedPath,
|
|
2525
|
+
durationMs: Date.now() - startedAt,
|
|
2526
|
+
metadata: {
|
|
2527
|
+
source,
|
|
2528
|
+
clientScope,
|
|
2529
|
+
diagnosticsMode,
|
|
2530
|
+
serverId: spawned[0].client.serverId
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
} catch {}
|
|
2536
|
+
}
|
|
2537
|
+
const verdict = resolveTouchVerdict({
|
|
2538
|
+
unavailablePrimaryServerIds,
|
|
2539
|
+
disabledPrimaryServerIds: unanswered.disabledServerIds,
|
|
2540
|
+
primaryUnavailableCause: unanswered.cause,
|
|
2541
|
+
primaryNotifyWriteTimedOutServerIds,
|
|
2542
|
+
diagnosticsTimedOut,
|
|
2543
|
+
diagnosticsUnansweredServerIds: diagnosticsUnansweredPrimaryServerIds
|
|
2544
|
+
});
|
|
2545
|
+
const inconclusive = verdict.inconclusive;
|
|
2546
|
+
const skippedAuxiliaries = collected !== undefined ? await this.skippedAuxiliaryServerIds(filePath, clientScope, options, spawned) : { brokenSkippedServerIds: [], policySkippedServerIds: [] };
|
|
2547
|
+
const brokenSkippedServerIds = skippedAuxiliaries.brokenSkippedServerIds;
|
|
2548
|
+
const policySkippedServerIds = skippedAuxiliaries.policySkippedServerIds;
|
|
2549
|
+
const auxNoAnswerServerIds = spawned.filter((entry) => isAuxiliary(entry.info) && (diagnosticsUnansweredServerIds.includes(entry.info.id) || notifyWriteTimedOutServerIds.includes(entry.info.id)) && !auxCoveredAtMerge.has(entry.info.id)).map((entry) => entry.info.id);
|
|
2550
|
+
const unconfirmedServerIds = [
|
|
2551
|
+
...new Set([
|
|
2552
|
+
...auxUnconfirmedServerIds ?? [],
|
|
2553
|
+
...auxNoAnswerServerIds,
|
|
2554
|
+
...uncoveredDeferredServerIds,
|
|
2555
|
+
...brokenSkippedServerIds,
|
|
2556
|
+
...policySkippedServerIds
|
|
2557
|
+
])
|
|
2558
|
+
].filter((serverId) => !auxCoveredAtMerge.has(serverId));
|
|
2559
|
+
const coverageGap = unconfirmedServerIds.length > 0;
|
|
2560
|
+
if (brokenSkippedServerIds.length > 0 || policySkippedServerIds.length > 0 || uncoveredDeferredServerIds.length > 0 || auxNoAnswerServerIds.length > 0) {
|
|
2561
|
+
const configFailureSuffix = (serverId) => {
|
|
2562
|
+
const failure = spawned.find((entry) => entry.info.id === serverId)?.client.getConfigLoadFailure?.();
|
|
2563
|
+
return failure ? ` (server reported: ${failure})` : "";
|
|
2564
|
+
};
|
|
2565
|
+
for (const serverId of unconfirmedServerIds) {
|
|
2566
|
+
const reasons = [
|
|
2567
|
+
brokenSkippedServerIds.includes(serverId) && "breaker skip",
|
|
2568
|
+
policySkippedServerIds.includes(serverId) && "root policy skip",
|
|
2569
|
+
uncoveredDeferredServerIds.includes(serverId) && "deferred resync",
|
|
2570
|
+
auxNoAnswerServerIds.includes(serverId) && `no diagnostics answer${configFailureSuffix(serverId)}`
|
|
2571
|
+
].filter(Boolean);
|
|
2572
|
+
incrementDegradationCount({
|
|
2573
|
+
kind: "lsp-scanner-coverage-gap",
|
|
2574
|
+
subject: `${serverId}:${normalizedPath}`,
|
|
2575
|
+
reason: reasons.join(", ") || "scanner coverage gap"
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
emitBounded("lsp_scanner_coverage_gap", `${source}:${normalizedPath}`, {
|
|
2579
|
+
filePath: normalizedPath,
|
|
2580
|
+
durationMs: Date.now() - startedAt,
|
|
2581
|
+
metadata: {
|
|
2582
|
+
source,
|
|
2583
|
+
clientScope,
|
|
2584
|
+
...brokenSkippedServerIds.length > 0 && {
|
|
2585
|
+
brokenSkippedServerIds
|
|
2586
|
+
},
|
|
2587
|
+
...policySkippedServerIds.length > 0 && {
|
|
2588
|
+
policySkippedServerIds
|
|
2589
|
+
},
|
|
2590
|
+
...uncoveredDeferredServerIds.length > 0 && {
|
|
2591
|
+
deferredResyncServerIds: uncoveredDeferredServerIds
|
|
2592
|
+
},
|
|
2593
|
+
...auxNoAnswerServerIds.length > 0 && { auxNoAnswerServerIds }
|
|
2594
|
+
}
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
const notifyTimedOutServerIds = new Set(notifyWriteTimedOutServerIds);
|
|
2598
|
+
const uncoveredServerIds = new Set(unconfirmedServerIds);
|
|
2599
|
+
if (diagnosticsMode !== "none" && !diagnosticsTimedOut) {
|
|
2600
|
+
for (const entry of spawned) {
|
|
2601
|
+
if (notifyTimedOutServerIds.has(entry.info.id))
|
|
2602
|
+
continue;
|
|
2603
|
+
if (uncoveredServerIds.has(entry.info.id))
|
|
2604
|
+
continue;
|
|
2605
|
+
const key = await this.demonstratedReadyKeyFor(entry.info, filePath);
|
|
2606
|
+
if (key && this.state.clients.get(key) === entry.client)
|
|
2607
|
+
this.markDemonstratedReadyKey(key);
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
if (collected !== undefined && !inconclusive && !coverageGap) {
|
|
2611
|
+
const normalizedKey = normalizeMapKey(filePath);
|
|
2612
|
+
if (collected.length > 0) {
|
|
2613
|
+
this.lastKnownDiagnostics.set(normalizedKey, collected);
|
|
2614
|
+
this.lastKnownContentHash.set(normalizedKey, this.hashContent(content));
|
|
2615
|
+
} else {
|
|
2616
|
+
this.lastKnownDiagnostics.delete(normalizedKey);
|
|
2617
|
+
this.lastKnownContentHash.delete(normalizedKey);
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
const result = { diags: collected ?? [] };
|
|
2621
|
+
const primaryDiagnosticsUnsupported = diagnosticsUnsupportedServerIds.some((serverId) => spawned.some((entry) => entry.info.id === serverId && !isAuxiliary(entry.info)));
|
|
2622
|
+
if (diagnosticsUnsupportedServerIds.length > 0) {
|
|
2623
|
+
result.diagnosticsUnsupportedServerIds = diagnosticsUnsupportedServerIds;
|
|
2624
|
+
}
|
|
2625
|
+
if (collected !== undefined && inconclusive) {
|
|
2626
|
+
result.inconclusive = true;
|
|
2627
|
+
if (verdict.inconclusiveServerIds) {
|
|
2628
|
+
result.inconclusiveServerIds = verdict.inconclusiveServerIds;
|
|
2629
|
+
}
|
|
2630
|
+
result.inconclusiveReason = verdict.inconclusiveReason;
|
|
2631
|
+
if (verdict.disabledPrimaryServerIds) {
|
|
2632
|
+
result.disabledPrimaryServerIds = verdict.disabledPrimaryServerIds;
|
|
2633
|
+
}
|
|
2634
|
+
if (verdict.primaryUnavailableCause) {
|
|
2635
|
+
result.primaryUnavailableCause = verdict.primaryUnavailableCause;
|
|
2636
|
+
}
|
|
2637
|
+
} else if (collected !== undefined && primaryDiagnosticsUnsupported) {
|
|
2638
|
+
if (unconfirmedServerIds.length > 0) {
|
|
2639
|
+
result.unconfirmedServerIds = [...unconfirmedServerIds];
|
|
2640
|
+
}
|
|
2641
|
+
} else if (collected !== undefined && coverageGap) {
|
|
2642
|
+
result.confirmation = "partial";
|
|
2643
|
+
result.unconfirmedServerIds = [...unconfirmedServerIds];
|
|
2644
|
+
} else if (collected !== undefined && !primaryDiagnosticsUnsupported) {
|
|
2645
|
+
result.confirmation = "confirmed";
|
|
2646
|
+
}
|
|
2647
|
+
let binding;
|
|
2648
|
+
if (collected !== undefined) {
|
|
2649
|
+
binding = syncConfirmed ? { boundToCurrentDisk: "unknown" } : this.mergeBinding(filePath, [
|
|
2650
|
+
...spawned.filter((entry) => !droppedAuxiliaryServerIds.has(entry.info.id)).map((entry) => entry.client.getDiagnosticBinding?.(filePath)),
|
|
2651
|
+
...carriedAuxiliary.map((entry) => entry.binding)
|
|
2652
|
+
]);
|
|
2653
|
+
result.binding = binding;
|
|
2654
|
+
}
|
|
2655
|
+
const lateDeliveryPending = unconfirmedServerIds.filter((serverId) => (lateDeliveryServerIds ?? []).includes(serverId));
|
|
2656
|
+
if (lateDeliveryPending.length > 0) {
|
|
2657
|
+
result.deferredServerIds = lateDeliveryPending;
|
|
2658
|
+
}
|
|
2659
|
+
if (supersededServerIds.length > 0) {
|
|
2660
|
+
result.supersededServerIds = supersededServerIds;
|
|
2661
|
+
}
|
|
2662
|
+
logLatency({
|
|
2663
|
+
type: "phase",
|
|
2664
|
+
phase: "lsp_touch_file",
|
|
2665
|
+
filePath: normalizedPath,
|
|
2666
|
+
durationMs: Date.now() - startedAt,
|
|
2667
|
+
metadata: {
|
|
2668
|
+
serverCountReady: spawned.length,
|
|
2669
|
+
clientScope,
|
|
2670
|
+
diagnosticsMode,
|
|
2671
|
+
source,
|
|
2672
|
+
failureKind: "success",
|
|
2673
|
+
collectedDiagnostics: collected?.length,
|
|
2674
|
+
...binding !== undefined && {
|
|
2675
|
+
bindingState: bindingStateLabel(binding.boundToCurrentDisk)
|
|
2676
|
+
},
|
|
2677
|
+
notifySkipped,
|
|
2678
|
+
notifyWriteTimedOut,
|
|
2679
|
+
...notifyWriteTimedOutServerIds.length > 0 && {
|
|
2680
|
+
notifyWriteTimedOutServerIds
|
|
2681
|
+
},
|
|
2682
|
+
...supersededServerIds.length > 0 && { supersededServerIds },
|
|
2683
|
+
...savedServerIds.length > 0 && { savedServerIds },
|
|
2684
|
+
diagnosticsTimedOut,
|
|
2685
|
+
inconclusive,
|
|
2686
|
+
...verdict.inconclusiveServerIds && {
|
|
2687
|
+
inconclusiveServerIds: verdict.inconclusiveServerIds
|
|
2688
|
+
},
|
|
2689
|
+
...verdict.inconclusiveReason && {
|
|
2690
|
+
inconclusiveReason: verdict.inconclusiveReason
|
|
2691
|
+
},
|
|
2692
|
+
...result.confirmation !== undefined && {
|
|
2693
|
+
confirmation: result.confirmation
|
|
2694
|
+
},
|
|
2695
|
+
...auxCutOffServerIds !== undefined && { auxCutOffServerIds },
|
|
2696
|
+
...auxUnconfirmedServerIds !== undefined && {
|
|
2697
|
+
auxUnconfirmedServerIds
|
|
2698
|
+
},
|
|
2699
|
+
...brokenSkippedServerIds.length > 0 && { brokenSkippedServerIds },
|
|
2700
|
+
...policySkippedServerIds.length > 0 && { policySkippedServerIds },
|
|
2701
|
+
...uncoveredDeferredServerIds.length > 0 && {
|
|
2702
|
+
deferredResyncServerIds: uncoveredDeferredServerIds
|
|
2703
|
+
},
|
|
2704
|
+
...lateDeliveryPending.length > 0 && {
|
|
2705
|
+
lateDeliveryServerIds: lateDeliveryPending
|
|
2706
|
+
},
|
|
2707
|
+
...auxNoAnswerServerIds.length > 0 && { auxNoAnswerServerIds }
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
return result;
|
|
2711
|
+
} finally {
|
|
2712
|
+
for (const lease of leaseKeys)
|
|
2713
|
+
this.clientRegistry.releaseClientLease(lease.key, lease.server);
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
async findOutsideProjectRoot(filePath) {
|
|
2717
|
+
if (!this.clientRegistry.fileIsOutsideRegisteredRoots(filePath))
|
|
2718
|
+
return;
|
|
2719
|
+
if (this.clientRegistry.analysisRootModeForFile(filePath) === "adopted")
|
|
2720
|
+
return;
|
|
2721
|
+
const candidates = await Promise.all(getServersForFileWithConfig(filePath).map((server) => server.root(filePath)));
|
|
2722
|
+
return candidates.find((candidate) => Boolean(candidate));
|
|
2723
|
+
}
|
|
2724
|
+
recordOutsideRootDecline(filePath, nearestRoot, operation) {
|
|
2725
|
+
const root = normalizeMapKey(nearestRoot);
|
|
2726
|
+
const sessionRoots = getSessionRootsForTelemetry().map((sessionRoot) => normalizeMapKey(sessionRoot)).join(", ");
|
|
2727
|
+
emitBounded("lsp_capability_skip", root, {
|
|
2728
|
+
filePath: normalizeMapKey(filePath),
|
|
2729
|
+
durationMs: 0,
|
|
2730
|
+
metadata: {
|
|
2731
|
+
operation,
|
|
2732
|
+
nearestMarkerRoot: root,
|
|
2733
|
+
sessionRoots,
|
|
2734
|
+
identity: root
|
|
2735
|
+
}
|
|
2736
|
+
}, {
|
|
2737
|
+
ledgerKind: "lsp-capability-skip",
|
|
2738
|
+
risingEdgePer: "identity",
|
|
2739
|
+
reason: `declined LSP root outside session cwd: ${root}`
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
getDiagnosticsHealth(filePath) {
|
|
2743
|
+
return this.lastDiagnosticsHealth.get(normalizeMapKey(filePath));
|
|
2744
|
+
}
|
|
2745
|
+
getLastKnownDiagnostics(filePath, expectedContentHash) {
|
|
2746
|
+
const normalizedKey = normalizeMapKey(filePath);
|
|
2747
|
+
if (expectedContentHash !== undefined) {
|
|
2748
|
+
const knownHash = this.lastKnownContentHash.get(normalizedKey);
|
|
2749
|
+
if (knownHash === undefined || knownHash !== expectedContentHash) {
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
return this.lastKnownDiagnostics.get(normalizedKey);
|
|
2754
|
+
}
|
|
2755
|
+
async getDiagnostics(filePath, diagnosticsMode = "full", excludeServerIds) {
|
|
2756
|
+
const normalizedPath = normalizeMapKey(filePath);
|
|
2757
|
+
const outsideRoot = await this.findOutsideProjectRoot(filePath);
|
|
2758
|
+
if (outsideRoot) {
|
|
2759
|
+
this.recordOutsideRootDecline(filePath, outsideRoot, "getDiagnostics");
|
|
2760
|
+
return [];
|
|
2761
|
+
}
|
|
2762
|
+
if (this.checkDestroyed()) {
|
|
2763
|
+
this.lastDiagnosticsHealth.set(normalizedPath, {
|
|
2764
|
+
health: "destroyed",
|
|
2765
|
+
failureKind: "destroyed",
|
|
2766
|
+
serverCountAttempted: 0,
|
|
2767
|
+
serverCountReady: 0,
|
|
2768
|
+
candidateServerIds: getServersForFileWithConfig(filePath).map((s) => s.id),
|
|
2769
|
+
mergedCount: 0,
|
|
2770
|
+
dedupDroppedCount: 0,
|
|
2771
|
+
checkedAt: new Date().toISOString()
|
|
2772
|
+
});
|
|
2773
|
+
return [];
|
|
2774
|
+
}
|
|
2775
|
+
const startedAt = Date.now();
|
|
2776
|
+
const candidateServerIds = getServersForFileWithConfig(filePath).flatMap((s) => excludeServerIds?.has(s.id) ? [] : [s.id]);
|
|
2777
|
+
const resolvedPrimaryRoots = new Map;
|
|
2778
|
+
const { clients: spawned, serverCountAttempted } = await this.getClientsForFile(filePath, excludeServerIds, resolvedPrimaryRoots);
|
|
2779
|
+
if (spawned.length === 0) {
|
|
2780
|
+
const stored = this.lastKnownDiagnostics.get(normalizedPath);
|
|
2781
|
+
const stale = excludeServerIds !== undefined && excludeServerIds.size > 0 ? stored?.filter((diagnostic) => !excludeServerIds.has(diagnostic.serverId ?? "")) : stored;
|
|
2782
|
+
const failureKind = stale?.length ? "no_clients_stale" : "no_clients";
|
|
2783
|
+
const unanswered = unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
|
|
2784
|
+
const unavailablePrimaryServerIds = unanswered.serverIds;
|
|
2785
|
+
this.lastDiagnosticsHealth.set(normalizedPath, {
|
|
2786
|
+
health: failureKind,
|
|
2787
|
+
failureKind,
|
|
2788
|
+
serverCountAttempted,
|
|
2789
|
+
serverCountReady: 0,
|
|
2790
|
+
candidateServerIds,
|
|
2791
|
+
mergedCount: stale?.length ?? 0,
|
|
2792
|
+
dedupDroppedCount: 0,
|
|
2793
|
+
checkedAt: new Date().toISOString(),
|
|
2794
|
+
unavailablePrimaryServerIds,
|
|
2795
|
+
...unanswered.disabledServerIds.length > 0 && {
|
|
2796
|
+
disabledPrimaryServerIds: unanswered.disabledServerIds
|
|
2797
|
+
},
|
|
2798
|
+
...unavailablePrimaryServerIds.length > 0 && {
|
|
2799
|
+
primaryUnavailableCause: unanswered.cause
|
|
2800
|
+
}
|
|
2801
|
+
});
|
|
2802
|
+
logLatency({
|
|
2803
|
+
type: "phase",
|
|
2804
|
+
phase: "lsp_diagnostics_aggregate",
|
|
2805
|
+
filePath: normalizedPath,
|
|
2806
|
+
durationMs: Date.now() - startedAt,
|
|
2807
|
+
metadata: {
|
|
2808
|
+
serverCountAttempted,
|
|
2809
|
+
serverCountReady: 0,
|
|
2810
|
+
mergedCount: stale?.length ?? 0,
|
|
2811
|
+
dedupDroppedCount: 0,
|
|
2812
|
+
failureKind,
|
|
2813
|
+
health: failureKind,
|
|
2814
|
+
servers: [],
|
|
2815
|
+
...unavailablePrimaryServerIds.length > 0 && {
|
|
2816
|
+
unavailablePrimaryServerIds
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
});
|
|
2820
|
+
return stale ?? [];
|
|
2821
|
+
}
|
|
2822
|
+
const clientWaits = spawned.map(async (entry) => {
|
|
2823
|
+
const waitStart = Date.now();
|
|
2824
|
+
const launchVariant = entry.client.getLaunchVariant?.();
|
|
2825
|
+
const strategy = getStrategy(entry.info.id, launchVariant);
|
|
2826
|
+
await entry.client.waitForDiagnostics(filePath, strategy.aggregateWaitMs);
|
|
2827
|
+
let diagnostics = entry.client.getDiagnostics(filePath);
|
|
2828
|
+
const firstWaitMs = Date.now() - waitStart;
|
|
2829
|
+
if (strategy.expectSemanticSecondPush && diagnostics.length === 0 && firstWaitMs < DIAGNOSTICS_SEMANTIC_SETTLE_THRESHOLD_MS) {
|
|
2830
|
+
await entry.client.waitForDiagnostics(filePath, DIAGNOSTICS_SEMANTIC_SETTLE_WAIT_MS);
|
|
2831
|
+
diagnostics = entry.client.getDiagnostics(filePath);
|
|
2832
|
+
}
|
|
2833
|
+
return {
|
|
2834
|
+
serverId: entry.info.id,
|
|
2835
|
+
launchVariant,
|
|
2836
|
+
waitMs: Date.now() - waitStart,
|
|
2837
|
+
diagnosticCount: diagnostics.length,
|
|
2838
|
+
diagnostics
|
|
2839
|
+
};
|
|
2840
|
+
});
|
|
2841
|
+
const graceMs = diagnosticsMode === "document" ? 0 : EARLY_UNBLOCK_GRACE_MS;
|
|
2842
|
+
const diagDescriptors = spawned.map((entry) => {
|
|
2843
|
+
if (!isAuxiliary(entry.info))
|
|
2844
|
+
return { role: entry.info.role };
|
|
2845
|
+
const strategy = getStrategy(entry.info.id, entry.client.getLaunchVariant?.());
|
|
2846
|
+
return { role: entry.info.role, budgetMs: strategy.aggregateWaitMs };
|
|
2847
|
+
});
|
|
2848
|
+
const perServer = await raceToCompletion(clientWaits, (results) => results.some((r) => r.diagnosticCount > 0 || getStrategy(r.serverId, r.launchVariant).seedFirstPush), {
|
|
2849
|
+
timeoutMs: Math.max(...spawned.map((entry) => getStrategy(entry.info.id, entry.client.getLaunchVariant?.()).aggregateWaitMs)),
|
|
2850
|
+
graceMs,
|
|
2851
|
+
descriptors: diagDescriptors,
|
|
2852
|
+
auxGraceMs: readEnvAuxGraceMs() ?? DEFAULT_AUX_GRACE_CEILING_MS
|
|
2853
|
+
});
|
|
2854
|
+
const earlyUnblockedCount = spawned.length - perServer.length;
|
|
2855
|
+
const perServerFull = spawned.map((entry) => {
|
|
2856
|
+
const found = perServer.find((r) => r.serverId === entry.info.id);
|
|
2857
|
+
return found ?? {
|
|
2858
|
+
serverId: entry.info.id,
|
|
2859
|
+
launchVariant: entry.client.getLaunchVariant?.(),
|
|
2860
|
+
waitMs: getStrategy(entry.info.id, entry.client.getLaunchVariant?.()).aggregateWaitMs,
|
|
2861
|
+
diagnosticCount: 0,
|
|
2862
|
+
diagnostics: []
|
|
2863
|
+
};
|
|
2864
|
+
});
|
|
2865
|
+
const merged = [];
|
|
2866
|
+
const seen = new Set;
|
|
2867
|
+
for (const entry of perServerFull) {
|
|
2868
|
+
for (const diagnostic of entry.diagnostics) {
|
|
2869
|
+
const key = [
|
|
2870
|
+
diagnostic.range.start.line,
|
|
2871
|
+
diagnostic.range.start.character,
|
|
2872
|
+
diagnostic.message
|
|
2873
|
+
].join(":");
|
|
2874
|
+
if (seen.has(key))
|
|
2875
|
+
continue;
|
|
2876
|
+
seen.add(key);
|
|
2877
|
+
merged.push({ ...diagnostic, serverId: entry.serverId });
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
const rawCount = perServerFull.reduce((sum, entry) => sum + entry.diagnosticCount, 0);
|
|
2881
|
+
const serversWithDiagnostics = perServerFull.filter((entry) => entry.diagnosticCount > 0).length;
|
|
2882
|
+
const failureKind = merged.length === 0 ? "ok_empty" : "success";
|
|
2883
|
+
const unanswered = unansweredPrimaries(spawned, resolvedPrimaryRoots, filePath);
|
|
2884
|
+
const unavailablePrimaryServerIds = unanswered.serverIds;
|
|
2885
|
+
this.lastDiagnosticsHealth.set(normalizedPath, {
|
|
2886
|
+
health: failureKind === "success" ? "ok" : "ok_empty",
|
|
2887
|
+
failureKind,
|
|
2888
|
+
serverCountAttempted,
|
|
2889
|
+
serverCountReady: perServerFull.length,
|
|
2890
|
+
candidateServerIds,
|
|
2891
|
+
mergedCount: merged.length,
|
|
2892
|
+
dedupDroppedCount: rawCount - merged.length,
|
|
2893
|
+
checkedAt: new Date().toISOString(),
|
|
2894
|
+
unavailablePrimaryServerIds,
|
|
2895
|
+
...unanswered.disabledServerIds.length > 0 && {
|
|
2896
|
+
disabledPrimaryServerIds: unanswered.disabledServerIds
|
|
2897
|
+
},
|
|
2898
|
+
...unavailablePrimaryServerIds.length > 0 && {
|
|
2899
|
+
primaryUnavailableCause: unanswered.cause
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
logLatency({
|
|
2903
|
+
type: "phase",
|
|
2904
|
+
phase: "lsp_diagnostics_aggregate",
|
|
2905
|
+
filePath: normalizedPath,
|
|
2906
|
+
durationMs: Date.now() - startedAt,
|
|
2907
|
+
metadata: {
|
|
2908
|
+
serverCountAttempted,
|
|
2909
|
+
serverCountReady: perServerFull.length,
|
|
2910
|
+
serverCountWithDiagnostics: serversWithDiagnostics,
|
|
2911
|
+
mergedCount: merged.length,
|
|
2912
|
+
dedupDroppedCount: rawCount - merged.length,
|
|
2913
|
+
earlyUnblockedCount,
|
|
2914
|
+
diagnosticsMode,
|
|
2915
|
+
failureKind,
|
|
2916
|
+
health: failureKind === "success" ? "ok" : "ok_empty",
|
|
2917
|
+
servers: perServerFull.map((entry) => ({
|
|
2918
|
+
id: entry.serverId,
|
|
2919
|
+
waitMs: entry.waitMs,
|
|
2920
|
+
diagnosticCount: entry.diagnosticCount
|
|
2921
|
+
})),
|
|
2922
|
+
...unavailablePrimaryServerIds.length > 0 && {
|
|
2923
|
+
unavailablePrimaryServerIds
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
if (merged.length > 0) {
|
|
2928
|
+
this.lastKnownDiagnostics.set(normalizedPath, merged);
|
|
2929
|
+
} else {
|
|
2930
|
+
this.lastKnownDiagnostics.delete(normalizedPath);
|
|
2931
|
+
}
|
|
2932
|
+
this.lastKnownContentHash.delete(normalizedPath);
|
|
2933
|
+
return merged;
|
|
2934
|
+
}
|
|
2935
|
+
hashContent(content) {
|
|
2936
|
+
return hashDiagnosticContent(content);
|
|
2937
|
+
}
|
|
2938
|
+
mergeBinding(filePath, stored) {
|
|
2939
|
+
const verdicts = [];
|
|
2940
|
+
let version;
|
|
2941
|
+
let contentHash;
|
|
2942
|
+
for (const entry of stored) {
|
|
2943
|
+
verdicts.push(this.diskBindingCache.boundToCurrentDisk(filePath, entry ?? {}));
|
|
2944
|
+
if (version === undefined && entry?.version !== undefined) {
|
|
2945
|
+
version = entry.version;
|
|
2946
|
+
}
|
|
2947
|
+
if (contentHash === undefined && entry?.contentHash !== undefined) {
|
|
2948
|
+
contentHash = entry.contentHash;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
return {
|
|
2952
|
+
version,
|
|
2953
|
+
contentHash,
|
|
2954
|
+
boundToCurrentDisk: composeBoundToCurrentDisk(verdicts)
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2957
|
+
async definition(filePath, line, character) {
|
|
2958
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
2959
|
+
if (!spawned)
|
|
2960
|
+
return [];
|
|
2961
|
+
if (!spawned.client.getOperationSupport().definition) {
|
|
2962
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for definition");
|
|
2963
|
+
}
|
|
2964
|
+
return spawned.client.definition(filePath, line, character);
|
|
2965
|
+
}
|
|
2966
|
+
async typeDefinition(filePath, line, character) {
|
|
2967
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
2968
|
+
if (!spawned)
|
|
2969
|
+
return [];
|
|
2970
|
+
if (!spawned.client.getOperationSupport().typeDefinition) {
|
|
2971
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for typeDefinition");
|
|
2972
|
+
}
|
|
2973
|
+
return spawned.client.typeDefinition(filePath, line, character);
|
|
2974
|
+
}
|
|
2975
|
+
async declaration(filePath, line, character) {
|
|
2976
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
2977
|
+
if (!spawned)
|
|
2978
|
+
return [];
|
|
2979
|
+
if (!spawned.client.getOperationSupport().declaration) {
|
|
2980
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for declaration");
|
|
2981
|
+
}
|
|
2982
|
+
return spawned.client.declaration(filePath, line, character);
|
|
2983
|
+
}
|
|
2984
|
+
async references(filePath, line, character, includeDeclaration = true) {
|
|
2985
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
2986
|
+
if (!spawned)
|
|
2987
|
+
return [];
|
|
2988
|
+
if (!spawned.client.getOperationSupport().references) {
|
|
2989
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for references");
|
|
2990
|
+
}
|
|
2991
|
+
return spawned.client.references(filePath, line, character, includeDeclaration);
|
|
2992
|
+
}
|
|
2993
|
+
async hover(filePath, line, character) {
|
|
2994
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
2995
|
+
if (!spawned)
|
|
2996
|
+
return null;
|
|
2997
|
+
if (!spawned.client.getOperationSupport().hover) {
|
|
2998
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for hover");
|
|
2999
|
+
}
|
|
3000
|
+
return spawned.client.hover(filePath, line, character);
|
|
3001
|
+
}
|
|
3002
|
+
async signatureHelp(filePath, line, character) {
|
|
3003
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3004
|
+
if (!spawned)
|
|
3005
|
+
return null;
|
|
3006
|
+
if (!spawned.client.getOperationSupport().signatureHelp) {
|
|
3007
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for signatureHelp");
|
|
3008
|
+
}
|
|
3009
|
+
return spawned.client.signatureHelp(filePath, line, character);
|
|
3010
|
+
}
|
|
3011
|
+
async documentSymbol(filePath) {
|
|
3012
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3013
|
+
if (!spawned)
|
|
3014
|
+
return [];
|
|
3015
|
+
if (!spawned.client.getOperationSupport().documentSymbol) {
|
|
3016
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for documentSymbol");
|
|
3017
|
+
}
|
|
3018
|
+
return spawned.client.documentSymbol(filePath);
|
|
3019
|
+
}
|
|
3020
|
+
selectWorkspaceScopeClient(predicate) {
|
|
3021
|
+
let auxFallback;
|
|
3022
|
+
for (const [key, client] of this.state.clients) {
|
|
3023
|
+
if (!client.isAlive())
|
|
3024
|
+
continue;
|
|
3025
|
+
if (predicate && !predicate(client))
|
|
3026
|
+
continue;
|
|
3027
|
+
const separator = key.indexOf(":");
|
|
3028
|
+
const serverId = separator >= 0 ? key.slice(0, separator) : key;
|
|
3029
|
+
if (isAuxiliary(getServerById(serverId))) {
|
|
3030
|
+
if (!auxFallback)
|
|
3031
|
+
auxFallback = { client, serverId };
|
|
3032
|
+
continue;
|
|
3033
|
+
}
|
|
3034
|
+
return { client, serverId };
|
|
3035
|
+
}
|
|
3036
|
+
return auxFallback;
|
|
3037
|
+
}
|
|
3038
|
+
async workspaceSymbol(query, filePath, attribution) {
|
|
3039
|
+
if (filePath) {
|
|
3040
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3041
|
+
if (!spawned)
|
|
3042
|
+
return [];
|
|
3043
|
+
if (!spawned.client.getOperationSupport().workspaceSymbol)
|
|
3044
|
+
return [];
|
|
3045
|
+
return spawned.client.workspaceSymbol(query);
|
|
3046
|
+
}
|
|
3047
|
+
const target = this.selectWorkspaceScopeClient((client) => client.getOperationSupport().workspaceSymbol);
|
|
3048
|
+
if (!target)
|
|
3049
|
+
return [];
|
|
3050
|
+
if (attribution)
|
|
3051
|
+
attribution.workspaceSymbol = target.serverId;
|
|
3052
|
+
return target.client.workspaceSymbol(query);
|
|
3053
|
+
}
|
|
3054
|
+
async getAdvertisedCommands(filePath, attribution) {
|
|
3055
|
+
if (filePath) {
|
|
3056
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3057
|
+
if (!spawned)
|
|
3058
|
+
return [];
|
|
3059
|
+
return spawned.client.getAdvertisedCommands();
|
|
3060
|
+
}
|
|
3061
|
+
const first = this.selectWorkspaceScopeClient();
|
|
3062
|
+
if (!first)
|
|
3063
|
+
return [];
|
|
3064
|
+
if (attribution)
|
|
3065
|
+
attribution.getAdvertisedCommands = first.serverId;
|
|
3066
|
+
return first.client.getAdvertisedCommands();
|
|
3067
|
+
}
|
|
3068
|
+
async executeCommand(filePath, command, args, mutationContext, attribution) {
|
|
3069
|
+
if (filePath) {
|
|
3070
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3071
|
+
if (!spawned) {
|
|
3072
|
+
return { executed: false, reason: "no LSP server for file" };
|
|
3073
|
+
}
|
|
3074
|
+
return spawned.client.executeCommand(command, args, mutationContext);
|
|
3075
|
+
}
|
|
3076
|
+
const first = this.selectWorkspaceScopeClient();
|
|
3077
|
+
if (!first)
|
|
3078
|
+
return { executed: false, reason: "no active LSP server" };
|
|
3079
|
+
if (attribution)
|
|
3080
|
+
attribution.executeCommand = first.serverId;
|
|
3081
|
+
return first.client.executeCommand(command, args, mutationContext);
|
|
3082
|
+
}
|
|
3083
|
+
async executeReadOnlyCommandOnLiveClient(filePath, command, args) {
|
|
3084
|
+
if (this.checkDestroyed()) {
|
|
3085
|
+
return { executed: false, reason: "lsp service destroyed" };
|
|
3086
|
+
}
|
|
3087
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
3088
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
3089
|
+
if (!root)
|
|
3090
|
+
continue;
|
|
3091
|
+
const entry = this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`);
|
|
3092
|
+
if (!entry?.isAlive())
|
|
3093
|
+
continue;
|
|
3094
|
+
const run = entry.executeReadOnlyCommand;
|
|
3095
|
+
if (typeof run !== "function")
|
|
3096
|
+
continue;
|
|
3097
|
+
return run.call(entry, command, args);
|
|
3098
|
+
}
|
|
3099
|
+
return { executed: false, reason: "no live LSP server for file" };
|
|
3100
|
+
}
|
|
3101
|
+
async getOperationSupport(filePath, attribution) {
|
|
3102
|
+
if (filePath) {
|
|
3103
|
+
const spawned = await this.getClientForFile(filePath);
|
|
3104
|
+
if (!spawned)
|
|
3105
|
+
return null;
|
|
3106
|
+
const getter = spawned.client.getOperationSupport;
|
|
3107
|
+
if (typeof getter !== "function")
|
|
3108
|
+
return null;
|
|
3109
|
+
return getter();
|
|
3110
|
+
}
|
|
3111
|
+
const readable = (client) => typeof client.getOperationSupport === "function";
|
|
3112
|
+
const first = this.selectWorkspaceScopeClient(readable);
|
|
3113
|
+
if (!first)
|
|
3114
|
+
return null;
|
|
3115
|
+
const aggregate = { ...first.client.getOperationSupport() };
|
|
3116
|
+
const contributors = {};
|
|
3117
|
+
for (const capability of Object.keys(aggregate)) {
|
|
3118
|
+
if (aggregate[capability]) {
|
|
3119
|
+
contributors[capability] = first.serverId;
|
|
3120
|
+
continue;
|
|
3121
|
+
}
|
|
3122
|
+
const supporter = this.selectWorkspaceScopeClient((client) => readable(client) && Boolean(client.getOperationSupport()[capability]));
|
|
3123
|
+
if (supporter) {
|
|
3124
|
+
aggregate[capability] = true;
|
|
3125
|
+
contributors[capability] = supporter.serverId;
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
if (attribution) {
|
|
3129
|
+
attribution.getOperationSupport = {
|
|
3130
|
+
baseClientId: first.serverId,
|
|
3131
|
+
contributors
|
|
3132
|
+
};
|
|
3133
|
+
}
|
|
3134
|
+
return aggregate;
|
|
3135
|
+
}
|
|
3136
|
+
async getCapabilitySnapshots(filePath, attribution) {
|
|
3137
|
+
if (this.checkDestroyed())
|
|
3138
|
+
return [];
|
|
3139
|
+
const snapshots = [];
|
|
3140
|
+
if (filePath) {
|
|
3141
|
+
const servers = getServersForFileWithConfig(filePath);
|
|
3142
|
+
for (const server of servers) {
|
|
3143
|
+
const root = await this.clientRegistry.resolveServerRoot(server, filePath);
|
|
3144
|
+
if (!root)
|
|
3145
|
+
continue;
|
|
3146
|
+
const client = this.state.clients.get(`${server.id}:${normalizeMapKey(root)}`);
|
|
3147
|
+
if (!client?.isAlive())
|
|
3148
|
+
continue;
|
|
3149
|
+
snapshots.push({
|
|
3150
|
+
serverId: server.id,
|
|
3151
|
+
root,
|
|
3152
|
+
operationSupport: client.getOperationSupport(),
|
|
3153
|
+
workspaceDiagnosticsSupport: client.getWorkspaceDiagnosticsSupport(),
|
|
3154
|
+
customServer: server.custom,
|
|
3155
|
+
diagnosticsPublished: this.state.diagnosticsPublished.has(server.id),
|
|
3156
|
+
diagnosticsUnsupported: this.state.diagnosticsUnsupported.has(server.id),
|
|
3157
|
+
advertisedCommands: client.getAdvertisedCommands(),
|
|
3158
|
+
rawCapabilityKeys: client.getRawCapabilityKeys?.() ?? [],
|
|
3159
|
+
textDocumentSave: textDocumentSaveOf(client),
|
|
3160
|
+
launchVariant: client.getLaunchVariant?.()
|
|
3161
|
+
});
|
|
3162
|
+
}
|
|
3163
|
+
return snapshots;
|
|
3164
|
+
}
|
|
3165
|
+
for (const [key, client] of this.state.clients) {
|
|
3166
|
+
if (!client.isAlive())
|
|
3167
|
+
continue;
|
|
3168
|
+
const separator = key.indexOf(":");
|
|
3169
|
+
const serverId = separator >= 0 ? key.slice(0, separator) : key;
|
|
3170
|
+
snapshots.push({
|
|
3171
|
+
serverId,
|
|
3172
|
+
root: client.root,
|
|
3173
|
+
operationSupport: client.getOperationSupport(),
|
|
3174
|
+
workspaceDiagnosticsSupport: client.getWorkspaceDiagnosticsSupport(),
|
|
3175
|
+
customServer: this.state.servers.get(serverId)?.custom,
|
|
3176
|
+
diagnosticsPublished: this.state.diagnosticsPublished.has(serverId),
|
|
3177
|
+
diagnosticsUnsupported: this.state.diagnosticsUnsupported.has(serverId),
|
|
3178
|
+
advertisedCommands: client.getAdvertisedCommands(),
|
|
3179
|
+
rawCapabilityKeys: client.getRawCapabilityKeys?.() ?? [],
|
|
3180
|
+
textDocumentSave: textDocumentSaveOf(client),
|
|
3181
|
+
launchVariant: client.getLaunchVariant?.()
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
3184
|
+
if (attribution) {
|
|
3185
|
+
attribution.getCapabilitySnapshots = {
|
|
3186
|
+
clientIds: snapshots.slice(0, WORKSPACE_ATTRIBUTION_CLIENT_CAP).map((snapshot) => snapshot.serverId),
|
|
3187
|
+
clientCount: snapshots.length
|
|
3188
|
+
};
|
|
3189
|
+
}
|
|
3190
|
+
return snapshots;
|
|
3191
|
+
}
|
|
3192
|
+
async getWorkspaceDiagnosticsSupport(filePath, attribution) {
|
|
3193
|
+
if (filePath) {
|
|
3194
|
+
const spawned = await this.getClientForFile(filePath);
|
|
3195
|
+
if (!spawned)
|
|
3196
|
+
return null;
|
|
3197
|
+
const getter = spawned.client.getWorkspaceDiagnosticsSupport;
|
|
3198
|
+
if (typeof getter !== "function")
|
|
3199
|
+
return null;
|
|
3200
|
+
return getter();
|
|
3201
|
+
}
|
|
3202
|
+
const first = this.selectWorkspaceScopeClient();
|
|
3203
|
+
if (!first)
|
|
3204
|
+
return null;
|
|
3205
|
+
const getter = first.client.getWorkspaceDiagnosticsSupport;
|
|
3206
|
+
if (typeof getter !== "function")
|
|
3207
|
+
return null;
|
|
3208
|
+
if (attribution)
|
|
3209
|
+
attribution.getWorkspaceDiagnosticsSupport = first.serverId;
|
|
3210
|
+
return getter.call(first.client);
|
|
3211
|
+
}
|
|
3212
|
+
async codeAction(filePath, line, character, endLine, endCharacter) {
|
|
3213
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3214
|
+
if (!spawned)
|
|
3215
|
+
return [];
|
|
3216
|
+
if (!spawned.client.getOperationSupport().codeAction) {
|
|
3217
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for codeAction");
|
|
3218
|
+
}
|
|
3219
|
+
return spawned.client.codeAction(filePath, line, character, endLine, endCharacter);
|
|
3220
|
+
}
|
|
3221
|
+
async rename(filePath, line, character, newName) {
|
|
3222
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3223
|
+
if (!spawned)
|
|
3224
|
+
return null;
|
|
3225
|
+
if (!spawned.client.getOperationSupport().rename) {
|
|
3226
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for rename");
|
|
3227
|
+
}
|
|
3228
|
+
return spawned.client.rename(filePath, line, character, newName);
|
|
3229
|
+
}
|
|
3230
|
+
async renameFile(oldFilePath, newFilePath, options) {
|
|
3231
|
+
const cwd = options.cwd;
|
|
3232
|
+
const apply = options.apply ?? false;
|
|
3233
|
+
await validateWorkspaceEdit({
|
|
3234
|
+
documentChanges: [
|
|
3235
|
+
{
|
|
3236
|
+
kind: "rename",
|
|
3237
|
+
oldUri: pathToFileURL(oldFilePath).href,
|
|
3238
|
+
newUri: pathToFileURL(newFilePath).href
|
|
3239
|
+
}
|
|
3240
|
+
]
|
|
3241
|
+
}, cwd);
|
|
3242
|
+
const priorityServerIds = getServersForFileWithConfig(oldFilePath).map((server) => server.id);
|
|
3243
|
+
const activeClients = this.activeClientsForCwd(cwd, priorityServerIds);
|
|
3244
|
+
const willRenameFailures = [];
|
|
3245
|
+
const didRenameFailures = [];
|
|
3246
|
+
const willRenameClients = activeClients.filter(({ serverId, client }) => {
|
|
3247
|
+
if (client.getOperationSupport().willRenameFiles === true)
|
|
3248
|
+
return true;
|
|
3249
|
+
recordDegradationOnce({
|
|
3250
|
+
kind: "lsp-capability-skip",
|
|
3251
|
+
subject: `${serverId}:workspace/willRenameFiles`,
|
|
3252
|
+
reason: client.getMalformedFileOperationRegistrations().has("willRename") ? "malformed-registration" : "no-registration"
|
|
3253
|
+
});
|
|
3254
|
+
return false;
|
|
3255
|
+
});
|
|
3256
|
+
const renameRequestedAtMs = Date.now();
|
|
3257
|
+
const willResults = await Promise.all(willRenameClients.map(async ({ clientKey, serverId, client }) => {
|
|
3258
|
+
try {
|
|
3259
|
+
return {
|
|
3260
|
+
clientKey,
|
|
3261
|
+
serverId,
|
|
3262
|
+
edit: await client.willRenameFiles(oldFilePath, newFilePath),
|
|
3263
|
+
failed: false
|
|
3264
|
+
};
|
|
3265
|
+
} catch (err) {
|
|
3266
|
+
willRenameFailures.push({
|
|
3267
|
+
serverId,
|
|
3268
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3269
|
+
});
|
|
3270
|
+
return { clientKey, serverId, edit: null, failed: true };
|
|
3271
|
+
}
|
|
3272
|
+
}));
|
|
3273
|
+
const successfulWillResults = willResults.filter((result) => !result.failed);
|
|
3274
|
+
if (willRenameClients.length > 0 && successfulWillResults.length === 0) {
|
|
3275
|
+
throw new Error(`workspace/willRenameFiles failed for all active LSP servers: ${willRenameFailures.map((failure) => `${failure.serverId}: ${failure.error}`).join("; ")}`);
|
|
3276
|
+
}
|
|
3277
|
+
const merged = mergeWorkspaceTextEditsByPriority(successfulWillResults);
|
|
3278
|
+
const summary = summarizeWorkspaceEdit(merged.edit, cwd);
|
|
3279
|
+
if (!apply) {
|
|
3280
|
+
return {
|
|
3281
|
+
applied: false,
|
|
3282
|
+
serverIds: activeClients.map((entry) => entry.serverId),
|
|
3283
|
+
willRenameFailures,
|
|
3284
|
+
didRenameFailures,
|
|
3285
|
+
droppedConflicts: merged.droppedConflicts,
|
|
3286
|
+
inputEditCount: merged.inputEditCount,
|
|
3287
|
+
summary
|
|
3288
|
+
};
|
|
3289
|
+
}
|
|
3290
|
+
let applied;
|
|
3291
|
+
try {
|
|
3292
|
+
applied = await applyWorkspaceEdit(merged.edit, cwd, {
|
|
3293
|
+
mutationContext: options.mutationContext,
|
|
3294
|
+
observe: false,
|
|
3295
|
+
watchedFileSink: this,
|
|
3296
|
+
expectedContent: captureRenameExpectedContent(merged.edit, cwd, renameRequestedAtMs, (filePath, atCwd, sourceClientKeys) => sourceClientKeys === undefined ? this.getTrackedContent(filePath, atCwd) : this.getTrackedContent(filePath, atCwd, sourceClientKeys), undefined, merged.sourceClientKeys)
|
|
3297
|
+
});
|
|
3298
|
+
} catch (err) {
|
|
3299
|
+
if (options.mutationContext) {
|
|
3300
|
+
const partial = err.appliedWorkspaceEdit;
|
|
3301
|
+
if (partial) {
|
|
3302
|
+
recordLspMutation(options.mutationContext, {
|
|
3303
|
+
results: [partial],
|
|
3304
|
+
status: "failed"
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
throw err;
|
|
3309
|
+
}
|
|
3310
|
+
const openDocuments = activeClients.filter(({ client }) => client.isDocumentOpen(oldFilePath)).map(({ clientKey, serverId, client }) => ({
|
|
3311
|
+
clientKey,
|
|
3312
|
+
serverId,
|
|
3313
|
+
client,
|
|
3314
|
+
oldUri: client.getDocumentUri(oldFilePath)
|
|
3315
|
+
}));
|
|
3316
|
+
const closeFailures = [];
|
|
3317
|
+
await Promise.all(activeClients.map(async ({ serverId, client }) => {
|
|
3318
|
+
const result = await runRenameNotify(() => client.closeDocument(oldFilePath), RENAME_NOTIFY_TIMEOUT_MS);
|
|
3319
|
+
if (!result.ok) {
|
|
3320
|
+
closeFailures.push({
|
|
3321
|
+
serverId,
|
|
3322
|
+
error: result.error,
|
|
3323
|
+
disposition: result.disposition
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
}));
|
|
3327
|
+
if (closeFailures.length > 0) {
|
|
3328
|
+
if (options.mutationContext) {
|
|
3329
|
+
recordLspMutation(options.mutationContext, {
|
|
3330
|
+
results: [applied],
|
|
3331
|
+
status: "failed"
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3334
|
+
const content = await fs.readFile(oldFilePath, "utf-8");
|
|
3335
|
+
const languageId = getLanguageId(oldFilePath) ?? "plaintext";
|
|
3336
|
+
const resyncFailures = [];
|
|
3337
|
+
await Promise.all(openDocuments.map(async ({ serverId, client }) => {
|
|
3338
|
+
const resyncResult = await runRenameNotify(() => client.notify.open(oldFilePath, content, languageId, true, true).then((sent) => {
|
|
3339
|
+
if (sent === false) {
|
|
3340
|
+
throw new Error(client.isAlive() ? "re-open not sent: the close is still queued" : "re-open not sent: the client is dead");
|
|
3341
|
+
}
|
|
3342
|
+
}), RENAME_NOTIFY_TIMEOUT_MS);
|
|
3343
|
+
if (!resyncResult.ok) {
|
|
3344
|
+
resyncFailures.push({
|
|
3345
|
+
serverId,
|
|
3346
|
+
error: resyncResult.error,
|
|
3347
|
+
disposition: resyncResult.disposition
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
}));
|
|
3351
|
+
if (resyncFailures.length > 0) {
|
|
3352
|
+
logLatency({
|
|
3353
|
+
type: "phase",
|
|
3354
|
+
phase: "lsp_rename_resync_failed",
|
|
3355
|
+
filePath: oldFilePath,
|
|
3356
|
+
durationMs: 0,
|
|
3357
|
+
metadata: {
|
|
3358
|
+
failures: resyncFailures.map((failure) => ({
|
|
3359
|
+
serverId: failure.serverId,
|
|
3360
|
+
disposition: failure.disposition,
|
|
3361
|
+
error: failure.error
|
|
3362
|
+
}))
|
|
3363
|
+
}
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
const closeFailureSummary = closeFailures.map((failure) => `${failure.serverId} (${failure.disposition}): ${failure.error}`).join("; ");
|
|
3367
|
+
const resyncFailureSummary = resyncFailures.length > 0 ? ` (resync also failed: ${resyncFailures.map((failure) => `${failure.serverId} (${failure.disposition}): ${failure.error}`).join("; ")})` : "";
|
|
3368
|
+
throw new Error(`workspace/didClose failed; rename aborted: ${closeFailureSummary}${resyncFailureSummary}`);
|
|
3369
|
+
}
|
|
3370
|
+
let renameApplied;
|
|
3371
|
+
try {
|
|
3372
|
+
renameApplied = await applyWorkspaceEdit({
|
|
3373
|
+
documentChanges: [
|
|
3374
|
+
{
|
|
3375
|
+
kind: "rename",
|
|
3376
|
+
oldUri: pathToFileURL(oldFilePath).href,
|
|
3377
|
+
newUri: pathToFileURL(newFilePath).href
|
|
3378
|
+
}
|
|
3379
|
+
]
|
|
3380
|
+
}, cwd, { observe: false, watchedFileSink: this });
|
|
3381
|
+
} catch (err) {
|
|
3382
|
+
if (options.mutationContext) {
|
|
3383
|
+
recordLspMutation(options.mutationContext, {
|
|
3384
|
+
results: [applied],
|
|
3385
|
+
status: "failed"
|
|
3386
|
+
});
|
|
3387
|
+
}
|
|
3388
|
+
throw err;
|
|
3389
|
+
}
|
|
3390
|
+
const relOld = path.relative(cwd, oldFilePath).replace(/\\/g, "/") || path.basename(oldFilePath);
|
|
3391
|
+
const relNew = path.relative(cwd, newFilePath).replace(/\\/g, "/") || path.basename(newFilePath);
|
|
3392
|
+
const renameDescription = `Renamed ${relOld} → ${relNew}`;
|
|
3393
|
+
await Promise.all(activeClients.map(async ({ clientKey, serverId, client }) => {
|
|
3394
|
+
if (client.getOperationSupport().didRenameFiles !== true) {
|
|
3395
|
+
recordDegradationOnce({
|
|
3396
|
+
kind: "lsp-capability-skip",
|
|
3397
|
+
subject: `${serverId}:workspace/didRenameFiles`,
|
|
3398
|
+
reason: client.getMalformedFileOperationRegistrations().has("didRename") ? "malformed-registration" : "no-registration"
|
|
3399
|
+
});
|
|
3400
|
+
return;
|
|
3401
|
+
}
|
|
3402
|
+
const opened = openDocuments.find((entry) => entry.clientKey === clientKey);
|
|
3403
|
+
const result = await runRenameNotify(() => opened?.oldUri ? client.didRenameFiles(oldFilePath, newFilePath, opened.oldUri, destinationUriPreservingSpelling(opened.oldUri, oldFilePath, newFilePath)) : client.didRenameFiles(oldFilePath, newFilePath), RENAME_NOTIFY_TIMEOUT_MS);
|
|
3404
|
+
if (!result.ok) {
|
|
3405
|
+
didRenameFailures.push({
|
|
3406
|
+
serverId,
|
|
3407
|
+
error: result.error,
|
|
3408
|
+
disposition: result.disposition
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
}));
|
|
3412
|
+
const files = [...new Set([...applied.files, oldFilePath, newFilePath])];
|
|
3413
|
+
if (options.mutationContext) {
|
|
3414
|
+
recordLspMutation(options.mutationContext, {
|
|
3415
|
+
results: [
|
|
3416
|
+
{
|
|
3417
|
+
...applied,
|
|
3418
|
+
files,
|
|
3419
|
+
operationTotal: applied.operationTotal + renameApplied.operationTotal,
|
|
3420
|
+
appliedOperationTotal: applied.appliedOperationTotal + renameApplied.appliedOperationTotal,
|
|
3421
|
+
appliedOperationIndexes: [
|
|
3422
|
+
...applied.appliedOperationIndexes,
|
|
3423
|
+
...renameApplied.appliedOperationIndexes.map((index) => applied.operationTotal + index)
|
|
3424
|
+
],
|
|
3425
|
+
operationCounts: {
|
|
3426
|
+
textEdits: applied.operationCounts.textEdits + renameApplied.operationCounts.textEdits,
|
|
3427
|
+
create: applied.operationCounts.create + renameApplied.operationCounts.create,
|
|
3428
|
+
rename: applied.operationCounts.rename + renameApplied.operationCounts.rename,
|
|
3429
|
+
delete: applied.operationCounts.delete + renameApplied.operationCounts.delete
|
|
3430
|
+
},
|
|
3431
|
+
fileDetails: [...applied.fileDetails, ...renameApplied.fileDetails]
|
|
3432
|
+
}
|
|
3433
|
+
],
|
|
3434
|
+
status: "success"
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
return {
|
|
3438
|
+
applied: true,
|
|
3439
|
+
serverIds: activeClients.map((entry) => entry.serverId),
|
|
3440
|
+
willRenameFailures,
|
|
3441
|
+
didRenameFailures,
|
|
3442
|
+
droppedConflicts: merged.droppedConflicts,
|
|
3443
|
+
inputEditCount: merged.inputEditCount,
|
|
3444
|
+
summary,
|
|
3445
|
+
descriptions: [...applied.descriptions, renameDescription],
|
|
3446
|
+
files
|
|
3447
|
+
};
|
|
3448
|
+
}
|
|
3449
|
+
async implementation(filePath, line, character) {
|
|
3450
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3451
|
+
if (!spawned)
|
|
3452
|
+
return [];
|
|
3453
|
+
if (!spawned.client.getOperationSupport().implementation) {
|
|
3454
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for implementation");
|
|
3455
|
+
}
|
|
3456
|
+
return spawned.client.implementation(filePath, line, character);
|
|
3457
|
+
}
|
|
3458
|
+
async prepareCallHierarchy(filePath, line, character) {
|
|
3459
|
+
const spawned = await this.getClientForFile(filePath, NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3460
|
+
if (!spawned)
|
|
3461
|
+
return [];
|
|
3462
|
+
if (!spawned.client.getOperationSupport().callHierarchy) {
|
|
3463
|
+
throw new Error("__UNSUPPORTED__ Active LSP server does not advertise support for prepareCallHierarchy");
|
|
3464
|
+
}
|
|
3465
|
+
return spawned.client.prepareCallHierarchy(filePath, line, character);
|
|
3466
|
+
}
|
|
3467
|
+
async incomingCalls(item) {
|
|
3468
|
+
const spawned = await this.getClientForFile(uriToPath(item.uri), NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3469
|
+
if (!spawned)
|
|
3470
|
+
return [];
|
|
3471
|
+
if (!spawned.client.getOperationSupport().callHierarchy)
|
|
3472
|
+
return [];
|
|
3473
|
+
return spawned.client.incomingCalls(item);
|
|
3474
|
+
}
|
|
3475
|
+
async outgoingCalls(item) {
|
|
3476
|
+
const spawned = await this.getClientForFile(uriToPath(item.uri), NAV_CLIENT_WAIT_TIMEOUT_MS);
|
|
3477
|
+
if (!spawned)
|
|
3478
|
+
return [];
|
|
3479
|
+
if (!spawned.client.getOperationSupport().callHierarchy)
|
|
3480
|
+
return [];
|
|
3481
|
+
return spawned.client.outgoingCalls(item);
|
|
3482
|
+
}
|
|
3483
|
+
async ensureWarmForSweep(representativeFile, options = {}) {
|
|
3484
|
+
if (this.checkDestroyed() || options.signal?.aborted) {
|
|
3485
|
+
return { performedWarmup: false, failedServerIds: [] };
|
|
3486
|
+
}
|
|
3487
|
+
const servers = getServersForFileWithConfig(representativeFile).filter((s) => !isAuxiliary(s));
|
|
3488
|
+
if (servers.length === 0) {
|
|
3489
|
+
return { performedWarmup: false, failedServerIds: [] };
|
|
3490
|
+
}
|
|
3491
|
+
const keys = await Promise.all(servers.map((server) => this.demonstratedReadyKeyFor(server, representativeFile)));
|
|
3492
|
+
const headOf = new Map;
|
|
3493
|
+
const familyHead = servers.map((server) => {
|
|
3494
|
+
const preferredHead = server.fallbackFor === undefined ? undefined : headOf.get(server.fallbackFor);
|
|
3495
|
+
const head = preferredHead ?? server.id;
|
|
3496
|
+
headOf.set(server.id, head);
|
|
3497
|
+
return head;
|
|
3498
|
+
});
|
|
3499
|
+
const isColdAt = (i) => {
|
|
3500
|
+
const key = keys[i];
|
|
3501
|
+
if (key === undefined || this.state.demonstratedReady.has(key)) {
|
|
3502
|
+
return false;
|
|
3503
|
+
}
|
|
3504
|
+
return !servers.some((_, j) => {
|
|
3505
|
+
const peerKey = keys[j];
|
|
3506
|
+
return peerKey !== undefined && familyHead[j] === familyHead[i] && this.state.demonstratedReady.has(peerKey);
|
|
3507
|
+
});
|
|
3508
|
+
};
|
|
3509
|
+
const alreadyWarm = servers.every((_, i) => !isColdAt(i));
|
|
3510
|
+
if (alreadyWarm)
|
|
3511
|
+
return { performedWarmup: false, failedServerIds: [] };
|
|
3512
|
+
const cachedColdServerIds = [];
|
|
3513
|
+
let allNonWarmCached = true;
|
|
3514
|
+
for (let i = 0;i < servers.length; i++) {
|
|
3515
|
+
const key = keys[i];
|
|
3516
|
+
if (key === undefined || !isColdAt(i))
|
|
3517
|
+
continue;
|
|
3518
|
+
if (this.state.demonstratedCold.has(key)) {
|
|
3519
|
+
cachedColdServerIds.push(servers[i].id);
|
|
3520
|
+
} else {
|
|
3521
|
+
allNonWarmCached = false;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
if (allNonWarmCached && cachedColdServerIds.length > 0) {
|
|
3525
|
+
logLatency({
|
|
3526
|
+
type: "phase",
|
|
3527
|
+
phase: "lsp_sweep_warmup_cached_cold",
|
|
3528
|
+
filePath: representativeFile,
|
|
3529
|
+
durationMs: 0,
|
|
3530
|
+
metadata: { serverIds: cachedColdServerIds }
|
|
3531
|
+
});
|
|
3532
|
+
return {
|
|
3533
|
+
performedWarmup: false,
|
|
3534
|
+
failedServerIds: cachedColdServerIds,
|
|
3535
|
+
skippedFromCache: true
|
|
3536
|
+
};
|
|
3537
|
+
}
|
|
3538
|
+
let content;
|
|
3539
|
+
try {
|
|
3540
|
+
content = await nodeFs.promises.readFile(representativeFile, "utf-8");
|
|
3541
|
+
} catch {
|
|
3542
|
+
return { performedWarmup: false, failedServerIds: [] };
|
|
3543
|
+
}
|
|
3544
|
+
if (options.signal?.aborted) {
|
|
3545
|
+
return { performedWarmup: false, failedServerIds: [] };
|
|
3546
|
+
}
|
|
3547
|
+
const timeoutMs = options.timeoutMs ?? warmupTimeoutMs();
|
|
3548
|
+
const rootedServerIds = [];
|
|
3549
|
+
const unrootedServerIds = [];
|
|
3550
|
+
for (let i = 0;i < servers.length; i++) {
|
|
3551
|
+
if (keys[i] !== undefined)
|
|
3552
|
+
rootedServerIds.push(servers[i].id);
|
|
3553
|
+
else
|
|
3554
|
+
unrootedServerIds.push(servers[i].id);
|
|
3555
|
+
}
|
|
3556
|
+
const unrootedCandidates = {
|
|
3557
|
+
count: unrootedServerIds.length,
|
|
3558
|
+
ids: unrootedServerIds
|
|
3559
|
+
};
|
|
3560
|
+
const stillColdServerIds = () => {
|
|
3561
|
+
const cold = [];
|
|
3562
|
+
for (let i = 0;i < servers.length; i++) {
|
|
3563
|
+
if (isColdAt(i))
|
|
3564
|
+
cold.push(servers[i].id);
|
|
3565
|
+
}
|
|
3566
|
+
return cold;
|
|
3567
|
+
};
|
|
3568
|
+
const runWarmupTouch = async (attempt) => {
|
|
3569
|
+
if (options.signal?.aborted)
|
|
3570
|
+
return;
|
|
3571
|
+
const startedAt = Date.now();
|
|
3572
|
+
logLatency({
|
|
3573
|
+
type: "phase",
|
|
3574
|
+
phase: "lsp_sweep_warmup_start",
|
|
3575
|
+
filePath: representativeFile,
|
|
3576
|
+
durationMs: 0,
|
|
3577
|
+
metadata: {
|
|
3578
|
+
serverIds: rootedServerIds,
|
|
3579
|
+
unrootedCandidates,
|
|
3580
|
+
timeoutMs,
|
|
3581
|
+
attempt
|
|
3582
|
+
}
|
|
3583
|
+
});
|
|
3584
|
+
const warmupAttempt = this.touchFile(representativeFile, content, {
|
|
3585
|
+
diagnostics: "document",
|
|
3586
|
+
collectDiagnostics: false,
|
|
3587
|
+
clientScope: "primary",
|
|
3588
|
+
source: "lsp_sweep_warmup",
|
|
3589
|
+
maxClientWaitMs: timeoutMs,
|
|
3590
|
+
maxDiagnosticsWaitMs: timeoutMs,
|
|
3591
|
+
warmupOverride: true,
|
|
3592
|
+
warmupAttempt: attempt
|
|
3593
|
+
});
|
|
3594
|
+
await (options.signal ? Promise.race([
|
|
3595
|
+
withDeadline(warmupAttempt, {
|
|
3596
|
+
ms: timeoutMs,
|
|
3597
|
+
onTimeout: "undefined"
|
|
3598
|
+
}),
|
|
3599
|
+
new Promise((resolve) => {
|
|
3600
|
+
if (options.signal.aborted) {
|
|
3601
|
+
resolve();
|
|
3602
|
+
return;
|
|
3603
|
+
}
|
|
3604
|
+
options.signal.addEventListener("abort", () => resolve(), {
|
|
3605
|
+
once: true
|
|
3606
|
+
});
|
|
3607
|
+
})
|
|
3608
|
+
]) : withDeadline(warmupAttempt, {
|
|
3609
|
+
ms: timeoutMs,
|
|
3610
|
+
onTimeout: "undefined"
|
|
3611
|
+
}));
|
|
3612
|
+
const coldServerIds = stillColdServerIds();
|
|
3613
|
+
logLatency({
|
|
3614
|
+
type: "phase",
|
|
3615
|
+
phase: options.signal?.aborted ? "lsp_sweep_warmup_aborted" : coldServerIds.length > 0 ? "lsp_sweep_warmup_failed" : "lsp_sweep_warmup_done",
|
|
3616
|
+
filePath: representativeFile,
|
|
3617
|
+
durationMs: Date.now() - startedAt,
|
|
3618
|
+
metadata: {
|
|
3619
|
+
serverIds: rootedServerIds,
|
|
3620
|
+
unrootedCandidates,
|
|
3621
|
+
timeoutMs,
|
|
3622
|
+
attempt,
|
|
3623
|
+
coldServerIds
|
|
3624
|
+
}
|
|
3625
|
+
});
|
|
3626
|
+
};
|
|
3627
|
+
await runWarmupTouch(1);
|
|
3628
|
+
let failedServerIds = stillColdServerIds();
|
|
3629
|
+
const warmedClients = keys.map((key) => key === undefined ? undefined : this.state.clients.get(key));
|
|
3630
|
+
if (failedServerIds.length > 0 && !options.signal?.aborted) {
|
|
3631
|
+
const backoffMs = warmupRetryBackoffMs();
|
|
3632
|
+
if (backoffMs > 0) {
|
|
3633
|
+
await new Promise((resolve) => {
|
|
3634
|
+
const timer = setTimeout(resolve, backoffMs);
|
|
3635
|
+
timer.unref?.();
|
|
3636
|
+
options.signal?.addEventListener("abort", () => resolve(), {
|
|
3637
|
+
once: true
|
|
3638
|
+
});
|
|
3639
|
+
});
|
|
3640
|
+
}
|
|
3641
|
+
if (!options.signal?.aborted) {
|
|
3642
|
+
await runWarmupTouch(2);
|
|
3643
|
+
failedServerIds = stillColdServerIds();
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
if (failedServerIds.length > 0) {
|
|
3647
|
+
for (let i = 0;i < servers.length; i++) {
|
|
3648
|
+
const key = keys[i];
|
|
3649
|
+
if (key !== undefined && failedServerIds.includes(servers[i].id) && this.state.clients.get(key) === warmedClients[i]) {
|
|
3650
|
+
this.state.demonstratedCold.add(key);
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
return { performedWarmup: true, failedServerIds };
|
|
3655
|
+
}
|
|
3656
|
+
async runWorkspaceDiagnostics(cwd, options = {}) {
|
|
3657
|
+
const releaseSweepHold = acquireWorkspaceSweepHold();
|
|
3658
|
+
try {
|
|
3659
|
+
return await this.runWorkspaceDiagnosticsSwept(cwd, options);
|
|
3660
|
+
} finally {
|
|
3661
|
+
releaseSweepHold();
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
async runWorkspaceDiagnosticsSwept(cwd, options = {}) {
|
|
3665
|
+
const startedAt = Date.now();
|
|
3666
|
+
const root = path.resolve(cwd);
|
|
3667
|
+
const { signal } = options;
|
|
3668
|
+
this.sweepDocumentDrift().catch(() => {});
|
|
3669
|
+
const maxFiles = typeof options.maxFiles === "number" && Number.isFinite(options.maxFiles) && options.maxFiles > 0 ? Math.floor(options.maxFiles) : getMaxWorkspaceDiagnosticFiles();
|
|
3670
|
+
const files = options.files ? options.files.slice(0, maxFiles) : await collectWorkspaceDiagnosticFiles(root, maxFiles, signal);
|
|
3671
|
+
const perFileMs = (() => {
|
|
3672
|
+
const raw = Number(process.env.DM_LENS_LSP_WORKSPACE_PER_FILE_MS);
|
|
3673
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 15000;
|
|
3674
|
+
})();
|
|
3675
|
+
const results = [];
|
|
3676
|
+
let completed = 0;
|
|
3677
|
+
let timedOutFiles = 0;
|
|
3678
|
+
let lastHeartbeat = Date.now();
|
|
3679
|
+
const workspaceDiagnosticsCacheCtx = createWorkspaceDiagnosticsCacheContext(root);
|
|
3680
|
+
const workspaceSweepScopeKey = buildScopeKey("all", [
|
|
3681
|
+
...WORKSPACE_SWEEP_EXCLUDED_SERVER_IDS
|
|
3682
|
+
]);
|
|
3683
|
+
const touchScopedOpenDependencies = async (filePath) => {
|
|
3684
|
+
if (options.files === undefined)
|
|
3685
|
+
return true;
|
|
3686
|
+
const imports = workspaceDiagnosticsCacheCtx.importsFor(filePath);
|
|
3687
|
+
if (!imports)
|
|
3688
|
+
return false;
|
|
3689
|
+
const openImports = imports.filter((dependency) => this.hasLiveClientHoldingDocument(dependency));
|
|
3690
|
+
const capped = openImports.length > SCOPED_DEPENDENCY_TOUCH_MAX;
|
|
3691
|
+
if (capped) {
|
|
3692
|
+
recordDegradationOnce({
|
|
3693
|
+
kind: "lsp_dependency_touch_capped",
|
|
3694
|
+
subject: filePath,
|
|
3695
|
+
reason: `scoped full scan limited open import touches to ${SCOPED_DEPENDENCY_TOUCH_MAX}`
|
|
3696
|
+
});
|
|
3697
|
+
}
|
|
3698
|
+
await Promise.all(openImports.slice(0, SCOPED_DEPENDENCY_TOUCH_MAX).map(async (dependency) => {
|
|
3699
|
+
let content;
|
|
3700
|
+
try {
|
|
3701
|
+
content = await fs.readFile(dependency, "utf8");
|
|
3702
|
+
} catch {
|
|
3703
|
+
return;
|
|
3704
|
+
}
|
|
3705
|
+
await this.touchFile(dependency, content, {
|
|
3706
|
+
diagnostics: "none",
|
|
3707
|
+
source: "lens_diagnostics_full_dependency",
|
|
3708
|
+
clientScope: "all",
|
|
3709
|
+
excludeServerIds: await this.serverIdsNotHoldingDocument(dependency)
|
|
3710
|
+
});
|
|
3711
|
+
}));
|
|
3712
|
+
return !capped;
|
|
3713
|
+
};
|
|
3714
|
+
this.announceCreatedFiles([...files, ...goPackageFilesToAnnounce(files)], await importTargetsToAnnounce(root, files.filter((filePath) => !workspaceDiagnosticsCacheCtx.servesClean(filePath, workspaceSweepScopeKey)), (filePath, scope) => workspaceDiagnosticsCacheCtx.noteImportScope(filePath, scope)));
|
|
3715
|
+
const cachedResults = [];
|
|
3716
|
+
const filesToTouch = [];
|
|
3717
|
+
const writeIndexByPath = new Map;
|
|
3718
|
+
for (const filePath of files) {
|
|
3719
|
+
writeIndexByPath.set(normalizeMapKey(filePath), options.nextWriteIndex?.());
|
|
3720
|
+
const cached = workspaceDiagnosticsCacheCtx.lookup(filePath, workspaceSweepScopeKey);
|
|
3721
|
+
if (cached && cached.binding.boundToCurrentDisk !== false) {
|
|
3722
|
+
const dependenciesConfirmed = await touchScopedOpenDependencies(filePath);
|
|
3723
|
+
if (dependenciesConfirmed)
|
|
3724
|
+
cachedResults.push({
|
|
3725
|
+
filePath,
|
|
3726
|
+
diagnostics: cached.diagnostics,
|
|
3727
|
+
count: cached.count,
|
|
3728
|
+
observedAt: cached.scannedAt,
|
|
3729
|
+
contentHash: cached.binding.contentHash,
|
|
3730
|
+
boundToCurrentDisk: cached.binding.boundToCurrentDisk,
|
|
3731
|
+
writeIndex: writeIndexByPath.get(normalizeMapKey(filePath))
|
|
3732
|
+
});
|
|
3733
|
+
else
|
|
3734
|
+
filesToTouch.push(filePath);
|
|
3735
|
+
} else {
|
|
3736
|
+
filesToTouch.push(filePath);
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
completed = cachedResults.length;
|
|
3740
|
+
if (cachedResults.length > 0) {
|
|
3741
|
+
options.onProgress?.(completed, files.length);
|
|
3742
|
+
}
|
|
3743
|
+
const cacheServedKeys = new Set(cachedResults.map((result) => normalizeMapKey(result.filePath)));
|
|
3744
|
+
const supersededCacheKeys = new Set;
|
|
3745
|
+
const pullAnsweredFiles = new Set;
|
|
3746
|
+
const scannedMtimeByFile = new Map;
|
|
3747
|
+
const scannedSizeByFile = new Map;
|
|
3748
|
+
const scannedAtByFile = new Map;
|
|
3749
|
+
const noteScanStat = (filePath) => {
|
|
3750
|
+
scannedAtByFile.set(filePath, Date.now());
|
|
3751
|
+
try {
|
|
3752
|
+
const scanStat = nodeFs.statSync(filePath);
|
|
3753
|
+
scannedMtimeByFile.set(filePath, scanStat.mtimeMs);
|
|
3754
|
+
scannedSizeByFile.set(filePath, scanStat.size);
|
|
3755
|
+
} catch {}
|
|
3756
|
+
};
|
|
3757
|
+
const groups = groupFilesByPrimaryServer(filesToTouch);
|
|
3758
|
+
const sweepIndexGate = createSweepIndexGate();
|
|
3759
|
+
const workspacePullEnabled = process.env.DM_LENS_LSP_WORKSPACE_PULL === "1";
|
|
3760
|
+
logLatency({
|
|
3761
|
+
type: "phase",
|
|
3762
|
+
phase: "lsp_workspace_diagnostics_start",
|
|
3763
|
+
filePath: root,
|
|
3764
|
+
durationMs: 0,
|
|
3765
|
+
metadata: {
|
|
3766
|
+
fileCount: files.length,
|
|
3767
|
+
cacheHits: cachedResults.length,
|
|
3768
|
+
filesToTouch: filesToTouch.length,
|
|
3769
|
+
maxFiles,
|
|
3770
|
+
perFileMs,
|
|
3771
|
+
serverGroups: groups.length
|
|
3772
|
+
}
|
|
3773
|
+
});
|
|
3774
|
+
const contentCache = new Map;
|
|
3775
|
+
const preOpenGroupFiles = async (groupFiles) => {
|
|
3776
|
+
if (isWarmAttached())
|
|
3777
|
+
return;
|
|
3778
|
+
for (const filePath of groupFiles) {
|
|
3779
|
+
if (signal?.aborted)
|
|
3780
|
+
return;
|
|
3781
|
+
let content;
|
|
3782
|
+
noteScanStat(filePath);
|
|
3783
|
+
try {
|
|
3784
|
+
content = await nodeFs.promises.readFile(filePath, "utf-8");
|
|
3785
|
+
} catch {
|
|
3786
|
+
continue;
|
|
3787
|
+
}
|
|
3788
|
+
contentCache.set(filePath, content);
|
|
3789
|
+
const languageId = getLanguageId(filePath) ?? "plaintext";
|
|
3790
|
+
const preOpenAttempt = withDeadline((async () => {
|
|
3791
|
+
const { clients } = await this.getClientsForFile(filePath, WORKSPACE_SWEEP_EXCLUDED_SERVER_IDS);
|
|
3792
|
+
for (const entry of clients) {
|
|
3793
|
+
let auxKey;
|
|
3794
|
+
if (isAuxiliary(entry.info)) {
|
|
3795
|
+
auxKey = await this.demonstratedReadyKeyFor(entry.info, filePath);
|
|
3796
|
+
if (auxKey && this.auxNotifyBacklogAtCeiling(auxKey, entry)) {
|
|
3797
|
+
continue;
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
try {
|
|
3801
|
+
const sent = await entry.client.notify.open(filePath, content, languageId);
|
|
3802
|
+
if (auxKey && sent !== false) {
|
|
3803
|
+
this.noteAuxNotifyIssued(auxKey, entry.client);
|
|
3804
|
+
}
|
|
3805
|
+
} catch {}
|
|
3806
|
+
}
|
|
3807
|
+
})(), { ms: perFileMs, onTimeout: "undefined" });
|
|
3808
|
+
await (signal ? Promise.race([
|
|
3809
|
+
preOpenAttempt,
|
|
3810
|
+
new Promise((resolve) => {
|
|
3811
|
+
if (signal.aborted) {
|
|
3812
|
+
resolve();
|
|
3813
|
+
return;
|
|
3814
|
+
}
|
|
3815
|
+
signal.addEventListener("abort", () => resolve(), {
|
|
3816
|
+
once: true
|
|
3817
|
+
});
|
|
3818
|
+
})
|
|
3819
|
+
]) : preOpenAttempt);
|
|
3820
|
+
}
|
|
3821
|
+
};
|
|
3822
|
+
const markServiceDestroyed = (remainingFiles) => {
|
|
3823
|
+
for (const filePath of remainingFiles) {
|
|
3824
|
+
results.push({
|
|
3825
|
+
filePath,
|
|
3826
|
+
diagnostics: [],
|
|
3827
|
+
count: 0,
|
|
3828
|
+
timedOut: true,
|
|
3829
|
+
unconfirmedReason: "service_destroyed",
|
|
3830
|
+
writeIndex: writeIndexByPath.get(normalizeMapKey(filePath))
|
|
3831
|
+
});
|
|
3832
|
+
timedOutFiles += 1;
|
|
3833
|
+
completed += 1;
|
|
3834
|
+
}
|
|
3835
|
+
options.onProgress?.(completed, files.length);
|
|
3836
|
+
};
|
|
3837
|
+
const processFile = async (filePath) => {
|
|
3838
|
+
try {
|
|
3839
|
+
let content = contentCache.get(filePath);
|
|
3840
|
+
if (content === undefined) {
|
|
3841
|
+
noteScanStat(filePath);
|
|
3842
|
+
content = await nodeFs.promises.readFile(filePath, "utf-8");
|
|
3843
|
+
}
|
|
3844
|
+
const attached = isWarmAttached() ? await tryWarmAttachedDiagnostics(filePath, content, perFileMs, "sweep") : undefined;
|
|
3845
|
+
if (attached && !attached.available) {
|
|
3846
|
+
await this.ensureWarmForSweep(filePath, { signal });
|
|
3847
|
+
}
|
|
3848
|
+
const touchResult = attached?.available ? {
|
|
3849
|
+
diags: attached.response.projectIdentity === undefined ? attached.response.diagnostics : await demoteInferredProjectDiagnostics(attached.response.diagnostics, {
|
|
3850
|
+
filePath,
|
|
3851
|
+
cwd,
|
|
3852
|
+
identityCache: new Map([
|
|
3853
|
+
[filePath, attached.response.projectIdentity]
|
|
3854
|
+
])
|
|
3855
|
+
}),
|
|
3856
|
+
...attached.response.unconfirmedServerIds !== undefined && {
|
|
3857
|
+
unconfirmedServerIds: attached.response.unconfirmedServerIds
|
|
3858
|
+
}
|
|
3859
|
+
} : await withDeadline(this.touchFile(filePath, content, {
|
|
3860
|
+
diagnostics: "document",
|
|
3861
|
+
collectDiagnostics: true,
|
|
3862
|
+
clientScope: "all",
|
|
3863
|
+
source: "lens_diagnostics_full",
|
|
3864
|
+
excludeServerIds: WORKSPACE_SWEEP_EXCLUDED_SERVER_IDS,
|
|
3865
|
+
sweepIndexGate
|
|
3866
|
+
}), { ms: perFileMs, onTimeout: "undefined" });
|
|
3867
|
+
const diagnostics = touchResult?.diags;
|
|
3868
|
+
const inconclusive = touchResult?.inconclusive === true;
|
|
3869
|
+
const unconfirmedServerIds = touchCoverageGap(touchResult);
|
|
3870
|
+
const coverageGap = unconfirmedServerIds.length > 0;
|
|
3871
|
+
const declinedOutsideRoot = touchResult?.skipReason === "outside-project-root";
|
|
3872
|
+
const timedOut = touchResult === undefined || inconclusive || declinedOutsideRoot;
|
|
3873
|
+
if (timedOut)
|
|
3874
|
+
timedOutFiles += 1;
|
|
3875
|
+
const unconfirmedReason = touchResult === undefined ? "budget" : declinedOutsideRoot ? "outside_project_root" : inconclusive ? touchResult?.inconclusiveReason === "primary-unavailable" ? SWEEP_REASON_FOR_CAUSE[touchResult.primaryUnavailableCause ?? "unstarted"] : "inconclusive" : undefined;
|
|
3876
|
+
const rawBinding = touchResult?.binding;
|
|
3877
|
+
const filteredDiagnostics = diagnostics ? applyAuxiliarySuppressions(diagnostics, content, {
|
|
3878
|
+
fileRole: detectFileRole(filePath, content),
|
|
3879
|
+
filePath,
|
|
3880
|
+
scanRoot: root
|
|
3881
|
+
}) : diagnostics;
|
|
3882
|
+
results.push({
|
|
3883
|
+
filePath,
|
|
3884
|
+
diagnostics: filteredDiagnostics ?? [],
|
|
3885
|
+
count: filteredDiagnostics?.length ?? 0,
|
|
3886
|
+
...timedOut && { timedOut: true, unconfirmedReason },
|
|
3887
|
+
...coverageGap && {
|
|
3888
|
+
unconfirmedServerIds: [...unconfirmedServerIds]
|
|
3889
|
+
},
|
|
3890
|
+
contentHash: rawBinding?.contentHash,
|
|
3891
|
+
boundToCurrentDisk: rawBinding?.boundToCurrentDisk,
|
|
3892
|
+
writeIndex: writeIndexByPath.get(normalizeMapKey(filePath))
|
|
3893
|
+
});
|
|
3894
|
+
} catch (err) {
|
|
3895
|
+
results.push({
|
|
3896
|
+
filePath,
|
|
3897
|
+
diagnostics: [],
|
|
3898
|
+
count: 0,
|
|
3899
|
+
error: err instanceof Error ? err.message : String(err),
|
|
3900
|
+
timedOut: true,
|
|
3901
|
+
unconfirmedReason: "error",
|
|
3902
|
+
writeIndex: writeIndexByPath.get(normalizeMapKey(filePath))
|
|
3903
|
+
});
|
|
3904
|
+
}
|
|
3905
|
+
completed += 1;
|
|
3906
|
+
options.onProgress?.(completed, files.length);
|
|
3907
|
+
if (Date.now() - lastHeartbeat >= 1e4) {
|
|
3908
|
+
lastHeartbeat = Date.now();
|
|
3909
|
+
logLatency({
|
|
3910
|
+
type: "phase",
|
|
3911
|
+
phase: "lsp_workspace_diagnostics_progress",
|
|
3912
|
+
filePath: root,
|
|
3913
|
+
durationMs: Date.now() - startedAt,
|
|
3914
|
+
metadata: {
|
|
3915
|
+
completed,
|
|
3916
|
+
total: files.length,
|
|
3917
|
+
timedOutFiles,
|
|
3918
|
+
aborted: signal?.aborted ?? false
|
|
3919
|
+
}
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
};
|
|
3923
|
+
const groupWorkers = Math.min(WORKSPACE_DIAGNOSTICS_CONCURRENCY, groups.length);
|
|
3924
|
+
const sweepPhase = phaseStarted("lsp_workspace_diagnostics_touch");
|
|
3925
|
+
try {
|
|
3926
|
+
await runPerServerGroups(groups, groupWorkers, async (group) => {
|
|
3927
|
+
if (signal?.aborted)
|
|
3928
|
+
return;
|
|
3929
|
+
if (this.checkDestroyed()) {
|
|
3930
|
+
markServiceDestroyed(group.files);
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3933
|
+
if (!isWarmAttached() && workspacePullEnabled && !group.multiServer) {
|
|
3934
|
+
const pullStartedAt = Date.now();
|
|
3935
|
+
const pulled = await this.tryWorkspacePull(group.files, perFileMs, cacheServedKeys);
|
|
3936
|
+
if (pulled) {
|
|
3937
|
+
for (const clean of pulled.extraClean) {
|
|
3938
|
+
supersededCacheKeys.add(normalizeMapKey(clean.filePath));
|
|
3939
|
+
}
|
|
3940
|
+
for (const result of [...pulled.results, ...pulled.extraClean]) {
|
|
3941
|
+
results.push({
|
|
3942
|
+
...result,
|
|
3943
|
+
writeIndex: writeIndexByPath.get(normalizeMapKey(result.filePath))
|
|
3944
|
+
});
|
|
3945
|
+
pullAnsweredFiles.add(result.filePath);
|
|
3946
|
+
try {
|
|
3947
|
+
const pullStat = nodeFs.statSync(result.filePath);
|
|
3948
|
+
scannedMtimeByFile.set(result.filePath, pullStat.mtimeMs);
|
|
3949
|
+
scannedSizeByFile.set(result.filePath, pullStat.size);
|
|
3950
|
+
scannedAtByFile.set(result.filePath, pullStartedAt);
|
|
3951
|
+
} catch {}
|
|
3952
|
+
}
|
|
3953
|
+
completed += group.files.length;
|
|
3954
|
+
options.onProgress?.(completed, files.length);
|
|
3955
|
+
return;
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
const first = group.files[0];
|
|
3959
|
+
if (first && !isWarmAttached()) {
|
|
3960
|
+
const warmup = await this.ensureWarmForSweep(first, { signal });
|
|
3961
|
+
if (signal?.aborted)
|
|
3962
|
+
return;
|
|
3963
|
+
if (warmup.failedServerIds.length > 0) {
|
|
3964
|
+
logLatency({
|
|
3965
|
+
type: "phase",
|
|
3966
|
+
phase: "lsp_sweep_group_skipped_warmup",
|
|
3967
|
+
filePath: first,
|
|
3968
|
+
durationMs: 0,
|
|
3969
|
+
metadata: {
|
|
3970
|
+
failedServerIds: warmup.failedServerIds,
|
|
3971
|
+
skippedFromCache: warmup.skippedFromCache ?? false,
|
|
3972
|
+
skippedFiles: group.files.length
|
|
3973
|
+
}
|
|
3974
|
+
});
|
|
3975
|
+
for (const filePath of group.files) {
|
|
3976
|
+
const { disabledServerIds, fallbackServerIds } = disabledPrimaries(filePath);
|
|
3977
|
+
results.push({
|
|
3978
|
+
filePath,
|
|
3979
|
+
diagnostics: [],
|
|
3980
|
+
count: 0,
|
|
3981
|
+
timedOut: true,
|
|
3982
|
+
unconfirmedReason: SWEEP_REASON_FOR_CAUSE[primaryUnavailableCause([...warmup.failedServerIds, ...disabledServerIds], disabledServerIds, fallbackServerIds)],
|
|
3983
|
+
skippedWarmupFailure: true
|
|
3984
|
+
});
|
|
3985
|
+
timedOutFiles += 1;
|
|
3986
|
+
completed += 1;
|
|
3987
|
+
}
|
|
3988
|
+
options.onProgress?.(completed, files.length);
|
|
3989
|
+
return;
|
|
3990
|
+
}
|
|
3991
|
+
if (warmup.performedWarmup)
|
|
3992
|
+
options.onServerReady?.();
|
|
3993
|
+
}
|
|
3994
|
+
for (let chunkStart = 0;chunkStart < group.files.length; chunkStart += WORKSPACE_SWEEP_PREOPEN_CHUNK_SIZE) {
|
|
3995
|
+
if (signal?.aborted)
|
|
3996
|
+
return;
|
|
3997
|
+
if (this.checkDestroyed()) {
|
|
3998
|
+
markServiceDestroyed(group.files.slice(chunkStart));
|
|
3999
|
+
return;
|
|
4000
|
+
}
|
|
4001
|
+
const chunk = group.files.slice(chunkStart, chunkStart + WORKSPACE_SWEEP_PREOPEN_CHUNK_SIZE);
|
|
4002
|
+
await preOpenGroupFiles(chunk);
|
|
4003
|
+
for (const filePath of chunk) {
|
|
4004
|
+
if (signal?.aborted)
|
|
4005
|
+
return;
|
|
4006
|
+
if (this.checkDestroyed()) {
|
|
4007
|
+
markServiceDestroyed(group.files.slice(group.files.indexOf(filePath)));
|
|
4008
|
+
return;
|
|
4009
|
+
}
|
|
4010
|
+
await processFile(filePath);
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}, signal);
|
|
4014
|
+
} finally {
|
|
4015
|
+
phaseFinished(sweepPhase);
|
|
4016
|
+
}
|
|
4017
|
+
const unconfirmedByReason = {};
|
|
4018
|
+
for (const result of results) {
|
|
4019
|
+
if (!result.timedOut)
|
|
4020
|
+
continue;
|
|
4021
|
+
const reason = result.unconfirmedReason ?? "budget";
|
|
4022
|
+
unconfirmedByReason[reason] = (unconfirmedByReason[reason] ?? 0) + 1;
|
|
4023
|
+
}
|
|
4024
|
+
const partiallyCoveredFiles = results.filter((result) => (result.unconfirmedServerIds?.length ?? 0) > 0).length;
|
|
4025
|
+
const unconfirmedServerIds = [
|
|
4026
|
+
...new Set(results.flatMap((result) => result.unconfirmedServerIds ?? []))
|
|
4027
|
+
].sort((a, b) => Number(a > b) - Number(a < b));
|
|
4028
|
+
let pullUnbound = 0;
|
|
4029
|
+
for (const result of results) {
|
|
4030
|
+
if (pullAnsweredFiles.has(result.filePath) && result.contentHash === undefined)
|
|
4031
|
+
pullUnbound += 1;
|
|
4032
|
+
}
|
|
4033
|
+
logLatency({
|
|
4034
|
+
type: "phase",
|
|
4035
|
+
phase: "lsp_workspace_diagnostics",
|
|
4036
|
+
filePath: root,
|
|
4037
|
+
durationMs: Date.now() - startedAt,
|
|
4038
|
+
metadata: {
|
|
4039
|
+
filesChecked: files.length,
|
|
4040
|
+
cacheHits: cachedResults.length,
|
|
4041
|
+
diagnosticCount: results.reduce((sum, result) => sum + (result?.count ?? 0), 0),
|
|
4042
|
+
serverGroups: groups.length,
|
|
4043
|
+
concurrency: groupWorkers,
|
|
4044
|
+
maxFiles,
|
|
4045
|
+
timedOutFiles,
|
|
4046
|
+
unconfirmedByReason,
|
|
4047
|
+
partiallyCoveredFiles,
|
|
4048
|
+
pullUnbound,
|
|
4049
|
+
...unconfirmedServerIds.length > 0 && { unconfirmedServerIds },
|
|
4050
|
+
aborted: signal?.aborted ?? false
|
|
4051
|
+
}
|
|
4052
|
+
});
|
|
4053
|
+
for (const result of results) {
|
|
4054
|
+
const scannedAt = scannedMtimeByFile.get(result.filePath);
|
|
4055
|
+
if (result.error || result.timedOut || (result.unconfirmedServerIds?.length ?? 0) > 0 || scannedAt === undefined) {
|
|
4056
|
+
continue;
|
|
4057
|
+
}
|
|
4058
|
+
if (pullAnsweredFiles.has(result.filePath) && result.contentHash === undefined) {
|
|
4059
|
+
workspaceDiagnosticsCacheCtx.forget(result.filePath);
|
|
4060
|
+
continue;
|
|
4061
|
+
}
|
|
4062
|
+
workspaceDiagnosticsCacheCtx.record(result.filePath, workspaceSweepScopeKey, result.diagnostics, scannedAt, result.contentHash, scannedSizeByFile.get(result.filePath), scannedAtByFile.get(result.filePath));
|
|
4063
|
+
}
|
|
4064
|
+
workspaceDiagnosticsCacheCtx.persist();
|
|
4065
|
+
const servedCacheResults = supersededCacheKeys.size === 0 ? cachedResults : cachedResults.filter((result) => !supersededCacheKeys.has(normalizeMapKey(result.filePath)));
|
|
4066
|
+
const freshResults = results.map((result) => ({
|
|
4067
|
+
...result,
|
|
4068
|
+
observedAt: scannedAtByFile.get(result.filePath)
|
|
4069
|
+
}));
|
|
4070
|
+
return [...servedCacheResults, ...freshResults].filter(Boolean);
|
|
4071
|
+
}
|
|
4072
|
+
async tryWorkspacePull(groupFiles, perFileMs, reanswerFor) {
|
|
4073
|
+
try {
|
|
4074
|
+
const first = groupFiles[0];
|
|
4075
|
+
if (!first)
|
|
4076
|
+
return;
|
|
4077
|
+
const spawned = await this.getClientForFile(first, perFileMs);
|
|
4078
|
+
if (!spawned)
|
|
4079
|
+
return;
|
|
4080
|
+
if (!spawned.client.getWorkspaceDiagnosticsSupport().workspaceDiagnostics) {
|
|
4081
|
+
return;
|
|
4082
|
+
}
|
|
4083
|
+
const report = await spawned.client.requestWorkspaceDiagnostics(Math.max(perFileMs, workspacePullBudgetMs()));
|
|
4084
|
+
if (!report)
|
|
4085
|
+
return;
|
|
4086
|
+
const byPath = new Map;
|
|
4087
|
+
for (const entry of report) {
|
|
4088
|
+
byPath.set(normalizeMapKey(entry.filePath), entry);
|
|
4089
|
+
}
|
|
4090
|
+
const results = groupFiles.map((filePath) => {
|
|
4091
|
+
const entry = byPath.get(normalizeMapKey(filePath));
|
|
4092
|
+
const diagnostics = entry?.diagnostics ?? [];
|
|
4093
|
+
return {
|
|
4094
|
+
filePath,
|
|
4095
|
+
diagnostics,
|
|
4096
|
+
count: diagnostics.length,
|
|
4097
|
+
timedOut: false,
|
|
4098
|
+
contentHash: entry?.contentHash
|
|
4099
|
+
};
|
|
4100
|
+
});
|
|
4101
|
+
const extraClean = [];
|
|
4102
|
+
if (reanswerFor && reanswerFor.size > 0) {
|
|
4103
|
+
const asked = new Set(groupFiles.map((f) => normalizeMapKey(f)));
|
|
4104
|
+
const withFindings = new Set;
|
|
4105
|
+
for (const entry of report) {
|
|
4106
|
+
if (entry.diagnostics.length > 0) {
|
|
4107
|
+
withFindings.add(normalizeMapKey(entry.filePath));
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
for (const [key, entry] of byPath) {
|
|
4111
|
+
if (asked.has(key) || !reanswerFor.has(key))
|
|
4112
|
+
continue;
|
|
4113
|
+
if (entry.diagnostics.length > 0 || withFindings.has(key))
|
|
4114
|
+
continue;
|
|
4115
|
+
extraClean.push({
|
|
4116
|
+
filePath: entry.filePath,
|
|
4117
|
+
diagnostics: [],
|
|
4118
|
+
count: 0,
|
|
4119
|
+
timedOut: false,
|
|
4120
|
+
contentHash: entry.contentHash
|
|
4121
|
+
});
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
return { results, extraClean };
|
|
4125
|
+
} catch {
|
|
4126
|
+
return;
|
|
4127
|
+
}
|
|
4128
|
+
}
|
|
4129
|
+
async getAllDiagnostics(excludeServerIds) {
|
|
4130
|
+
const all = new Map;
|
|
4131
|
+
const bindingsByPath = new Map;
|
|
4132
|
+
const now = Date.now();
|
|
4133
|
+
for (const [_key, client] of this.state.clients) {
|
|
4134
|
+
const trackedPaths = client.getTrackedDiagnosticPaths();
|
|
4135
|
+
const existingPaths = new Set;
|
|
4136
|
+
await Promise.all(trackedPaths.map(async (filePath) => {
|
|
4137
|
+
try {
|
|
4138
|
+
await nodeFs.promises.access(filePath);
|
|
4139
|
+
existingPaths.add(filePath);
|
|
4140
|
+
} catch {}
|
|
4141
|
+
return true;
|
|
4142
|
+
}));
|
|
4143
|
+
client.pruneDiagnostics((filePath, ts) => !existingPaths.has(filePath) || now - ts > CASCADE_DIAGNOSTICS_TTL_MS);
|
|
4144
|
+
if (excludeServerIds?.has(client.serverId))
|
|
4145
|
+
continue;
|
|
4146
|
+
const clientDiags = client.getAllDiagnostics();
|
|
4147
|
+
for (const [filePath, entry] of clientDiags) {
|
|
4148
|
+
const attributed = attributeDiagnostics(client.serverId, entry.diags);
|
|
4149
|
+
const existing = all.get(filePath);
|
|
4150
|
+
if (existing) {
|
|
4151
|
+
existing.diags = mergeLspDiagnostics([
|
|
4152
|
+
...existing.diags,
|
|
4153
|
+
...attributed
|
|
4154
|
+
]);
|
|
4155
|
+
existing.ts = Math.max(existing.ts, entry.ts);
|
|
4156
|
+
} else {
|
|
4157
|
+
all.set(filePath, { diags: attributed, ts: entry.ts });
|
|
4158
|
+
}
|
|
4159
|
+
const list = bindingsByPath.get(filePath) ?? [];
|
|
4160
|
+
list.push(entry.binding);
|
|
4161
|
+
bindingsByPath.set(filePath, list);
|
|
4162
|
+
}
|
|
4163
|
+
}
|
|
4164
|
+
for (const [filePath, entry] of all) {
|
|
4165
|
+
const stored = bindingsByPath.get(filePath) ?? [];
|
|
4166
|
+
let memo;
|
|
4167
|
+
Object.defineProperty(entry, "binding", {
|
|
4168
|
+
enumerable: false,
|
|
4169
|
+
configurable: true,
|
|
4170
|
+
get: () => memo ??= this.mergeBinding(filePath, stored)
|
|
4171
|
+
});
|
|
4172
|
+
}
|
|
4173
|
+
return all;
|
|
4174
|
+
}
|
|
4175
|
+
supportsLSP(filePath) {
|
|
4176
|
+
return getServersForFileWithConfig(filePath).length > 0;
|
|
4177
|
+
}
|
|
4178
|
+
describeTouchCandidates(filePath, resolvedRoots, auxiliaryRoots = new Map) {
|
|
4179
|
+
const candidates = [];
|
|
4180
|
+
for (const server of getServersForFileWithConfig(filePath)) {
|
|
4181
|
+
const auxiliary = isAuxiliary(server);
|
|
4182
|
+
if (auxiliary && !auxiliaryRoots.has(server.id))
|
|
4183
|
+
continue;
|
|
4184
|
+
if (candidates.length >= MAX_TOUCH_CANDIDATES)
|
|
4185
|
+
break;
|
|
4186
|
+
const root = (auxiliary ? auxiliaryRoots : resolvedRoots).get(server.id);
|
|
4187
|
+
const key = root === undefined ? undefined : `${server.id}:${root}`;
|
|
4188
|
+
const client = key === undefined ? undefined : this.state.clients.get(key);
|
|
4189
|
+
candidates.push({
|
|
4190
|
+
serverId: server.id,
|
|
4191
|
+
rooted: root !== undefined,
|
|
4192
|
+
clientFound: client ? client.isAlive() ? "alive" : "dead" : "none",
|
|
4193
|
+
generation: key === undefined ? undefined : this.state.clientSpawnedAt.get(key)
|
|
4194
|
+
});
|
|
4195
|
+
}
|
|
4196
|
+
return candidates;
|
|
4197
|
+
}
|
|
4198
|
+
async hasWarmLSP(filePath) {
|
|
4199
|
+
const spawned = await this.getWarmClientForFile(filePath);
|
|
4200
|
+
return Boolean(spawned);
|
|
4201
|
+
}
|
|
4202
|
+
async hasLSP(filePath) {
|
|
4203
|
+
const spawned = await this.getClientForFile(filePath);
|
|
4204
|
+
return Boolean(spawned);
|
|
4205
|
+
}
|
|
4206
|
+
async shutdown(options = {}) {
|
|
4207
|
+
const resetStartedAt = Date.now();
|
|
4208
|
+
if (this.checkDestroyed())
|
|
4209
|
+
return;
|
|
4210
|
+
this.clientRegistry.markDestroyed();
|
|
4211
|
+
this.shutdownController.abort();
|
|
4212
|
+
for (const [key, token] of this.outstandingAuxNotifyWrites) {
|
|
4213
|
+
this.releaseOutstandingAuxNotifyWrite(key, token);
|
|
4214
|
+
}
|
|
4215
|
+
const aliveClients = await this.clientRegistry.shutdownClients(options);
|
|
4216
|
+
logLatency({
|
|
4217
|
+
type: "phase",
|
|
4218
|
+
phase: "lsp_service_reset",
|
|
4219
|
+
filePath: "",
|
|
4220
|
+
startedAt: new Date(resetStartedAt).toISOString(),
|
|
4221
|
+
durationMs: Date.now() - resetStartedAt,
|
|
4222
|
+
metadata: {
|
|
4223
|
+
reason: options.reason ?? null,
|
|
4224
|
+
aliveClients,
|
|
4225
|
+
fast: !!options.fast,
|
|
4226
|
+
processExiting: !!options.processExiting
|
|
4227
|
+
}
|
|
4228
|
+
});
|
|
4229
|
+
this.clientRegistry.clearAfterShutdown();
|
|
4230
|
+
this.firstContactWaits.clear();
|
|
4231
|
+
for (const [key, token] of this.outstandingAuxNotifyWrites) {
|
|
4232
|
+
this.releaseOutstandingAuxNotifyWrite(key, token);
|
|
4233
|
+
}
|
|
4234
|
+
this.notifyStallDemotions.clear();
|
|
4235
|
+
this.auxNotifyDrainLatencyEwma.clear();
|
|
4236
|
+
this.auxNotifyInflight.clear();
|
|
4237
|
+
this.documentDrift.clear();
|
|
4238
|
+
}
|
|
4239
|
+
isSpawnInFlight(filePath, resolvedRoots) {
|
|
4240
|
+
return this.clientRegistry.isSpawnInFlight(filePath, resolvedRoots);
|
|
4241
|
+
}
|
|
4242
|
+
getStatus() {
|
|
4243
|
+
return this.clientRegistry.getStatus();
|
|
4244
|
+
}
|
|
4245
|
+
getBrokenStatus() {
|
|
4246
|
+
return this.clientRegistry.getBrokenStatus();
|
|
4247
|
+
}
|
|
4248
|
+
getAliveClientCount() {
|
|
4249
|
+
return this.clientRegistry.getAliveClientCount();
|
|
4250
|
+
}
|
|
4251
|
+
getAliveServerIds() {
|
|
4252
|
+
return this.clientRegistry.getAliveServerIds();
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4255
|
+
configureLspServiceLifecycle({
|
|
4256
|
+
create: (generationHandoff) => new LSPService(generationHandoff, process.cwd()),
|
|
4257
|
+
beforeReset: (options) => {
|
|
4258
|
+
abortDeferredLspWork(`lsp service reset: ${options.reason ?? "unspecified"}`);
|
|
4259
|
+
resetLspLaunchAvailabilityGeneration();
|
|
4260
|
+
if (options.reason === "session_start") {
|
|
4261
|
+
resetClassicTsRepairGuard();
|
|
4262
|
+
}
|
|
4263
|
+
},
|
|
4264
|
+
destroy: (service, options) => service.shutdown(options)
|
|
4265
|
+
});
|
|
4266
|
+
export function getLSPService() {
|
|
4267
|
+
return getOwnedLspService();
|
|
4268
|
+
}
|
|
4269
|
+
export function peekLSPService() {
|
|
4270
|
+
return peekOwnedLspService();
|
|
4271
|
+
}
|
|
4272
|
+
export async function hasAuxiliaryLspPublishedForRoot(serverId, filePath) {
|
|
4273
|
+
return getLSPService().hasServerPublishedForFileRoot(serverId, filePath);
|
|
4274
|
+
}
|
|
4275
|
+
export async function notifyExternalFileChange(filePath, type) {
|
|
4276
|
+
return getLSPService().notifyExternalFileChange(filePath, type);
|
|
4277
|
+
}
|
|
4278
|
+
export async function resyncGitChangedFiles(changedPaths) {
|
|
4279
|
+
return getLSPService().resyncGitChangedFiles(changedPaths);
|
|
4280
|
+
}
|
|
4281
|
+
export function resetLSPService(options = {}) {
|
|
4282
|
+
if (options.reason === "session_start") {
|
|
4283
|
+
resetClassicTsRepairGuard();
|
|
4284
|
+
clearWorkspaceSweepHoldForSessionStart();
|
|
4285
|
+
}
|
|
4286
|
+
if (options.reason === "session_shutdown")
|
|
4287
|
+
emitCreatedImportScanRollupAtSessionEnd();
|
|
4288
|
+
resetOwnedLspService(options);
|
|
4289
|
+
}
|
|
4290
|
+
export function __collectWorkspaceDiagnosticFilesForTest(root, maxFiles, signal, homeDir) {
|
|
4291
|
+
return collectWorkspaceDiagnosticFiles(path.resolve(root), maxFiles ?? getMaxWorkspaceDiagnosticFiles(), signal, homeDir);
|
|
4292
|
+
}
|