pi-lens 3.8.73 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2614 -12
- package/README.md +50 -21
- package/dist/clients/actionable-warnings.js +73 -18
- package/dist/clients/agent-behavior-client.js +21 -4
- package/dist/clients/ast-grep-client.js +68 -16
- package/dist/clients/ast-grep-types.js +0 -1
- package/dist/clients/ast-grep-yaml-synth.js +37 -10
- package/dist/clients/atomic-write-staging.js +63 -0
- package/dist/clients/atomic-write.js +116 -16
- package/dist/clients/bash-file-access.js +193 -23
- package/dist/clients/biome-client.js +29 -25
- package/dist/clients/bootstrap.js +11 -2
- package/dist/clients/bounded-cache.js +34 -0
- package/dist/clients/bounded-pid-file-lock.js +192 -0
- package/dist/clients/bus-events-logger.js +5 -1
- package/dist/clients/bus-publish.js +10 -3
- package/dist/clients/cache/rule-cache.js +89 -6
- package/dist/clients/cache-manager.js +97 -9
- package/dist/clients/cache-observability.js +498 -0
- package/dist/clients/call-graph.js +460 -108
- package/dist/clients/cascade-logger.js +5 -1
- package/dist/clients/child-unref.js +85 -0
- package/dist/clients/codebase-model.js +52 -23
- package/dist/clients/collateral-test-role.js +40 -0
- package/dist/clients/complexity-client.js +6 -8
- package/dist/clients/console-guard-install.js +14 -0
- package/dist/clients/cooperative-budget.js +42 -0
- package/dist/clients/dead-code-client.js +2 -1
- package/dist/clients/debug-handles.js +206 -0
- package/dist/clients/debug-heap.js +167 -0
- package/dist/clients/degradation-ledger.js +153 -0
- package/dist/clients/dependency-checker.js +466 -63
- package/dist/clients/diagnostic-dispositions.js +83 -13
- package/dist/clients/diagnostics-publish.js +10 -3
- package/dist/clients/dispatch/auxiliary-lsp.js +34 -0
- package/dist/clients/dispatch/dispatcher.js +71 -13
- package/dist/clients/dispatch/fact-store.js +11 -0
- package/dist/clients/dispatch/facts/function-facts.js +37 -7
- package/dist/clients/dispatch/facts/import-facts.js +108 -119
- package/dist/clients/dispatch/facts/tree-sitter-facts.js +12 -12
- package/dist/clients/dispatch/facts/try-catch-facts.js +13 -0
- package/dist/clients/dispatch/indent-detect.js +35 -0
- package/dist/clients/dispatch/inline-suppressions.js +17 -8
- package/dist/clients/dispatch/integration.js +1094 -611
- package/dist/clients/dispatch/lazy.js +14 -0
- package/dist/clients/dispatch/plan.js +11 -1
- package/dist/clients/dispatch/rule-id-normalize.js +50 -0
- package/dist/clients/dispatch/rule-policy.js +135 -0
- package/dist/clients/dispatch/rules/async-noise.js +1 -0
- package/dist/clients/dispatch/rules/unsafe-boundary.js +7 -0
- package/dist/clients/dispatch/runners/ast-grep-napi.js +47 -6
- package/dist/clients/dispatch/runners/biome-check.js +5 -9
- package/dist/clients/dispatch/runners/detekt.js +3 -2
- package/dist/clients/dispatch/runners/hadolint.js +2 -1
- package/dist/clients/dispatch/runners/helm-lint.js +154 -0
- package/dist/clients/dispatch/runners/htmlhint.js +3 -2
- package/dist/clients/dispatch/runners/index.js +5 -1
- package/dist/clients/dispatch/runners/lsp.js +14 -6
- package/dist/clients/dispatch/runners/markdownlint.js +4 -9
- package/dist/clients/dispatch/runners/psscriptanalyzer.js +10 -1
- package/dist/clients/dispatch/runners/pyright.js +9 -5
- package/dist/clients/dispatch/runners/ruff.js +4 -8
- package/dist/clients/dispatch/runners/shellcheck.js +2 -3
- package/dist/clients/dispatch/runners/shfmt.js +2 -3
- package/dist/clients/dispatch/runners/spotbugs.js +2 -1
- package/dist/clients/dispatch/runners/taplo.js +2 -1
- package/dist/clients/dispatch/runners/terragrunt.js +163 -0
- package/dist/clients/dispatch/runners/tflint.js +37 -5
- package/dist/clients/dispatch/runners/tree-sitter.js +155 -166
- package/dist/clients/dispatch/runners/trivy-config.js +13 -7
- package/dist/clients/dispatch/runners/utils/lazy-installer.js +3 -0
- package/dist/clients/dispatch/runners/utils/runner-helpers.js +284 -34
- package/dist/clients/dispatch/runners/utils/spawn-outcome.js +22 -0
- package/dist/clients/dispatch/runners/yaml-rule-parser.js +5 -4
- package/dist/clients/disposition-publish.js +10 -3
- package/dist/clients/durable-store.js +97 -0
- package/dist/clients/event-loop-monitor.js +94 -3
- package/dist/clients/extension-log.js +139 -0
- package/dist/clients/extension-mode.js +73 -0
- package/dist/clients/feature-hints.js +53 -7
- package/dist/clients/file-kinds.js +143 -31
- package/dist/clients/file-role.js +18 -3
- package/dist/clients/file-utils.js +56 -34
- package/dist/clients/fix-worklog.js +14 -2
- package/dist/clients/format-events-publish.js +16 -3
- package/dist/clients/format-service.js +24 -8
- package/dist/clients/formatters-lazy.js +8 -0
- package/dist/clients/formatters.js +358 -61
- package/dist/clients/generated-artifacts.js +169 -15
- package/dist/clients/git-guard.js +681 -11
- package/dist/clients/git-tracked-ignore.js +4 -0
- package/dist/clients/go-client.js +2 -1
- package/dist/clients/govulncheck-client.js +8 -0
- package/dist/clients/grammar-source.js +12 -4
- package/dist/clients/gzip-stage-write.js +102 -0
- package/dist/clients/host-ports.js +31 -0
- package/dist/clients/installer/index.js +733 -213
- package/dist/clients/instance-reaper.js +142 -172
- package/dist/clients/jscpd-client.js +31 -54
- package/dist/clients/knip-client.js +78 -36
- package/dist/clients/language-policy.js +14 -2
- package/dist/clients/language-profile.js +72 -77
- package/dist/clients/latency-logger.js +28 -16
- package/dist/clients/lens-config.js +140 -166
- package/dist/clients/lens-engine.js +124 -21
- package/dist/clients/lens-events.js +27 -4
- package/dist/clients/lens-flag-registry.js +293 -0
- package/dist/clients/lens-map.js +96 -26
- package/dist/clients/live-bus-emitter.js +30 -0
- package/dist/clients/log-cleanup.js +8 -18
- package/dist/clients/lsp/cascade-tier.js +23 -3
- package/dist/clients/lsp/client.js +566 -57
- package/dist/clients/lsp/config.js +74 -10
- package/dist/clients/lsp/diagnostic-binding.js +86 -0
- package/dist/clients/lsp/edits.js +1012 -121
- package/dist/clients/lsp/index.js +1840 -803
- package/dist/clients/lsp/language.js +4 -1
- package/dist/clients/lsp/launch.js +40 -32
- package/dist/clients/lsp/path-utils.js +1 -1
- package/dist/clients/lsp/ruby-drive-dirs.js +83 -0
- package/dist/clients/lsp/server.js +279 -60
- package/dist/clients/lsp/workspace-diagnostics-cache.js +28 -4
- package/dist/clients/lsp-document-symbols.js +112 -0
- package/dist/clients/lsp-lazy.js +8 -0
- package/dist/clients/lsp-mutation.js +248 -0
- package/dist/clients/mcp/analyze.js +128 -36
- package/dist/clients/mcp/ipc.js +157 -24
- package/dist/clients/mcp/review.js +36 -3
- package/dist/clients/mcp/session.js +216 -8
- package/dist/clients/memory-sampler.js +115 -0
- package/dist/clients/metrics-client.js +2 -1
- package/dist/clients/metrics-history.js +2 -1
- package/dist/clients/module-report-lsp.js +5 -0
- package/dist/clients/module-report.js +267 -82
- package/dist/clients/ndjson-logger.js +334 -103
- package/dist/clients/opengrep-client.js +1 -1
- package/dist/clients/partial-edit-apply.js +120 -5
- package/dist/clients/path-keyed-map.js +76 -0
- package/dist/clients/path-utils.js +141 -5
- package/dist/clients/performance-report.js +327 -0
- package/dist/clients/pipeline.js +54 -13
- package/dist/clients/print-mode.js +21 -0
- package/dist/clients/project-changes.js +117 -4
- package/dist/clients/project-diagnostics/cache.js +3 -2
- package/dist/clients/project-diagnostics/extractors.js +26 -115
- package/dist/clients/project-diagnostics/fresh-fetch.js +149 -19
- package/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +117 -0
- package/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +37 -5
- package/dist/clients/project-diagnostics/scanner.js +268 -128
- package/dist/clients/project-lens-config.js +138 -34
- package/dist/clients/project-report.js +64 -25
- package/dist/clients/project-scale.js +8 -10
- package/dist/clients/project-snapshot-persist-worker.js +6 -0
- package/dist/clients/project-snapshot.js +767 -8
- package/dist/clients/project-trust.js +181 -0
- package/dist/clients/quiet-window.js +27 -5
- package/dist/clients/read-bridge.js +147 -0
- package/dist/clients/read-expansion.js +22 -12
- package/dist/clients/read-guard-logger.js +159 -1
- package/dist/clients/read-guard-tool-lines.js +150 -29
- package/dist/clients/read-guard.js +262 -3
- package/dist/clients/redact/secrets.js +449 -0
- package/dist/clients/resource-sampler.js +144 -39
- package/dist/clients/reverse-deps.js +48 -0
- package/dist/clients/review-graph/builder.js +2570 -326
- package/dist/clients/review-graph/git-identity.js +2 -1
- package/dist/clients/review-graph/import-resolvers.js +21 -10
- package/dist/clients/review-graph/persist-worker.js +10 -0
- package/dist/clients/review-graph/query.js +5 -0
- package/dist/clients/review-graph/shared-extraction-ir.js +90 -0
- package/dist/clients/review-graph/symbol-id.js +46 -0
- package/dist/clients/review-graph/tsconfig-paths.js +57 -6
- package/dist/clients/review-graph/workspace-modules.js +51 -3
- package/dist/clients/review-graph-logger.js +53 -0
- package/dist/clients/ruff-client.js +27 -44
- package/dist/clients/runtime-agent-end.js +111 -75
- package/dist/clients/runtime-context.js +36 -12
- package/dist/clients/runtime-coordinator.js +76 -8
- package/dist/clients/runtime-session.js +799 -137
- package/dist/clients/runtime-tool-call.js +117 -62
- package/dist/clients/runtime-tool-result.js +218 -23
- package/dist/clients/runtime-turn.js +284 -40
- package/dist/clients/rust-client.js +2 -1
- package/dist/clients/safe-spawn.js +873 -71
- package/dist/clients/security-scan-client.js +2 -1
- package/dist/clients/session-start-observability.js +15 -0
- package/dist/clients/session-state-store.js +5 -3
- package/dist/clients/sessionstart-logger.js +18 -0
- package/dist/clients/sg-runner.js +284 -159
- package/dist/clients/slow-fs.js +2 -1
- package/dist/clients/smells-rollup.js +224 -0
- package/dist/clients/source-filter.js +231 -43
- package/dist/clients/source-walker.js +66 -10
- package/dist/clients/startup-scan.js +15 -16
- package/dist/clients/startup-timing.js +9 -0
- package/dist/clients/test-runner-client.js +38 -8
- package/dist/clients/todo-scanner.js +30 -3
- package/dist/clients/tool-event.js +35 -0
- package/dist/clients/tool-policy.js +388 -39
- package/dist/clients/tool-render.js +155 -0
- package/dist/clients/tree-sitter-cache.js +153 -140
- package/dist/clients/tree-sitter-client.js +1722 -80
- package/dist/clients/tree-sitter-logger.js +64 -1
- package/dist/clients/tree-sitter-query-loader.js +117 -12
- package/dist/clients/tree-sitter-shared.js +48 -19
- package/dist/clients/tree-sitter-symbol-extractor.js +115 -11
- package/dist/clients/user-notify.js +51 -0
- package/dist/clients/vanished-instance-marker.js +57 -0
- package/dist/clients/warm-attach.js +33 -13
- package/dist/clients/widget-state.js +342 -49
- package/dist/clients/word-index-logger.js +44 -0
- package/dist/clients/word-index.js +612 -68
- package/dist/clients/workspace-topology.js +100 -7
- package/dist/index.js +65923 -47161
- package/dist/mcp/analyze-cli.js +185 -29
- package/dist/mcp/cli.js +110 -0
- package/dist/mcp/server.js +272 -50
- package/dist/tools/ast-grep-search.js +93 -27
- package/dist/tools/lens-diagnostics.js +247 -41
- package/dist/tools/lsp-diagnostics.js +153 -40
- package/dist/tools/lsp-navigation.js +51 -31
- package/dist/tools/module-report.js +9 -0
- package/dist/tools/symbol-search.js +21 -2
- package/docs/agent-guide.md +247 -0
- package/docs/agent-tools.md +21 -10
- package/docs/analysisall.md +192 -0
- package/docs/api-ports-inventory.md +165 -0
- package/docs/ast-grep_rules_catalog.md +5 -2
- package/docs/astplayground.md +3 -4
- package/docs/audit1.md +5 -5
- package/docs/durable-store-audit-1202.md +32 -0
- package/docs/environment-variables.md +197 -11
- package/docs/fable.md +27 -0
- package/docs/features.md +35 -5
- package/docs/globalconfig.md +101 -5
- package/docs/language-coverage.md +6 -5
- package/docs/lsp-capability-matrix.md +2 -2
- package/docs/mcp.md +54 -20
- package/docs/servercapabilities.md +7 -4
- package/docs/settings.md +192 -0
- package/docs/tools.md +18 -1
- package/docs/tree-sitter_rules_catalog.md +11 -31
- package/docs/usage.md +31 -0
- package/package.json +139 -138
- package/rules/ast-grep-rules/rule-tests/hardcoded-url-js-test.yml +1 -0
- package/rules/ast-grep-rules/rule-tests/hardcoded-url-test.yml +2 -0
- package/rules/ast-grep-rules/rule-tests/no-bare-except-test.yml +49 -0
- package/rules/ast-grep-rules/rule-tests/no-bare-host-path-in-win32-branch-test.yml +87 -0
- package/rules/ast-grep-rules/rule-tests/no-case-declarations-js-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-case-declarations-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-javascript-url-js-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-javascript-url-test.yml +10 -0
- package/rules/ast-grep-rules/rule-tests/no-nested-links-test.yml +11 -1
- package/rules/ast-grep-rules/rule-tests/no-raw-json-store-write-test.yml +17 -0
- package/rules/ast-grep-rules/rule-tests/no-win32-isabsolute-for-qualification-test.yml +16 -0
- package/rules/ast-grep-rules/rule-tests/strict-equality-js-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-equality-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-inequality-js-test.yml +3 -0
- package/rules/ast-grep-rules/rule-tests/strict-inequality-test.yml +4 -0
- package/rules/ast-grep-rules/rules/hardcoded-url-js.yml +22 -4
- package/rules/ast-grep-rules/rules/hardcoded-url.yml +22 -4
- package/rules/ast-grep-rules/rules/no-bare-except.yml +3 -15
- package/rules/ast-grep-rules/rules/no-bare-host-path-in-win32-branch.yml +25 -0
- package/rules/ast-grep-rules/rules/no-case-declarations-js.yml +4 -3
- package/rules/ast-grep-rules/rules/no-case-declarations.yml +4 -3
- package/rules/ast-grep-rules/rules/no-console-except-error-js.yml +10 -0
- package/rules/ast-grep-rules/rules/no-console-except-error.yml +10 -0
- package/rules/ast-grep-rules/rules/no-javascript-url-js.yml +42 -6
- package/rules/ast-grep-rules/rules/no-javascript-url.yml +42 -6
- package/rules/ast-grep-rules/rules/no-nested-links.yml +7 -0
- package/rules/ast-grep-rules/rules/no-raw-json-store-write.yml +30 -0
- package/rules/ast-grep-rules/rules/no-win32-isabsolute-for-qualification.yml +23 -0
- package/rules/ast-grep-rules/rules/strict-equality-js.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-equality.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-inequality-js.yml +14 -1
- package/rules/ast-grep-rules/rules/strict-inequality.yml +14 -1
- package/rules/tree-sitter-queries/cpp/no-memset-sensitive-data.yml +9 -3
- package/rules/tree-sitter-queries/cpp/no-scoped-lock-without-args.yml +6 -6
- package/rules/tree-sitter-queries/css/calc-spacing.yml +8 -6
- package/rules/tree-sitter-queries/go/go-mutex-copy.yml +21 -18
- package/rules/tree-sitter-queries/go/go-shared-map-write-goroutine.yml +3 -3
- package/rules/tree-sitter-queries/java/infinite-loop-java.yml +3 -3
- package/rules/tree-sitter-queries/java/junit-call-super.yml +6 -4
- package/rules/tree-sitter-queries/java/no-double-checked-locking.yml +10 -8
- package/rules/tree-sitter-queries/java/no-field-shadowing.yml +1 -1
- package/rules/tree-sitter-queries/java/prepared-statement-valid-indices.yml +2 -3
- package/rules/tree-sitter-queries/java/resources-closed.yml +2 -2
- package/rules/tree-sitter-queries/java/springboot-default-package.yml +6 -3
- package/rules/tree-sitter-queries/java/switch-fall-through.yml +6 -4
- package/rules/tree-sitter-queries/java/switch-non-case-labels.yml +4 -3
- package/rules/tree-sitter-queries/java/tests-include-assertions.yml +6 -5
- package/rules/tree-sitter-queries/javascript/switch-case-termination-js.yml +5 -8
- package/rules/tree-sitter-queries/javascript/switch-non-case-labels.yml +3 -2
- package/rules/tree-sitter-queries/kotlin/prepared-statement-indices.yml +9 -5
- package/rules/tree-sitter-queries/php/this-in-static-context.yml +5 -5
- package/rules/tree-sitter-queries/python/exit-signature-check.yml +2 -9
- package/rules/tree-sitter-queries/python/in-operator-unsupported.yml +3 -4
- package/rules/tree-sitter-queries/python/no-super-torchscript.yml +4 -8
- package/rules/tree-sitter-queries/python/notimplemented-boolean-context.yml +1 -5
- package/rules/tree-sitter-queries/python/python-empty-except.yml +1 -1
- package/rules/tree-sitter-queries/python/return-in-init.yml +0 -2
- package/rules/tree-sitter-queries/python/yield-return-outside-function.yml +0 -3
- package/rules/tree-sitter-queries/ruby/ruby-command-injection.yml +1 -12
- package/rules/tree-sitter-queries/ruby/ruby-eval.yml +1 -1
- package/rules/tree-sitter-queries/ruby/ruby-insecure-deserialization.yml +4 -4
- package/rules/tree-sitter-queries/ruby/ruby-insecure-random.yml +4 -11
- package/rules/tree-sitter-queries/ruby/ruby-open-struct.yml +1 -1
- package/rules/tree-sitter-queries/ruby/ruby-string-eval.yml +2 -3
- package/rules/tree-sitter-queries/ruby/ruby-weak-hash.yml +4 -4
- package/rules/tree-sitter-queries/rust/rust-lock-held-across-await.yml +4 -3
- package/rules/tree-sitter-queries/tsx/no-nested-links.yml +4 -6
- package/rules/tree-sitter-queries/typescript/console-statement.yml +11 -0
- package/rules/tree-sitter-queries/typescript/duplicate-function-arg.yml +4 -9
- package/rules/tree-sitter-queries/typescript/empty-switch-case.yml +13 -9
- package/rules/tree-sitter-queries/typescript/infinite-loop.yml +2 -2
- package/rules/tree-sitter-queries/typescript/mixed-async-styles.yml +10 -1
- package/rules/tree-sitter-queries/typescript/switch-case-termination.yml +5 -8
- package/rules/tree-sitter-queries/typescript/ts-insecure-random.yml +7 -10
- package/rules/tree-sitter-queries/typescript/unsafe-regex.yml +4 -2
- package/rules/typos/_typos.toml +17 -0
- package/scripts/analyze-pi-lens-logs.mjs +55 -2
- package/skills/pi-lens-write-tree-sitter-rule/SKILL.md +5 -0
- package/dist/clients/ast-grep-parser.js +0 -86
- package/dist/clients/config-enabled-shape.js +0 -39
- package/dist/clients/lsp/interactive-install.js +0 -367
- package/dist/clients/lsp/lsp-index.js +0 -10
- package/dist/clients/lsp/server-strategies.js +0 -5
- package/dist/clients/project-metadata.js +0 -690
- package/dist/clients/source-groups.js +0 -96
- package/dist/clients/types.js +0 -11
- package/docs/env_variables.md +0 -10
- package/rules/tree-sitter-queries/abap-disabled/delete-where.yml +0 -46
- package/rules/tree-sitter-queries/cpp/no-confused-move-forward.yml +0 -59
- package/rules/tree-sitter-queries/cpp/noexcept-functions.yml +0 -58
- package/rules/tree-sitter-queries/java/mockito-initialized.yml +0 -66
- package/rules/tree-sitter-queries/java/no-wait-notify-on-thread.yml +0 -58
- package/rules/tree-sitter-queries/java/short-circuit-logic.yml +0 -57
- package/rules/tree-sitter-queries/java/spring-session-attributes-setcomplete.yml +0 -75
- package/rules/tree-sitter-queries/plsql-disabled/delete-update-where.yml +0 -56
- package/rules/tree-sitter-queries/plsql-disabled/end-loop-semicolon.yml +0 -51
- package/rules/tree-sitter-queries/plsql-disabled/fetch-bulk-collect-limit.yml +0 -47
- package/rules/tree-sitter-queries/plsql-disabled/forallsave-exceptions.yml +0 -51
- package/rules/tree-sitter-queries/plsql-disabled/nchar-nvarchar2-bytes.yml +0 -54
- package/rules/tree-sitter-queries/plsql-disabled/not-null-initialization.yml +0 -59
- package/rules/tree-sitter-queries/plsql-disabled/raise-application-error-codes.yml +0 -50
- package/rules/tree-sitter-queries/typescript-disabled/ts-path-traversal.yml +0 -71
|
@@ -2,15 +2,78 @@ import * as path from "node:path";
|
|
|
2
2
|
import { isTestMode } from "./env-utils.js";
|
|
3
3
|
import { getGlobalPiLensDir } from "./file-utils.js";
|
|
4
4
|
import { createNdjsonLogger } from "./ndjson-logger.js";
|
|
5
|
+
import { getMaxLogSizeMB } from "./log-cleanup.js";
|
|
5
6
|
const TREE_SITTER_LOG_DIR = getGlobalPiLensDir();
|
|
6
7
|
const TREE_SITTER_LOG_FILE = path.join(TREE_SITTER_LOG_DIR, "tree-sitter.log");
|
|
7
|
-
const writer = createNdjsonLogger({
|
|
8
|
+
const writer = createNdjsonLogger({
|
|
9
|
+
filePath: TREE_SITTER_LOG_FILE,
|
|
10
|
+
maxBytes: getMaxLogSizeMB() * 1024 * 1024,
|
|
11
|
+
});
|
|
12
|
+
const CACHE_COUNTER_KEYS = [
|
|
13
|
+
"lookups",
|
|
14
|
+
"hits",
|
|
15
|
+
"misses",
|
|
16
|
+
"coldMisses",
|
|
17
|
+
"capacityMisses",
|
|
18
|
+
"contentChangedMisses",
|
|
19
|
+
"mtimeMisses",
|
|
20
|
+
"statFailedMisses",
|
|
21
|
+
"sets",
|
|
22
|
+
"replacements",
|
|
23
|
+
"evictions",
|
|
24
|
+
"clears",
|
|
25
|
+
"ghostHistoryDrops",
|
|
26
|
+
"parserInvocations",
|
|
27
|
+
"parserDurationMs",
|
|
28
|
+
"parserFailures",
|
|
29
|
+
];
|
|
8
30
|
export function logTreeSitter(entry) {
|
|
9
31
|
if (isTestMode()) {
|
|
10
32
|
return;
|
|
11
33
|
}
|
|
12
34
|
writer.log({ ts: new Date().toISOString(), ...entry });
|
|
13
35
|
}
|
|
36
|
+
export function logTreeSitterCacheStats(options) {
|
|
37
|
+
const delta = Object.fromEntries(CACHE_COUNTER_KEYS.map((key) => [key, options.stats[key]]));
|
|
38
|
+
logTreeSitter({
|
|
39
|
+
phase: "cache_stats",
|
|
40
|
+
filePath: options.filePath,
|
|
41
|
+
durationMs: options.durationMs,
|
|
42
|
+
metadata: {
|
|
43
|
+
scope: options.scope,
|
|
44
|
+
fileCount: options.fileCount,
|
|
45
|
+
hitRate: delta.lookups > 0 ? delta.hits / delta.lookups : null,
|
|
46
|
+
delta,
|
|
47
|
+
resident: {
|
|
48
|
+
size: options.stats.size,
|
|
49
|
+
maxSize: options.stats.maxSize,
|
|
50
|
+
totalBytes: options.stats.totalBytes,
|
|
51
|
+
totalLines: options.stats.totalLines,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The tree-sitter stack's terminal-safe diagnostic sink (#1333).
|
|
58
|
+
*
|
|
59
|
+
* pi owns the terminal, so nothing under `clients/` may `console.error`. The
|
|
60
|
+
* tree-sitter subsystem already owns `tree-sitter.log`, so its diagnostics stay
|
|
61
|
+
* there rather than moving to the generic `extension.log` — one log per
|
|
62
|
+
* subsystem, per the AGENTS.md logger invariant.
|
|
63
|
+
*
|
|
64
|
+
* `filePath` is optional because several of these fire process-wide (WASM
|
|
65
|
+
* abort, grammar fetch, rule compile) with no file in hand.
|
|
66
|
+
*/
|
|
67
|
+
export function logTreeSitterDiagnostic(entry) {
|
|
68
|
+
logTreeSitter({
|
|
69
|
+
phase: "diagnostic",
|
|
70
|
+
filePath: entry.filePath ?? "<tree-sitter>",
|
|
71
|
+
...(entry.languageId ? { languageId: entry.languageId } : {}),
|
|
72
|
+
status: entry.level ?? "error",
|
|
73
|
+
reason: entry.message,
|
|
74
|
+
metadata: { subsystem: entry.subsystem, ...(entry.metadata ?? {}) },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
14
77
|
export function getTreeSitterLogPath() {
|
|
15
78
|
return TREE_SITTER_LOG_FILE;
|
|
16
79
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Loads tree-sitter queries from YAML files in rules/tree-sitter-queries/
|
|
5
5
|
* and provides them to the TreeSitterClient.
|
|
6
6
|
*/
|
|
7
|
+
import { logTreeSitterDiagnostic } from "./tree-sitter-logger.js";
|
|
7
8
|
import * as fs from "node:fs";
|
|
8
9
|
import * as path from "node:path";
|
|
9
10
|
import { resolvePackagePath } from "./package-root.js";
|
|
@@ -15,6 +16,84 @@ export function getQueryLanguageKey(directoryName) {
|
|
|
15
16
|
? directoryName.slice(0, -"-disabled".length)
|
|
16
17
|
: directoryName;
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Languages that inherit the typescript rule set on top of their own.
|
|
21
|
+
*
|
|
22
|
+
* ONLY `tsx`: verified rule-for-rule identical on the same source parsed under
|
|
23
|
+
* both grammars (console-statement 16/16, ts-path-traversal 277/277, …), which
|
|
24
|
+
* makes sense — tsx IS typescript plus JSX. `javascript` is deliberately NOT
|
|
25
|
+
* here. It looks like it should be, and the merge existed for years, but the
|
|
26
|
+
* queries were compiled against the typescript grammar and run against
|
|
27
|
+
* javascript trees, so they matched nothing and nobody noticed. Compiled
|
|
28
|
+
* correctly they misfire: JS parameters are bare `(identifier)` where
|
|
29
|
+
* typescript has `required_parameter`, so `duplicate-function-arg` alone
|
|
30
|
+
* reports 59 phantom duplicates across 60 files. Re-enabling it needs the
|
|
31
|
+
* typescript rules validated against the javascript grammar first.
|
|
32
|
+
*/
|
|
33
|
+
const TYPESCRIPT_RULE_HEIRS = new Set(["tsx"]);
|
|
34
|
+
/**
|
|
35
|
+
* The rule-source languages whose directories make up the effective rule set
|
|
36
|
+
* for a file parsed as `languageId`. This is the SINGLE SOURCE OF TRUTH for
|
|
37
|
+
* rule-set composition: `queriesForLanguage` (selection) and
|
|
38
|
+
* `ruleFilesForLanguage` (the RuleCache fingerprint, #878) both derive from
|
|
39
|
+
* it, so the cache key can never drift from the rules the runner actually runs.
|
|
40
|
+
*/
|
|
41
|
+
export function ruleSourceLanguages(languageId) {
|
|
42
|
+
return TYPESCRIPT_RULE_HEIRS.has(languageId)
|
|
43
|
+
? [languageId, "typescript"]
|
|
44
|
+
: [languageId];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Every rule file contributing to the effective rule set for `languageId`,
|
|
48
|
+
* from BOTH the project's own `rules/tree-sitter-queries/` tree and the
|
|
49
|
+
* bundled built-ins, across every rule-source language.
|
|
50
|
+
*
|
|
51
|
+
* The dispatch runner hashes this list into the RuleCache key. Fingerprinting
|
|
52
|
+
* only the language's OWN directory missed inherited rule sets — tsx runs the
|
|
53
|
+
* typescript rules too, so editing a typescript rule never invalidated the tsx
|
|
54
|
+
* cache and stale compiled rules kept firing until the process restarted or a
|
|
55
|
+
* tsx rule happened to change (#878).
|
|
56
|
+
*/
|
|
57
|
+
export function ruleFilesForLanguage(languageId, rootDir = process.cwd()) {
|
|
58
|
+
const resolvedRoot = path.resolve(rootDir);
|
|
59
|
+
const files = new Set();
|
|
60
|
+
for (const lang of ruleSourceLanguages(languageId)) {
|
|
61
|
+
for (const dir of [
|
|
62
|
+
path.join(resolvedRoot, "rules", "tree-sitter-queries", lang),
|
|
63
|
+
resolvePackagePath(import.meta.url, "rules", "tree-sitter-queries", lang),
|
|
64
|
+
]) {
|
|
65
|
+
if (!fs.existsSync(dir))
|
|
66
|
+
continue;
|
|
67
|
+
for (const f of fs.readdirSync(dir)) {
|
|
68
|
+
if (f.endsWith(".yml"))
|
|
69
|
+
files.add(path.join(dir, f));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return [...files];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The rule set that applies to a file parsed as `languageId`, in a stable order.
|
|
77
|
+
*
|
|
78
|
+
* Excludes `<language>-disabled/` rules. `getQueriesForLanguage` filtered these
|
|
79
|
+
* for the per-edit runner, but the project scanner read the raw loader map and
|
|
80
|
+
* ran them anyway — 1,936 of a scan's 2,590 tree-sitter findings came from
|
|
81
|
+
* rules somebody had explicitly switched off.
|
|
82
|
+
*/
|
|
83
|
+
export function queriesForLanguage(queries, languageId) {
|
|
84
|
+
const enabled = (langId) => (queries.get(langId) ?? []).filter((q) => !isDisabledQueryFilePath(q.filePath));
|
|
85
|
+
return ruleSourceLanguages(languageId).flatMap((langId) => enabled(langId));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Drop a trailing ` # comment` from an unquoted YAML scalar. Quoted values keep
|
|
89
|
+
* their `#` (a message may legitimately contain one), matching YAML's rule that
|
|
90
|
+
* a comment only starts after whitespace outside quotes.
|
|
91
|
+
*/
|
|
92
|
+
function stripInlineComment(value) {
|
|
93
|
+
if (value.startsWith('"') || value.startsWith("'"))
|
|
94
|
+
return value;
|
|
95
|
+
return value.replace(/\s+#.*$/, "").trim();
|
|
96
|
+
}
|
|
18
97
|
export function isDisabledQueryFilePath(filePath) {
|
|
19
98
|
const normalized = filePath.replaceAll("\\", "/");
|
|
20
99
|
const parts = normalized.split("/").filter(Boolean);
|
|
@@ -32,20 +111,31 @@ export class TreeSitterQueryLoader {
|
|
|
32
111
|
/** Debug logging helper */
|
|
33
112
|
dbg(msg) {
|
|
34
113
|
if (this.verbose) {
|
|
35
|
-
|
|
114
|
+
// #1333: verbose gate preserved, sink moved to tree-sitter.log.
|
|
115
|
+
logTreeSitterDiagnostic({
|
|
116
|
+
subsystem: "query-loader",
|
|
117
|
+
level: "debug",
|
|
118
|
+
message: msg,
|
|
119
|
+
});
|
|
36
120
|
}
|
|
37
121
|
}
|
|
38
122
|
/**
|
|
39
|
-
* Load all queries from the rules/tree-sitter-queries directory
|
|
123
|
+
* Load all queries from the rules/tree-sitter-queries directory.
|
|
124
|
+
*
|
|
125
|
+
* Returns the in-memory memo when the same root was already loaded.
|
|
126
|
+
* `force: true` re-reads from disk even then — the memo has no notion of
|
|
127
|
+
* rule-file mtimes, so a caller that KNOWS the files changed (the dispatch
|
|
128
|
+
* runner's RuleCache-miss path: a miss means the rule-file fingerprint
|
|
129
|
+
* moved) must force, or it gets the pre-edit rules back and persists them
|
|
130
|
+
* under the fresh fingerprint (#878).
|
|
40
131
|
*/
|
|
41
|
-
async loadQueries(rootDir = process.cwd()) {
|
|
132
|
+
async loadQueries(rootDir = process.cwd(), options = {}) {
|
|
42
133
|
const resolvedRoot = path.resolve(rootDir);
|
|
43
|
-
if (this.loaded && this.loadedRoot === resolvedRoot)
|
|
134
|
+
if (!options.force && this.loaded && this.loadedRoot === resolvedRoot) {
|
|
44
135
|
return this.queries;
|
|
45
|
-
if (this.loadedRoot !== resolvedRoot) {
|
|
46
|
-
this.queries.clear();
|
|
47
|
-
this.loaded = false;
|
|
48
136
|
}
|
|
137
|
+
this.queries.clear();
|
|
138
|
+
this.loaded = false;
|
|
49
139
|
// Load from user's project rules AND package built-in rules (coexist)
|
|
50
140
|
const queryDirs = [
|
|
51
141
|
...new Set([
|
|
@@ -124,6 +214,9 @@ export class TreeSitterQueryLoader {
|
|
|
124
214
|
? String(parsed.inline_tier)
|
|
125
215
|
: undefined,
|
|
126
216
|
skip_test_files: parsed.skip_test_files === true,
|
|
217
|
+
ignore_paths: Array.isArray(parsed.ignore_paths)
|
|
218
|
+
? parsed.ignore_paths.map(String)
|
|
219
|
+
: undefined,
|
|
127
220
|
// Parse predicates if present
|
|
128
221
|
predicates: Array.isArray(parsed.predicates)
|
|
129
222
|
? parsed.predicates.map((p) => ({
|
|
@@ -161,7 +254,12 @@ export class TreeSitterQueryLoader {
|
|
|
161
254
|
const match = line.match(/^([a-z_]+):\s*(.*)$/);
|
|
162
255
|
if (match) {
|
|
163
256
|
const key = match[1];
|
|
164
|
-
|
|
257
|
+
// Strip a trailing YAML comment (` # …`) on unquoted scalars, as the
|
|
258
|
+
// array-item branch below already does. Without this, a rule written
|
|
259
|
+
// `post_filter: not_in_test_block # skip test blocks` carried the
|
|
260
|
+
// whole comment as the filter NAME, so the filter never resolved and
|
|
261
|
+
// the rule reported unfiltered matches.
|
|
262
|
+
let value = stripInlineComment(match[2].trim());
|
|
165
263
|
// Handle arrays inline: metavars: [A, B, C]
|
|
166
264
|
if (value.startsWith("[") && value.endsWith("]")) {
|
|
167
265
|
value = value
|
|
@@ -262,10 +360,17 @@ export class TreeSitterQueryLoader {
|
|
|
262
360
|
const indentMatch = line.match(/^(\s*)/);
|
|
263
361
|
const indent = indentMatch ? indentMatch[1].length : 0;
|
|
264
362
|
const trimmed = line.trim();
|
|
265
|
-
// Stop at new key
|
|
266
|
-
if (indent <= startIndent &&
|
|
267
|
-
|
|
268
|
-
|
|
363
|
+
// Stop at a new top-level key (same or less indent than the key).
|
|
364
|
+
if (indent <= startIndent && trimmed.match(/^[a-z_]+:/)) {
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
// A comment at or below the key's indent is a document-level comment
|
|
368
|
+
// that follows the block, not part of it — stop. Block-scalar content
|
|
369
|
+
// (including native tree-sitter predicate lines `#eq?`/`#match?`) is
|
|
370
|
+
// always MORE indented than the key, so those are preserved. Without
|
|
371
|
+
// this, a stray `# …` line between a `query: |` block and the next key
|
|
372
|
+
// was appended to the query and made it fail to compile (mixed-async).
|
|
373
|
+
if (trimmed.startsWith("#") && indent <= startIndent) {
|
|
269
374
|
break;
|
|
270
375
|
}
|
|
271
376
|
// Skip YAML comment lines for most keys, but preserve native
|
|
@@ -4,47 +4,82 @@
|
|
|
4
4
|
* web-tree-sitter's WASM runtime is module-level — one per process. TRANSFER_BUFFER
|
|
5
5
|
* and _ts_init are global, so every subsystem MUST share a single TreeSitterClient:
|
|
6
6
|
* separate clients race on init and corrupt the shared WASM heap. This module is
|
|
7
|
-
* that single seam — the dispatch tree-sitter runner, project scanner,
|
|
8
|
-
* review-graph, and fact providers all obtain their client here, so a
|
|
9
|
-
* one is
|
|
7
|
+
* that single seam — read expansion, the dispatch tree-sitter runner, project scanner,
|
|
8
|
+
* module-report, review-graph, and fact providers all obtain their client here, so a
|
|
9
|
+
* file parsed by one is reused by the others while its content version remains resident.
|
|
10
10
|
*
|
|
11
11
|
* Once the WASM runtime aborts (Emscripten abort()), the heap is corrupted with no
|
|
12
12
|
* in-process recovery. markTreeSitterWasmAborted() poisons the singleton so EVERY
|
|
13
13
|
* consumer skips further tree-sitter work (previously only the runner tracked this,
|
|
14
14
|
* while the other subsystems kept calling the dead runtime).
|
|
15
15
|
*/
|
|
16
|
+
import { notifyUserDegradation } from "./user-notify.js";
|
|
16
17
|
import * as path from "node:path";
|
|
17
|
-
import { TreeSitterClient } from "./tree-sitter-client.js";
|
|
18
|
+
import { TreeSitterClient, } from "./tree-sitter-client.js";
|
|
19
|
+
import { logTreeSitter } from "./tree-sitter-logger.js";
|
|
18
20
|
let _shared = null;
|
|
19
21
|
let _wasmAborted = false;
|
|
22
|
+
let _wasmAbortedAt;
|
|
20
23
|
/** The process-wide TreeSitterClient, or null once the WASM runtime has aborted. */
|
|
21
24
|
export function getSharedTreeSitterClient() {
|
|
22
25
|
if (_wasmAborted)
|
|
23
26
|
return null;
|
|
24
|
-
_shared ??= new TreeSitterClient();
|
|
27
|
+
_shared ??= new TreeSitterClient(false, markTreeSitterWasmAborted);
|
|
25
28
|
return _shared;
|
|
26
29
|
}
|
|
27
30
|
export function isTreeSitterWasmAborted() {
|
|
28
31
|
return _wasmAborted;
|
|
29
32
|
}
|
|
33
|
+
/** Machine-readable process-wide runtime health for status/reporting surfaces. */
|
|
34
|
+
export function getTreeSitterRuntimeStatus() {
|
|
35
|
+
return {
|
|
36
|
+
available: !_wasmAborted,
|
|
37
|
+
wasmAborted: _wasmAborted,
|
|
38
|
+
recovery: _wasmAborted ? "restart_required" : "not_required",
|
|
39
|
+
...(_wasmAbortedAt ? { abortedAt: _wasmAbortedAt } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
30
42
|
/**
|
|
31
43
|
* Poison the singleton after an unrecoverable Emscripten abort() — the module-level
|
|
32
44
|
* WASM heap is corrupted, so no client can be used again this process.
|
|
33
45
|
*/
|
|
34
46
|
export function markTreeSitterWasmAborted() {
|
|
47
|
+
if (_wasmAborted)
|
|
48
|
+
return;
|
|
35
49
|
_wasmAborted = true;
|
|
50
|
+
_wasmAbortedAt = new Date().toISOString();
|
|
36
51
|
_shared = null;
|
|
52
|
+
// HUMAN-audience: structural analysis is dead for the rest of the process
|
|
53
|
+
// and only a restart recovers it. Reaches the user through the HOST's
|
|
54
|
+
// render path (#1333); the machine-readable record is the logTreeSitter
|
|
55
|
+
// `runtime_abort` entry below.
|
|
56
|
+
notifyUserDegradation("pi-lens: tree-sitter WASM runtime aborted; structural analysis is disabled " +
|
|
57
|
+
"for this process. Restart the pi-lens extension/MCP server to recover.", "error");
|
|
58
|
+
logTreeSitter({
|
|
59
|
+
phase: "runtime_abort",
|
|
60
|
+
filePath: process.cwd(),
|
|
61
|
+
status: "degraded",
|
|
62
|
+
reason: "wasm_aborted_restart_required",
|
|
63
|
+
metadata: { abortedAt: _wasmAbortedAt },
|
|
64
|
+
});
|
|
37
65
|
}
|
|
38
66
|
/** Test-only: reset the singleton + abort flag. */
|
|
39
67
|
export function _resetSharedTreeSitterClientForTests() {
|
|
40
68
|
_shared = null;
|
|
41
69
|
_wasmAborted = false;
|
|
70
|
+
_wasmAbortedAt = undefined;
|
|
42
71
|
}
|
|
43
|
-
// Grammar selection by extension
|
|
44
|
-
// the
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
|
|
72
|
+
// Grammar selection by extension — the single ext→grammar-id authority. `.tsx` →
|
|
73
|
+
// the tsx grammar (parses JSX); `.jsx` → the javascript grammar. The project
|
|
74
|
+
// scanner (project-diagnostics/scanner.ts) DERIVES its map from this one and
|
|
75
|
+
// module-report (module-report.ts `tsLangForFile`, #887) resolves its
|
|
76
|
+
// extension-split kinds (jsts/cxx) through `resolveTreeSitterLanguage` below,
|
|
77
|
+
// so neither can drift: post-#877 both key `.tsx`→tsx (the old note here said the
|
|
78
|
+
// scanner mapped `.tsx`→typescript to reuse typescript queries — that stopped
|
|
79
|
+
// being true when #877 moved typescript-rule inheritance into
|
|
80
|
+
// `queriesForLanguage`). The scanner layers only java/kotlin on top, whose
|
|
81
|
+
// grammars + rule dirs exist but are not wired into a per-edit runner `appliesTo`.
|
|
82
|
+
export const EXT_TO_LANG = {
|
|
48
83
|
".ts": "typescript",
|
|
49
84
|
".mts": "typescript",
|
|
50
85
|
".cts": "typescript",
|
|
@@ -84,18 +119,12 @@ const EXT_TO_LANG = {
|
|
|
84
119
|
export function resolveTreeSitterLanguage(filePath) {
|
|
85
120
|
return EXT_TO_LANG[path.extname(filePath).toLowerCase()];
|
|
86
121
|
}
|
|
87
|
-
|
|
88
|
-
* Parse `content` for `filePath` via the shared client and return the root node,
|
|
89
|
-
* or null when the grammar is unavailable / parse fails / wasm aborted. init()
|
|
90
|
-
* lazily loads the grammar (memoized) and must run before parseFile.
|
|
91
|
-
*/
|
|
92
|
-
export async function parseTreeSitterRoot(filePath, content) {
|
|
122
|
+
export async function withTreeSitterRoot(filePath, content, consume) {
|
|
93
123
|
const languageId = resolveTreeSitterLanguage(filePath);
|
|
94
124
|
const client = getSharedTreeSitterClient();
|
|
95
125
|
if (!languageId || !client || !(await client.init()))
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
return tree ? tree.rootNode : null;
|
|
126
|
+
return { parsed: false };
|
|
127
|
+
return client.withParsedTree(filePath, languageId, content, (tree) => consume(tree.rootNode));
|
|
99
128
|
}
|
|
100
129
|
export function childrenOfType(node, type) {
|
|
101
130
|
return (node.children ?? []).filter((c) => c && c.type === type);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Symbol extraction via tree-sitter queries
|
|
3
3
|
* Extracts definitions and references from source files
|
|
4
4
|
*/
|
|
5
|
+
import { logTreeSitterDiagnostic } from "./tree-sitter-logger.js";
|
|
5
6
|
import * as path from "node:path";
|
|
6
7
|
import { loadWebTreeSitter } from "./deps/web-tree-sitter.js";
|
|
7
8
|
// Tree-sitter query patterns for symbol extraction
|
|
@@ -455,6 +456,60 @@ const SYMBOL_QUERIES = {
|
|
|
455
456
|
// the JSX-aware grammar instead of erroring under the plain TS grammar, matching
|
|
456
457
|
// symbol-extraction coverage to the grammar set we actually ship.
|
|
457
458
|
SYMBOL_QUERIES.tsx = SYMBOL_QUERIES.typescript;
|
|
459
|
+
// The javascript grammar shares TypeScript's EXECUTABLE node types
|
|
460
|
+
// (function_declaration, arrow_function, variable_declarator, class_declaration,
|
|
461
|
+
// method_definition, call_expression, member_expression, new_expression) but
|
|
462
|
+
// NOT its type-level ones: interface_declaration, type_alias_declaration and
|
|
463
|
+
// type_identifier do not exist in it, and a class name is a plain (identifier),
|
|
464
|
+
// not a (type_identifier). A query naming a missing node type fails to COMPILE
|
|
465
|
+
// outright (probed: "Bad node name 'type_identifier'"), so — unlike tsx — the
|
|
466
|
+
// TypeScript defs/refs cannot be aliased; javascript gets the same queries minus
|
|
467
|
+
// the type-only patterns. module-report resolves .js/.mjs/.cjs/.jsx to this
|
|
468
|
+
// grammar via the shared EXT_TO_LANG (#887); interface/type symbols are a
|
|
469
|
+
// TypeScript-language feature, so nothing is lost on real JS.
|
|
470
|
+
SYMBOL_QUERIES.javascript = {
|
|
471
|
+
defs: `
|
|
472
|
+
;; Function declarations: function foo(params) { }
|
|
473
|
+
(function_declaration
|
|
474
|
+
name: (identifier) @funcName
|
|
475
|
+
parameters: (formal_parameters) @funcParams
|
|
476
|
+
body: (statement_block) @funcBody) @funcDef
|
|
477
|
+
|
|
478
|
+
;; Arrow functions: const foo = (params) => { }
|
|
479
|
+
(variable_declarator
|
|
480
|
+
name: (identifier) @arrowName
|
|
481
|
+
value: (arrow_function
|
|
482
|
+
parameters: (formal_parameters) @arrowParams
|
|
483
|
+
body: (_) @arrowBody)) @arrowDef
|
|
484
|
+
|
|
485
|
+
;; Class declarations: class Foo { } — (identifier) name on this grammar.
|
|
486
|
+
(class_declaration
|
|
487
|
+
name: (identifier) @className) @classDef
|
|
488
|
+
|
|
489
|
+
;; Method definitions: class Foo { bar() { } }
|
|
490
|
+
(method_definition
|
|
491
|
+
name: (property_identifier) @methodName
|
|
492
|
+
parameters: (formal_parameters) @methodParams) @methodDef
|
|
493
|
+
`,
|
|
494
|
+
refs: `
|
|
495
|
+
;; Function/method calls: foo() or obj.bar()
|
|
496
|
+
(call_expression
|
|
497
|
+
function: (identifier) @callIdent) @callRef
|
|
498
|
+
|
|
499
|
+
(call_expression
|
|
500
|
+
function: (member_expression
|
|
501
|
+
object: (_)
|
|
502
|
+
property: (property_identifier) @callMethod)) @callMethodRef
|
|
503
|
+
|
|
504
|
+
;; New expressions: new Foo()
|
|
505
|
+
(new_expression
|
|
506
|
+
constructor: (identifier) @newIdent) @newRef
|
|
507
|
+
`,
|
|
508
|
+
};
|
|
509
|
+
/** Language keys with symbol queries; used by fixture drift guards. */
|
|
510
|
+
export function getSymbolQueryLanguages() {
|
|
511
|
+
return Object.keys(SYMBOL_QUERIES);
|
|
512
|
+
}
|
|
458
513
|
// Per-language import-source extraction (#249). Optional and independent of
|
|
459
514
|
// SYMBOL_QUERIES: a language without an entry simply yields no imports (its
|
|
460
515
|
// symbols still extract). Each query captures the import source text as
|
|
@@ -547,6 +602,10 @@ const IMPORT_QUERIES = {
|
|
|
547
602
|
(#match? @_m "^(source|\\.)$"))
|
|
548
603
|
`,
|
|
549
604
|
};
|
|
605
|
+
// import/export ... from "..." have the same (import_statement source: (string))
|
|
606
|
+
// / (export_statement source: (string)) shape on the javascript grammar
|
|
607
|
+
// (validated — compiles + captures), so the typescript query applies unchanged.
|
|
608
|
+
IMPORT_QUERIES.javascript = IMPORT_QUERIES.typescript;
|
|
550
609
|
// biome-ignore lint/suspicious/noExplicitAny: tree-sitter match type
|
|
551
610
|
function parseImportMatch(match) {
|
|
552
611
|
for (const capture of match.captures) {
|
|
@@ -575,7 +634,8 @@ export class TreeSitterSymbolExtractor {
|
|
|
575
634
|
}
|
|
576
635
|
async init() {
|
|
577
636
|
try {
|
|
578
|
-
|
|
637
|
+
if (!(await this.client.isLanguageSupported(this.languageId)))
|
|
638
|
+
return false;
|
|
579
639
|
const language = this.client.getLanguage(this.languageId);
|
|
580
640
|
if (!language)
|
|
581
641
|
return false;
|
|
@@ -597,7 +657,12 @@ export class TreeSitterSymbolExtractor {
|
|
|
597
657
|
return Boolean(this.defQuery || this.importQuery);
|
|
598
658
|
}
|
|
599
659
|
catch (err) {
|
|
600
|
-
|
|
660
|
+
this.client.reportWasmAbort(err);
|
|
661
|
+
logTreeSitterDiagnostic({
|
|
662
|
+
subsystem: "symbol-extractor",
|
|
663
|
+
languageId: this.languageId,
|
|
664
|
+
message: `Failed to init ${this.languageId}: ${err instanceof Error ? err.message : String(err)}`,
|
|
665
|
+
});
|
|
601
666
|
return false;
|
|
602
667
|
}
|
|
603
668
|
}
|
|
@@ -607,7 +672,14 @@ export class TreeSitterSymbolExtractor {
|
|
|
607
672
|
return new Query(language, src);
|
|
608
673
|
}
|
|
609
674
|
catch (err) {
|
|
610
|
-
|
|
675
|
+
if (this.client.reportWasmAbort(err))
|
|
676
|
+
throw err;
|
|
677
|
+
logTreeSitterDiagnostic({
|
|
678
|
+
subsystem: "symbol-extractor",
|
|
679
|
+
languageId: this.languageId,
|
|
680
|
+
message: `${this.languageId} ${label} query failed: ${err.message}`,
|
|
681
|
+
metadata: { query: label },
|
|
682
|
+
});
|
|
611
683
|
return null;
|
|
612
684
|
}
|
|
613
685
|
}
|
|
@@ -623,7 +695,7 @@ export class TreeSitterSymbolExtractor {
|
|
|
623
695
|
// Extract definitions (guarded — a language's defs query may have failed to
|
|
624
696
|
// compile while its imports query succeeded, or vice versa).
|
|
625
697
|
if (this.defQuery) {
|
|
626
|
-
for (const match of this.defQuery
|
|
698
|
+
for (const match of this.queryMatches(this.defQuery, tree.rootNode)) {
|
|
627
699
|
const symbol = this.parseDefMatch(match, relativePath, content);
|
|
628
700
|
if (symbol)
|
|
629
701
|
symbols.push(symbol);
|
|
@@ -631,7 +703,7 @@ export class TreeSitterSymbolExtractor {
|
|
|
631
703
|
}
|
|
632
704
|
// Extract references
|
|
633
705
|
if (this.refQuery) {
|
|
634
|
-
for (const match of this.refQuery
|
|
706
|
+
for (const match of this.queryMatches(this.refQuery, tree.rootNode)) {
|
|
635
707
|
const ref = this.parseRefMatch(match, relativePath);
|
|
636
708
|
if (ref)
|
|
637
709
|
refs.push(ref);
|
|
@@ -640,13 +712,31 @@ export class TreeSitterSymbolExtractor {
|
|
|
640
712
|
// Extract imports (optional — only for languages with an IMPORT_QUERIES entry)
|
|
641
713
|
const imports = [];
|
|
642
714
|
if (this.importQuery) {
|
|
643
|
-
for (const match of this.importQuery
|
|
715
|
+
for (const match of this.queryMatches(this.importQuery, tree.rootNode)) {
|
|
644
716
|
const ref = parseImportMatch(match);
|
|
645
717
|
if (ref)
|
|
646
718
|
imports.push(ref);
|
|
647
719
|
}
|
|
648
720
|
}
|
|
649
|
-
return {
|
|
721
|
+
return {
|
|
722
|
+
symbols,
|
|
723
|
+
refs,
|
|
724
|
+
imports,
|
|
725
|
+
coverage: {
|
|
726
|
+
definitions: this.defQuery ? "complete" : "unavailable",
|
|
727
|
+
references: this.refQuery ? "complete" : "unavailable",
|
|
728
|
+
imports: this.importQuery ? "complete" : "unavailable",
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
queryMatches(query, rootNode) {
|
|
733
|
+
try {
|
|
734
|
+
return query.matches(rootNode);
|
|
735
|
+
}
|
|
736
|
+
catch (error) {
|
|
737
|
+
this.client.reportWasmAbort(error);
|
|
738
|
+
throw error;
|
|
739
|
+
}
|
|
650
740
|
}
|
|
651
741
|
// biome-ignore lint/suspicious/noExplicitAny: Match type
|
|
652
742
|
parseDefMatch(match, filePath, content) {
|
|
@@ -934,26 +1024,40 @@ export class TreeSitterSymbolExtractor {
|
|
|
934
1024
|
parseRefMatch(match, filePath) {
|
|
935
1025
|
let name;
|
|
936
1026
|
let refNode;
|
|
1027
|
+
let referenceKind = "unknown";
|
|
937
1028
|
for (const capture of match.captures) {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1029
|
+
const captureName = String(capture.name);
|
|
1030
|
+
if (captureName.endsWith("Ident") ||
|
|
1031
|
+
captureName.endsWith("Method") ||
|
|
1032
|
+
captureName.endsWith("Field")) {
|
|
941
1033
|
name = capture.node.text;
|
|
942
1034
|
// biome-ignore lint/suspicious/noExplicitAny: Node type
|
|
943
1035
|
refNode = capture.node;
|
|
1036
|
+
if (captureName.startsWith("type"))
|
|
1037
|
+
referenceKind = "type";
|
|
1038
|
+
else if (captureName.startsWith("call") || captureName.startsWith("new")) {
|
|
1039
|
+
referenceKind = "call";
|
|
1040
|
+
}
|
|
944
1041
|
}
|
|
945
|
-
if (
|
|
1042
|
+
if (captureName.endsWith("Ref") && !refNode) {
|
|
946
1043
|
// biome-ignore lint/suspicious/noExplicitAny: Node type
|
|
947
1044
|
refNode = capture.node;
|
|
1045
|
+
if (captureName.startsWith("type"))
|
|
1046
|
+
referenceKind = "type";
|
|
1047
|
+
else if (captureName.startsWith("call") || captureName.startsWith("new")) {
|
|
1048
|
+
referenceKind = "call";
|
|
1049
|
+
}
|
|
948
1050
|
}
|
|
949
1051
|
}
|
|
950
1052
|
if (!name || !refNode)
|
|
951
1053
|
return null;
|
|
952
1054
|
return {
|
|
953
1055
|
symbolId: `${filePath}:${name}`, // Will be resolved later
|
|
1056
|
+
symbolName: name,
|
|
954
1057
|
filePath,
|
|
955
1058
|
line: refNode.startPosition.row + 1,
|
|
956
1059
|
column: refNode.startPosition.column + 1,
|
|
1060
|
+
referenceKind,
|
|
957
1061
|
};
|
|
958
1062
|
}
|
|
959
1063
|
// biome-ignore lint/suspicious/noExplicitAny: Node type
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HUMAN channel for degradations discovered deep in `clients/` (#1333).
|
|
3
|
+
*
|
|
4
|
+
* Most of what the migrated `console.*` sites emitted is LOG-audience and
|
|
5
|
+
* belongs in an ndjson sink (`clients/extension-log.ts`). A small set is
|
|
6
|
+
* genuinely user-facing — "the config file you wrote is being ignored", "this
|
|
7
|
+
* language's grammar could not be fetched, so its structural features are
|
|
8
|
+
* degraded", "the WASM runtime aborted; restart to recover". Those must reach
|
|
9
|
+
* the human through the HOST's own render path, never a raw terminal write
|
|
10
|
+
* (pi owns the terminal — see the module doc in `extension-log.ts`).
|
|
11
|
+
*
|
|
12
|
+
* `index.ts` wires a getter at extension init; modules deep in the tree call
|
|
13
|
+
* `notifyUserDegradation` without knowing anything about `ctx`. Per the
|
|
14
|
+
* #338/#798 detached-callback rule the notifier is resolved through a GETTER
|
|
15
|
+
* at delivery time — never captured once, because a session replacement
|
|
16
|
+
* invalidates the previously captured `ctx.ui`.
|
|
17
|
+
*
|
|
18
|
+
* Fail-soft by construction: with no host wired (MCP server, CLI, tests) this
|
|
19
|
+
* is a no-op and the ndjson sink remains the sole destination — the message is
|
|
20
|
+
* never lost, only un-rendered.
|
|
21
|
+
*/
|
|
22
|
+
let notifierGetter;
|
|
23
|
+
/** Called once from the extension entry with a getter over the live `ctx.ui.notify`. */
|
|
24
|
+
export function wireUserNotifier(portsOrGetter) {
|
|
25
|
+
notifierGetter =
|
|
26
|
+
typeof portsOrGetter === "function"
|
|
27
|
+
? portsOrGetter
|
|
28
|
+
: () => portsOrGetter.notify.user;
|
|
29
|
+
}
|
|
30
|
+
/** Test/teardown-only: drop the wired host. */
|
|
31
|
+
export function resetUserNotifier() {
|
|
32
|
+
notifierGetter = undefined;
|
|
33
|
+
}
|
|
34
|
+
/** True when a host render path is available (for callers that want to branch). */
|
|
35
|
+
export function hasUserNotifier() {
|
|
36
|
+
return notifierGetter !== undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Best-effort delivery of a user-facing degradation. Never throws — a stale
|
|
40
|
+
* `ctx` after a session replacement must degrade to a no-op, not break the
|
|
41
|
+
* diagnostic path that called it.
|
|
42
|
+
*/
|
|
43
|
+
export function notifyUserDegradation(message, level = "warning") {
|
|
44
|
+
try {
|
|
45
|
+
const notify = notifierGetter?.();
|
|
46
|
+
notify?.(message, level);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// The ndjson sink already holds this message; a dead host is not an error.
|
|
50
|
+
}
|
|
51
|
+
}
|