pi-lens 3.8.50 → 3.8.52
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 +113 -1
- package/dist/clients/actionable-warnings-logger.js +51 -0
- package/dist/clients/actionable-warnings.js +542 -0
- package/dist/clients/agent-behavior-client.js +119 -0
- package/dist/clients/ast-grep-client.js +391 -0
- package/dist/clients/ast-grep-parser.js +86 -0
- package/dist/clients/ast-grep-rule-manager.js +91 -0
- package/dist/clients/ast-grep-tool-logger.js +150 -0
- package/dist/clients/ast-grep-types.js +9 -0
- package/dist/clients/ast-grep-yaml-synth.js +103 -0
- package/dist/clients/bash-file-access.js +360 -0
- package/dist/clients/biome-client.js +183 -0
- package/dist/clients/bootstrap.js +40 -0
- package/dist/clients/cache/rule-cache.js +75 -0
- package/dist/clients/cache-manager.js +273 -0
- package/dist/clients/call-graph.js +325 -0
- package/dist/clients/cascade-format.js +21 -0
- package/dist/clients/cascade-logger.js +25 -0
- package/dist/clients/cascade-types.js +1 -0
- package/dist/clients/code-quality-warnings.js +189 -0
- package/dist/clients/codebase-model.js +136 -0
- package/dist/clients/complexity-client.js +676 -0
- package/dist/clients/dependency-checker.js +359 -0
- package/dist/clients/diagnostic-logger.js +87 -0
- package/dist/clients/diagnostic-tracker.js +105 -0
- package/dist/clients/dispatch/diagnostic-taxonomy.js +66 -0
- package/dist/clients/dispatch/dispatcher.js +759 -0
- package/dist/clients/dispatch/fact-provider-types.js +1 -0
- package/dist/clients/dispatch/fact-rule-runner.js +17 -0
- package/dist/clients/dispatch/fact-runner.js +19 -0
- package/dist/clients/dispatch/fact-scheduler.js +68 -0
- package/dist/clients/dispatch/fact-store.js +47 -0
- package/dist/clients/dispatch/facts/comment-facts.js +35 -0
- package/dist/clients/dispatch/facts/file-content.js +19 -0
- package/dist/clients/dispatch/facts/function-facts.js +204 -0
- package/dist/clients/dispatch/facts/import-facts.js +163 -0
- package/dist/clients/dispatch/facts/try-catch-facts.js +112 -0
- package/dist/clients/dispatch/integration.js +1092 -0
- package/dist/clients/dispatch/plan.js +295 -0
- package/dist/clients/dispatch/priorities.js +21 -0
- package/dist/clients/dispatch/rules/async-noise.js +39 -0
- package/dist/clients/dispatch/rules/async-unnecessary-wrapper.js +27 -0
- package/dist/clients/dispatch/rules/error-obscuring.js +31 -0
- package/dist/clients/dispatch/rules/error-swallowing.js +28 -0
- package/dist/clients/dispatch/rules/high-complexity.js +36 -0
- package/dist/clients/dispatch/rules/high-fan-out.js +43 -0
- package/dist/clients/dispatch/rules/missing-error-propagation.js +62 -0
- package/dist/clients/dispatch/rules/pass-through-wrappers.js +38 -0
- package/dist/clients/dispatch/rules/placeholder-comments.js +40 -0
- package/dist/clients/dispatch/rules/quality-rules.js +297 -0
- package/dist/clients/dispatch/rules/sonar-rules.js +493 -0
- package/dist/clients/dispatch/rules/unsafe-boundary.js +95 -0
- package/dist/clients/dispatch/runner-context.js +52 -0
- package/dist/clients/dispatch/runners/actionlint.js +110 -0
- package/dist/clients/dispatch/runners/ast-grep-napi.js +302 -0
- package/dist/clients/dispatch/runners/biome-check.js +120 -0
- package/dist/clients/dispatch/runners/biome.js +69 -0
- package/dist/clients/dispatch/runners/cpp-check.js +225 -0
- package/dist/clients/dispatch/runners/credo.js +71 -0
- package/dist/clients/dispatch/runners/dart-analyze.js +202 -0
- package/dist/clients/dispatch/runners/detekt.js +165 -0
- package/dist/clients/dispatch/runners/dotnet-build.js +159 -0
- package/dist/clients/dispatch/runners/elixir-check.js +136 -0
- package/dist/clients/dispatch/runners/eslint.js +126 -0
- package/dist/clients/dispatch/runners/fact-rules.js +30 -0
- package/dist/clients/dispatch/runners/fish-indent.js +69 -0
- package/dist/clients/dispatch/runners/gleam-check.js +87 -0
- package/dist/clients/dispatch/runners/go-vet.js +50 -0
- package/dist/clients/dispatch/runners/golangci-lint.js +118 -0
- package/dist/clients/dispatch/runners/hadolint.js +71 -0
- package/dist/clients/dispatch/runners/htmlhint.js +90 -0
- package/dist/clients/dispatch/runners/index.js +105 -0
- package/dist/clients/dispatch/runners/javac.js +76 -0
- package/dist/clients/dispatch/runners/ktlint.js +136 -0
- package/dist/clients/dispatch/runners/lsp.js +217 -0
- package/dist/clients/dispatch/runners/markdownlint.js +113 -0
- package/dist/clients/dispatch/runners/mypy.js +68 -0
- package/dist/clients/dispatch/runners/oxlint.js +178 -0
- package/dist/clients/dispatch/runners/php-lint.js +62 -0
- package/dist/clients/dispatch/runners/phpstan.js +73 -0
- package/dist/clients/dispatch/runners/prisma-validate.js +62 -0
- package/dist/clients/dispatch/runners/psscriptanalyzer.js +149 -0
- package/dist/clients/dispatch/runners/pyright.js +115 -0
- package/dist/clients/dispatch/runners/python-slop.js +106 -0
- package/dist/clients/dispatch/runners/rubocop.js +90 -0
- package/dist/clients/dispatch/runners/ruff.js +94 -0
- package/dist/clients/dispatch/runners/rust-clippy.js +149 -0
- package/dist/clients/dispatch/runners/semgrep.js +197 -0
- package/dist/clients/dispatch/runners/shellcheck.js +160 -0
- package/dist/clients/dispatch/runners/shfmt.js +86 -0
- package/dist/clients/dispatch/runners/spellcheck.js +111 -0
- package/dist/clients/dispatch/runners/sqlfluff.js +146 -0
- package/dist/clients/dispatch/runners/stylelint.js +116 -0
- package/dist/clients/dispatch/runners/swiftlint.js +144 -0
- package/dist/clients/dispatch/runners/taplo.js +61 -0
- package/dist/clients/dispatch/runners/tflint.js +68 -0
- package/dist/clients/dispatch/runners/tree-sitter.js +690 -0
- package/dist/clients/dispatch/runners/ts-lsp.js +109 -0
- package/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +149 -0
- package/dist/clients/dispatch/runners/utils/lazy-installer.js +38 -0
- package/dist/clients/dispatch/runners/utils/runner-helpers.js +385 -0
- package/dist/clients/dispatch/runners/utils.js +36 -0
- package/dist/clients/dispatch/runners/vale.js +105 -0
- package/dist/clients/dispatch/runners/yaml-rule-parser.js +167 -0
- package/dist/clients/dispatch/runners/yamllint.js +70 -0
- package/dist/clients/dispatch/runners/zig-check.js +87 -0
- package/dist/clients/dispatch/tool-profile.js +30 -0
- package/dist/clients/dispatch/types.js +13 -0
- package/dist/clients/dispatch/utils/format-utils.js +45 -0
- package/dist/clients/dispatch/utils/lsp-diagnostics.js +28 -0
- package/{clients/env-utils.ts → dist/clients/env-utils.js} +9 -9
- package/dist/clients/event-loop-monitor.js +56 -0
- package/dist/clients/feature-hints.js +49 -0
- package/dist/clients/file-kinds.js +401 -0
- package/dist/clients/file-role.js +102 -0
- package/dist/clients/file-time.js +155 -0
- package/dist/clients/file-utils.js +454 -0
- package/dist/clients/fix-worklog.js +87 -0
- package/dist/clients/format-service.js +184 -0
- package/dist/clients/formatters.js +917 -0
- package/dist/clients/generated-artifacts.js +146 -0
- package/dist/clients/git-guard.js +32 -0
- package/dist/clients/gitleaks-client.js +317 -0
- package/dist/clients/go-client.js +84 -0
- package/dist/clients/govulncheck-client.js +378 -0
- package/dist/clients/indent-retarget.js +84 -0
- package/dist/clients/installer/index.js +2013 -0
- package/dist/clients/jscpd-client.js +282 -0
- package/dist/clients/knip-client.js +371 -0
- package/dist/clients/language-policy.js +232 -0
- package/dist/clients/language-profile.js +329 -0
- package/dist/clients/latency-logger.js +44 -0
- package/dist/clients/lens-config.js +135 -0
- package/dist/clients/lens-engine.js +91 -0
- package/dist/clients/lens-events.js +70 -0
- package/dist/clients/log-cleanup.js +203 -0
- package/dist/clients/lsp/aggregation.js +83 -0
- package/dist/clients/lsp/client.js +1053 -0
- package/dist/clients/lsp/config.js +165 -0
- package/dist/clients/lsp/edits.js +228 -0
- package/dist/clients/lsp/index.js +1405 -0
- package/dist/clients/lsp/interactive-install.js +355 -0
- package/dist/clients/lsp/language.js +175 -0
- package/dist/clients/lsp/launch.js +755 -0
- package/{clients/lsp/lsp-index.ts → dist/clients/lsp/lsp-index.js} +1 -2
- package/dist/clients/lsp/path-utils.js +5 -0
- package/dist/clients/lsp/server-strategies.js +59 -0
- package/dist/clients/lsp/server.js +1600 -0
- package/dist/clients/mcp/analyze.js +170 -0
- package/dist/clients/mcp/host-shim.js +27 -0
- package/dist/clients/mcp/ipc.js +84 -0
- package/dist/clients/mcp/review.js +115 -0
- package/dist/clients/mcp/session.js +136 -0
- package/dist/clients/metrics-client.js +108 -0
- package/dist/clients/metrics-history.js +388 -0
- package/dist/clients/oldtext-autopatch.js +127 -0
- package/dist/clients/package-root.js +38 -0
- package/dist/clients/partial-edit-apply.js +43 -0
- package/dist/clients/path-utils.js +205 -0
- package/dist/clients/pipeline.js +835 -0
- package/dist/clients/production-readiness.js +517 -0
- package/dist/clients/project-changes.js +68 -0
- package/dist/clients/project-conventions.js +177 -0
- package/dist/clients/project-diagnostics/cache.js +51 -0
- package/dist/clients/project-diagnostics/runner-adapters/knip.js +44 -0
- package/dist/clients/project-diagnostics/scanner.js +159 -0
- package/dist/clients/project-diagnostics/types.js +1 -0
- package/dist/clients/project-metadata.js +710 -0
- package/dist/clients/project-scan-policy.js +49 -0
- package/dist/clients/project-snapshot.js +137 -0
- package/dist/clients/read-expansion.js +289 -0
- package/dist/clients/read-guard-logger.js +77 -0
- package/dist/clients/read-guard-tool-lines.js +1002 -0
- package/dist/clients/read-guard.js +875 -0
- package/dist/clients/reverse-deps.js +182 -0
- package/dist/clients/review-graph/builder.js +984 -0
- package/dist/clients/review-graph/format.js +33 -0
- package/dist/clients/review-graph/query.js +166 -0
- package/dist/clients/review-graph/service.js +44 -0
- package/dist/clients/review-graph/types.js +1 -0
- package/dist/clients/review-graph/workspace-modules.js +445 -0
- package/dist/clients/ruff-client.js +159 -0
- package/dist/clients/rules-scanner.js +118 -0
- package/dist/clients/runner-tracker.js +153 -0
- package/dist/clients/runtime-agent-end.js +227 -0
- package/dist/clients/runtime-config.js +73 -0
- package/dist/clients/runtime-context.js +42 -0
- package/dist/clients/runtime-coordinator.js +365 -0
- package/dist/clients/runtime-session.js +868 -0
- package/dist/clients/runtime-tool-result.js +509 -0
- package/dist/clients/runtime-turn.js +602 -0
- package/dist/clients/rust-client.js +83 -0
- package/dist/clients/safe-spawn.js +301 -0
- package/dist/clients/sanitize.js +291 -0
- package/dist/clients/scan-utils.js +80 -0
- package/dist/clients/search-read-registration.js +66 -0
- package/dist/clients/secrets-scanner.js +181 -0
- package/dist/clients/semgrep-config.js +157 -0
- package/dist/clients/session-state-store.js +97 -0
- package/dist/clients/session-summary.js +37 -0
- package/dist/clients/sg-runner.js +501 -0
- package/dist/clients/source-filter.js +274 -0
- package/dist/clients/source-groups.js +96 -0
- package/dist/clients/startup-scan.js +255 -0
- package/dist/clients/startup-timing.js +32 -0
- package/dist/clients/symbol-types.js +5 -0
- package/dist/clients/test-runner-client.js +766 -0
- package/dist/clients/todo-scanner.js +198 -0
- package/{clients/tool-event.ts → dist/clients/tool-event.js} +4 -9
- package/dist/clients/tool-policy.js +1856 -0
- package/dist/clients/tree-sitter-cache.js +244 -0
- package/dist/clients/tree-sitter-client.js +1235 -0
- package/dist/clients/tree-sitter-fixer.js +127 -0
- package/dist/clients/tree-sitter-logger.js +25 -0
- package/dist/clients/tree-sitter-navigator.js +269 -0
- package/dist/clients/tree-sitter-query-loader.js +428 -0
- package/{clients/tree-sitter-symbol-extractor.ts → dist/clients/tree-sitter-symbol-extractor.js} +262 -299
- package/dist/clients/ts-service.js +130 -0
- package/dist/clients/type-coverage-client.js +128 -0
- package/dist/clients/types.js +11 -0
- package/dist/clients/typescript-client.js +509 -0
- package/dist/clients/widget-state.js +533 -0
- package/dist/clients/word-index.js +250 -0
- package/dist/commands/booboo.js +1412 -0
- package/dist/i18n.js +61 -0
- package/dist/index.js +1743 -0
- package/dist/mcp/analyze-cli.js +105 -0
- package/dist/mcp/server.js +745 -0
- package/dist/mcp/worker.js +46 -0
- package/{tools → dist/tools}/ast-grep-replace.js +15 -3
- package/{tools → dist/tools}/ast-grep-search.js +17 -3
- package/dist/tools/lens-diagnostics.js +469 -0
- package/{tools → dist/tools}/lsp-navigation.js +92 -8
- package/package.json +12 -11
- package/rules/ast-grep-rules/rules/nested-ternary-js.yml +2 -0
- package/rules/ast-grep-rules/rules/nested-ternary.yml +2 -0
- package/rules/ast-grep-rules/rules/no-constant-condition-js.yml +11 -18
- package/rules/ast-grep-rules/rules/no-constant-condition.yml +11 -18
- package/rules/ast-grep-rules/rules/switch-without-default.yml +3 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/constructor-super-js.yml +2 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/constructor-super.yml +3 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/no-hardcoded-secrets-js.yml +3 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/no-hardcoded-secrets.yml +3 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/no-process-env.yml +3 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/unchecked-sync-fs-js.yml +3 -0
- package/rules/ast-grep-rules/{rules → rules-disabled}/unchecked-sync-fs.yml +3 -0
- package/rules/ast-grep-rules/slop-patterns.yml +26 -35
- package/rules/rule-catalog.json +3 -5
- package/rules/tree-sitter-queries/java/{infinite-loop.yml → infinite-loop-java.yml} +1 -1
- package/scripts/analyze-pi-lens-logs.mjs +211 -7
- package/skills/write-ast-grep-rule/SKILL.md +66 -14
- package/clients/actionable-warnings-logger.ts +0 -65
- package/clients/actionable-warnings.ts +0 -764
- package/clients/agent-behavior-client.ts +0 -164
- package/clients/ast-grep-client.ts +0 -603
- package/clients/ast-grep-parser.ts +0 -130
- package/clients/ast-grep-rule-manager.ts +0 -104
- package/clients/ast-grep-tool-logger.ts +0 -174
- package/clients/ast-grep-types.ts +0 -121
- package/clients/ast-grep-yaml-synth.ts +0 -122
- package/clients/bash-file-access.ts +0 -220
- package/clients/biome-client.ts +0 -657
- package/clients/bootstrap.ts +0 -93
- package/clients/cache/rule-cache.ts +0 -110
- package/clients/cache-manager.ts +0 -361
- package/clients/call-graph.ts +0 -444
- package/clients/cascade-format.ts +0 -27
- package/clients/cascade-logger.ts +0 -78
- package/clients/cascade-types.ts +0 -36
- package/clients/code-quality-warnings.ts +0 -313
- package/clients/codebase-model.ts +0 -194
- package/clients/complexity-client.ts +0 -922
- package/clients/dependency-checker.ts +0 -466
- package/clients/diagnostic-logger.ts +0 -151
- package/clients/diagnostic-tracker.ts +0 -163
- package/clients/dispatch/diagnostic-taxonomy.ts +0 -81
- package/clients/dispatch/dispatcher.ts +0 -985
- package/clients/dispatch/fact-provider-types.ts +0 -22
- package/clients/dispatch/fact-rule-runner.ts +0 -22
- package/clients/dispatch/fact-runner.ts +0 -28
- package/clients/dispatch/fact-scheduler.ts +0 -79
- package/clients/dispatch/fact-store.ts +0 -65
- package/clients/dispatch/facts/comment-facts.ts +0 -59
- package/clients/dispatch/facts/file-content.ts +0 -20
- package/clients/dispatch/facts/function-facts.ts +0 -256
- package/clients/dispatch/facts/import-facts.ts +0 -218
- package/clients/dispatch/facts/try-catch-facts.ts +0 -177
- package/clients/dispatch/integration.ts +0 -1326
- package/clients/dispatch/plan.ts +0 -329
- package/clients/dispatch/priorities.ts +0 -21
- package/clients/dispatch/rules/async-noise.ts +0 -50
- package/clients/dispatch/rules/async-unnecessary-wrapper.ts +0 -35
- package/clients/dispatch/rules/error-obscuring.ts +0 -40
- package/clients/dispatch/rules/error-swallowing.ts +0 -35
- package/clients/dispatch/rules/high-complexity.ts +0 -44
- package/clients/dispatch/rules/high-fan-out.ts +0 -55
- package/clients/dispatch/rules/missing-error-propagation.ts +0 -71
- package/clients/dispatch/rules/pass-through-wrappers.ts +0 -52
- package/clients/dispatch/rules/placeholder-comments.ts +0 -47
- package/clients/dispatch/rules/quality-rules.ts +0 -375
- package/clients/dispatch/rules/sonar-rules.ts +0 -508
- package/clients/dispatch/rules/unsafe-boundary.ts +0 -104
- package/clients/dispatch/runner-context.ts +0 -61
- package/clients/dispatch/runners/actionlint.ts +0 -145
- package/clients/dispatch/runners/ast-grep-napi.ts +0 -576
- package/clients/dispatch/runners/biome-check.ts +0 -166
- package/clients/dispatch/runners/biome.ts +0 -86
- package/clients/dispatch/runners/cpp-check.ts +0 -267
- package/clients/dispatch/runners/credo.ts +0 -106
- package/clients/dispatch/runners/dart-analyze.ts +0 -226
- package/clients/dispatch/runners/detekt.ts +0 -192
- package/clients/dispatch/runners/dotnet-build.ts +0 -195
- package/clients/dispatch/runners/elixir-check.ts +0 -151
- package/clients/dispatch/runners/eslint.ts +0 -177
- package/clients/dispatch/runners/fact-rules.ts +0 -44
- package/clients/dispatch/runners/fish-indent.ts +0 -83
- package/clients/dispatch/runners/gleam-check.ts +0 -108
- package/clients/dispatch/runners/go-vet.ts +0 -66
- package/clients/dispatch/runners/golangci-lint.ts +0 -175
- package/clients/dispatch/runners/hadolint.ts +0 -103
- package/clients/dispatch/runners/htmlhint.ts +0 -118
- package/clients/dispatch/runners/index.ts +0 -108
- package/clients/dispatch/runners/javac.ts +0 -99
- package/clients/dispatch/runners/ktlint.ts +0 -173
- package/clients/dispatch/runners/lsp.ts +0 -243
- package/clients/dispatch/runners/markdownlint.ts +0 -132
- package/clients/dispatch/runners/mypy.ts +0 -89
- package/clients/dispatch/runners/oxlint.ts +0 -214
- package/clients/dispatch/runners/php-lint.ts +0 -82
- package/clients/dispatch/runners/phpstan.ts +0 -113
- package/clients/dispatch/runners/prisma-validate.ts +0 -89
- package/clients/dispatch/runners/psscriptanalyzer.ts +0 -177
- package/clients/dispatch/runners/pyright.ts +0 -143
- package/clients/dispatch/runners/python-slop.ts +0 -133
- package/clients/dispatch/runners/rubocop.ts +0 -144
- package/clients/dispatch/runners/ruff.ts +0 -133
- package/clients/dispatch/runners/rust-clippy.ts +0 -204
- package/clients/dispatch/runners/semgrep.ts +0 -271
- package/clients/dispatch/runners/shellcheck.ts +0 -195
- package/clients/dispatch/runners/shfmt.ts +0 -100
- package/clients/dispatch/runners/spellcheck.ts +0 -145
- package/clients/dispatch/runners/sqlfluff.ts +0 -174
- package/clients/dispatch/runners/stylelint.ts +0 -155
- package/clients/dispatch/runners/swiftlint.ts +0 -199
- package/clients/dispatch/runners/taplo.ts +0 -93
- package/clients/dispatch/runners/tflint.ts +0 -100
- package/clients/dispatch/runners/tree-sitter.ts +0 -819
- package/clients/dispatch/runners/ts-lsp.ts +0 -136
- package/clients/dispatch/runners/utils/diagnostic-parsers.ts +0 -223
- package/clients/dispatch/runners/utils/lazy-installer.ts +0 -54
- package/clients/dispatch/runners/utils/runner-helpers.ts +0 -598
- package/clients/dispatch/runners/utils.ts +0 -58
- package/clients/dispatch/runners/vale.ts +0 -175
- package/clients/dispatch/runners/yaml-rule-parser.ts +0 -417
- package/clients/dispatch/runners/yamllint.ts +0 -92
- package/clients/dispatch/runners/zig-check.ts +0 -113
- package/clients/dispatch/tool-profile.ts +0 -40
- package/clients/dispatch/types.ts +0 -185
- package/clients/dispatch/utils/format-utils.ts +0 -56
- package/clients/dispatch/utils/lsp-diagnostics.ts +0 -42
- package/clients/feature-hints.ts +0 -79
- package/clients/file-kinds.ts +0 -467
- package/clients/file-role.ts +0 -145
- package/clients/file-time.ts +0 -208
- package/clients/file-utils.ts +0 -503
- package/clients/fix-worklog.ts +0 -121
- package/clients/format-service.ts +0 -276
- package/clients/formatters.ts +0 -1039
- package/clients/generated-artifacts.ts +0 -140
- package/clients/git-guard.ts +0 -41
- package/clients/gitleaks-client.ts +0 -363
- package/clients/go-client.ts +0 -242
- package/clients/govulncheck-client.ts +0 -476
- package/clients/indent-retarget.ts +0 -90
- package/clients/installer/index.ts +0 -2349
- package/clients/jscpd-client.ts +0 -361
- package/clients/knip-client.ts +0 -437
- package/clients/language-policy.ts +0 -263
- package/clients/language-profile.ts +0 -258
- package/clients/latency-logger.ts +0 -74
- package/clients/lens-config.ts +0 -209
- package/clients/lens-events.ts +0 -151
- package/clients/log-cleanup.ts +0 -257
- package/clients/lsp/aggregation.ts +0 -91
- package/clients/lsp/client.ts +0 -1619
- package/clients/lsp/config.ts +0 -216
- package/clients/lsp/edits.ts +0 -359
- package/clients/lsp/index.ts +0 -1653
- package/clients/lsp/interactive-install.ts +0 -424
- package/clients/lsp/language.ts +0 -223
- package/clients/lsp/launch.ts +0 -928
- package/clients/lsp/path-utils.ts +0 -12
- package/clients/lsp/server-strategies.ts +0 -81
- package/clients/lsp/server.ts +0 -2051
- package/clients/metrics-client.ts +0 -153
- package/clients/metrics-history.ts +0 -510
- package/clients/oldtext-autopatch.ts +0 -160
- package/clients/package-root.ts +0 -44
- package/clients/partial-edit-apply.ts +0 -76
- package/clients/path-utils.ts +0 -223
- package/clients/pipeline.ts +0 -1129
- package/clients/production-readiness.ts +0 -552
- package/clients/project-changes.ts +0 -112
- package/clients/project-conventions.ts +0 -215
- package/clients/project-metadata.ts +0 -809
- package/clients/project-scan-policy.ts +0 -79
- package/clients/project-snapshot.ts +0 -209
- package/clients/read-expansion.ts +0 -369
- package/clients/read-guard-logger.ts +0 -101
- package/clients/read-guard-tool-lines.ts +0 -825
- package/clients/read-guard.ts +0 -1044
- package/clients/reverse-deps.ts +0 -244
- package/clients/review-graph/builder.ts +0 -1005
- package/clients/review-graph/format.ts +0 -51
- package/clients/review-graph/query.ts +0 -162
- package/clients/review-graph/service.ts +0 -69
- package/clients/review-graph/types.ts +0 -46
- package/clients/review-graph/workspace-modules.ts +0 -497
- package/clients/ruff-client.ts +0 -511
- package/clients/rules-scanner.ts +0 -149
- package/clients/runner-tracker.ts +0 -215
- package/clients/runtime-agent-end.ts +0 -331
- package/clients/runtime-config.ts +0 -77
- package/clients/runtime-context.ts +0 -79
- package/clients/runtime-coordinator.ts +0 -463
- package/clients/runtime-session.ts +0 -894
- package/clients/runtime-tool-result.ts +0 -699
- package/clients/runtime-turn.ts +0 -732
- package/clients/rust-client.ts +0 -270
- package/clients/safe-spawn.ts +0 -343
- package/clients/sanitize.ts +0 -356
- package/clients/scan-utils.ts +0 -75
- package/clients/search-read-registration.ts +0 -89
- package/clients/secrets-scanner.ts +0 -214
- package/clients/semgrep-config.ts +0 -203
- package/clients/session-summary.ts +0 -53
- package/clients/sg-runner.ts +0 -679
- package/clients/source-filter.ts +0 -263
- package/clients/source-groups.ts +0 -140
- package/clients/startup-scan.ts +0 -150
- package/clients/subprocess-client.ts +0 -101
- package/clients/symbol-types.ts +0 -77
- package/clients/test-runner-client.ts +0 -1134
- package/clients/todo-scanner.ts +0 -243
- package/clients/tool-availability.ts +0 -250
- package/clients/tool-policy.ts +0 -2104
- package/clients/tree-sitter-cache.ts +0 -316
- package/clients/tree-sitter-client.ts +0 -1554
- package/clients/tree-sitter-fixer.ts +0 -217
- package/clients/tree-sitter-logger.ts +0 -51
- package/clients/tree-sitter-navigator.ts +0 -329
- package/clients/tree-sitter-query-loader.ts +0 -521
- package/clients/ts-service.ts +0 -154
- package/clients/type-coverage-client.ts +0 -164
- package/clients/types.ts +0 -59
- package/clients/typescript-client.ts +0 -698
- package/clients/widget-state.ts +0 -597
- package/commands/booboo.ts +0 -1714
- package/i18n.ts +0 -66
- package/index.ts +0 -2028
- package/tools/ast-dump.ts +0 -79
- package/tools/ast-grep-replace.ts +0 -233
- package/tools/ast-grep-search.ts +0 -421
- package/tools/lens-diagnostics.js +0 -194
- package/tools/lens-diagnostics.ts +0 -248
- package/tools/lsp-diagnostics.ts +0 -706
- package/tools/lsp-navigation.ts +0 -1492
- package/tools/shared.ts +0 -31
- package/tsconfig.json +0 -18
- /package/{tools → dist/tools}/ast-dump.js +0 -0
- /package/{tools → dist/tools}/lsp-diagnostics.js +0 -0
- /package/{tools → dist/tools}/shared.js +0 -0
|
@@ -1,698 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeScript Language Service Client for pi-local
|
|
3
|
-
*
|
|
4
|
-
* Uses TypeScript's in-process Language Service API for rich code intelligence.
|
|
5
|
-
* This is lighter weight than spawning tsserver and provides the same features.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as fs from "node:fs";
|
|
9
|
-
import * as path from "node:path";
|
|
10
|
-
import * as ts from "typescript";
|
|
11
|
-
import type {
|
|
12
|
-
CompletionItem,
|
|
13
|
-
Diagnostic,
|
|
14
|
-
DiagnosticSeverity,
|
|
15
|
-
FoldingRange,
|
|
16
|
-
HoverInfo,
|
|
17
|
-
Location,
|
|
18
|
-
SymbolInfo,
|
|
19
|
-
} from "./types.js";
|
|
20
|
-
|
|
21
|
-
// TypeScript file extensions
|
|
22
|
-
const TS_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx"]);
|
|
23
|
-
|
|
24
|
-
// Default compiler options when no tsconfig is found
|
|
25
|
-
/**
|
|
26
|
-
* Build default CompilerOptions through TypeScript's own config parser so that
|
|
27
|
-
* lib name → file path resolution works correctly in the Language Service.
|
|
28
|
-
* Direct assignment of `lib: ["lib.es2020.d.ts"]` doesn't work because the
|
|
29
|
-
* Language Service looks up those names relative to cwd, not the TS install dir.
|
|
30
|
-
*/
|
|
31
|
-
function buildDefaultCompilerOptions(): ts.CompilerOptions {
|
|
32
|
-
const fakeConfig = {
|
|
33
|
-
compilerOptions: {
|
|
34
|
-
target: "ES2020",
|
|
35
|
-
module: "ESNext",
|
|
36
|
-
moduleResolution: "bundler",
|
|
37
|
-
strict: true,
|
|
38
|
-
esModuleInterop: true,
|
|
39
|
-
skipLibCheck: true,
|
|
40
|
-
lib: ["es2020", "dom", "dom.iterable"],
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
44
|
-
fakeConfig,
|
|
45
|
-
ts.sys,
|
|
46
|
-
process.cwd(),
|
|
47
|
-
);
|
|
48
|
-
return { ...parsed.options, skipLibCheck: true };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const DEFAULT_COMPILER_OPTIONS: ts.CompilerOptions =
|
|
52
|
-
buildDefaultCompilerOptions();
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Walk up from startDir until we find a tsconfig.json, or hit the fs root.
|
|
56
|
-
*/
|
|
57
|
-
function findTsConfig(startDir: string): string | null {
|
|
58
|
-
let dir = startDir;
|
|
59
|
-
while (true) {
|
|
60
|
-
const candidate = path.join(dir, "tsconfig.json");
|
|
61
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
62
|
-
const parent = path.dirname(dir);
|
|
63
|
-
if (parent === dir) return null; // reached root
|
|
64
|
-
dir = parent;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Read and parse a tsconfig.json, returning merged CompilerOptions.
|
|
70
|
-
* Falls back to DEFAULT_COMPILER_OPTIONS on any error.
|
|
71
|
-
*/
|
|
72
|
-
function loadCompilerOptions(tsconfigPath: string): ts.CompilerOptions {
|
|
73
|
-
try {
|
|
74
|
-
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
75
|
-
if (configFile.error) return DEFAULT_COMPILER_OPTIONS;
|
|
76
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
77
|
-
configFile.config,
|
|
78
|
-
ts.sys,
|
|
79
|
-
path.dirname(tsconfigPath),
|
|
80
|
-
);
|
|
81
|
-
if (parsed.errors.length) return DEFAULT_COMPILER_OPTIONS;
|
|
82
|
-
// Always set skipLibCheck to avoid noise from node_modules
|
|
83
|
-
return { ...parsed.options, skipLibCheck: true };
|
|
84
|
-
} catch (err) {
|
|
85
|
-
void err;
|
|
86
|
-
return DEFAULT_COMPILER_OPTIONS;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class TypeScriptClient {
|
|
91
|
-
private fileVersions = new Map<string, number>();
|
|
92
|
-
private fileContents = new Map<string, string>();
|
|
93
|
-
private languageService: ts.LanguageService | null = null;
|
|
94
|
-
private compilerOptions: ts.CompilerOptions = DEFAULT_COMPILER_OPTIONS;
|
|
95
|
-
private lastTsconfigDir: string | null = null;
|
|
96
|
-
|
|
97
|
-
constructor() {
|
|
98
|
-
this.initialize();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Normalize file path for consistent cross-platform use
|
|
103
|
-
*/
|
|
104
|
-
normalizePath(filePath: string): string {
|
|
105
|
-
return path.resolve(filePath).replace(/\\/g, "/");
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Check if a file is a TypeScript/JavaScript file
|
|
110
|
-
*/
|
|
111
|
-
isTypeScriptFile(filePath: string): boolean {
|
|
112
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
113
|
-
return TS_EXTENSIONS.has(ext);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private initialize(): void {
|
|
117
|
-
const host: ts.LanguageServiceHost = {
|
|
118
|
-
getScriptFileNames: () => Array.from(this.fileContents.keys()),
|
|
119
|
-
getScriptVersion: (fileName: string) => {
|
|
120
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
121
|
-
return String(this.fileVersions.get(normalized) ?? 0);
|
|
122
|
-
},
|
|
123
|
-
getScriptSnapshot: (fileName: string) => {
|
|
124
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
125
|
-
const content = this.fileContents.get(normalized);
|
|
126
|
-
if (content) return ts.ScriptSnapshot.fromString(content);
|
|
127
|
-
try {
|
|
128
|
-
return ts.ScriptSnapshot.fromString(
|
|
129
|
-
fs.readFileSync(fileName, "utf-8"),
|
|
130
|
-
);
|
|
131
|
-
} catch {
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
getCurrentDirectory: () => process.cwd(),
|
|
136
|
-
getCompilationSettings: () => this.compilerOptions,
|
|
137
|
-
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
138
|
-
fileExists: (fileName) => ts.sys.fileExists(fileName),
|
|
139
|
-
readFile: (fileName) => {
|
|
140
|
-
const normalized = fileName.replace(/\\/g, "/");
|
|
141
|
-
const cached = this.fileContents.get(normalized);
|
|
142
|
-
if (cached !== undefined) return cached;
|
|
143
|
-
return ts.sys.readFile(fileName);
|
|
144
|
-
},
|
|
145
|
-
directoryExists: (dirName) => ts.sys.directoryExists(dirName),
|
|
146
|
-
getDirectories: (dir) => ts.sys.getDirectories(dir),
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
this.languageService = ts.createLanguageService(
|
|
150
|
-
host,
|
|
151
|
-
ts.createDocumentRegistry(),
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Detect tsconfig for the given file and refresh compilerOptions if the
|
|
157
|
-
* project root changed (avoids redundant re-parses across edits to the same project).
|
|
158
|
-
*/
|
|
159
|
-
private refreshCompilerOptions(filePath: string): void {
|
|
160
|
-
const dir = path.dirname(path.resolve(filePath));
|
|
161
|
-
const tsconfigPath = findTsConfig(dir);
|
|
162
|
-
const key = tsconfigPath ?? dir;
|
|
163
|
-
if (key === this.lastTsconfigDir) return; // same project, no change
|
|
164
|
-
this.lastTsconfigDir = key;
|
|
165
|
-
this.compilerOptions = tsconfigPath
|
|
166
|
-
? loadCompilerOptions(tsconfigPath)
|
|
167
|
-
: DEFAULT_COMPILER_OPTIONS;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Add a file to the language service
|
|
172
|
-
*/
|
|
173
|
-
addFile(filePath: string, content: string): void {
|
|
174
|
-
const normalized = this.normalizePath(filePath);
|
|
175
|
-
this.fileContents.set(normalized, content);
|
|
176
|
-
this.fileVersions.set(
|
|
177
|
-
normalized,
|
|
178
|
-
(this.fileVersions.get(normalized) || 0) + 1,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Update a file's content — also refreshes compilerOptions if project changed
|
|
184
|
-
*/
|
|
185
|
-
updateFile(filePath: string, content: string): void {
|
|
186
|
-
this.refreshCompilerOptions(filePath);
|
|
187
|
-
const normalized = this.normalizePath(filePath);
|
|
188
|
-
this.fileVersions.set(
|
|
189
|
-
normalized,
|
|
190
|
-
(this.fileVersions.get(normalized) ?? 0) + 1,
|
|
191
|
-
);
|
|
192
|
-
this.fileContents.set(normalized, content);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Ensure a file is loaded from disk (refreshes cache)
|
|
197
|
-
*/
|
|
198
|
-
ensureFile(filePath: string): void {
|
|
199
|
-
const normalized = this.normalizePath(filePath);
|
|
200
|
-
try {
|
|
201
|
-
const diskContent = fs.readFileSync(filePath, "utf-8");
|
|
202
|
-
const cachedContent = this.fileContents.get(normalized);
|
|
203
|
-
if (cachedContent !== diskContent) {
|
|
204
|
-
this.updateFile(filePath, diskContent);
|
|
205
|
-
}
|
|
206
|
-
} catch (err) {
|
|
207
|
-
void err;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Get all tracked files
|
|
213
|
-
*/
|
|
214
|
-
getTrackedFiles(): string[] {
|
|
215
|
-
return Array.from(this.fileContents.keys());
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Convert line/character to position offset
|
|
220
|
-
*/
|
|
221
|
-
lineCharToPosition(content: string, line: number, character: number): number {
|
|
222
|
-
const lines = content.split("\n");
|
|
223
|
-
let position = 0;
|
|
224
|
-
for (let i = 0; i < Math.min(line, lines.length); i++) {
|
|
225
|
-
position += lines[i].length + 1;
|
|
226
|
-
}
|
|
227
|
-
return position + character;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get diagnostics (errors and warnings) for a file
|
|
232
|
-
*/
|
|
233
|
-
getDiagnostics(filePath: string): Diagnostic[] {
|
|
234
|
-
this.refreshCompilerOptions(filePath);
|
|
235
|
-
const normalized = this.normalizePath(filePath);
|
|
236
|
-
this.ensureFile(filePath);
|
|
237
|
-
if (!this.languageService) return [];
|
|
238
|
-
|
|
239
|
-
const syntactic = this.languageService.getSyntacticDiagnostics(normalized);
|
|
240
|
-
const semantic = this.languageService.getSemanticDiagnostics(normalized);
|
|
241
|
-
|
|
242
|
-
return (
|
|
243
|
-
[...syntactic, ...semantic]
|
|
244
|
-
.filter((diag) => diag.file && diag.start !== undefined)
|
|
245
|
-
// Filter cross-file "redeclare" noise — happens when non-module scripts
|
|
246
|
-
// share global scope across multiple tracked files (TS2300, TS2451)
|
|
247
|
-
.filter((diag) => {
|
|
248
|
-
if (diag.code !== 2300 && diag.code !== 2451) return true;
|
|
249
|
-
// Only keep if the related information points back to the same file
|
|
250
|
-
const related = diag.relatedInformation ?? [];
|
|
251
|
-
return related.every(
|
|
252
|
-
(r) =>
|
|
253
|
-
!r.file || this.normalizePath(r.file.fileName) === normalized,
|
|
254
|
-
);
|
|
255
|
-
})
|
|
256
|
-
.map((diag) => {
|
|
257
|
-
const startPos = diag.file?.getLineAndCharacterOfPosition(
|
|
258
|
-
diag.start!,
|
|
259
|
-
)!;
|
|
260
|
-
const endPos = diag.file?.getLineAndCharacterOfPosition(
|
|
261
|
-
diag.start! + diag.length!,
|
|
262
|
-
)!;
|
|
263
|
-
return {
|
|
264
|
-
range: {
|
|
265
|
-
start: { line: startPos.line, character: startPos.character },
|
|
266
|
-
end: { line: endPos.line, character: endPos.character },
|
|
267
|
-
},
|
|
268
|
-
severity: (diag.category === ts.DiagnosticCategory.Error
|
|
269
|
-
? 1
|
|
270
|
-
: 2) as DiagnosticSeverity,
|
|
271
|
-
code: diag.code,
|
|
272
|
-
message: ts.flattenDiagnosticMessageText(diag.messageText, "\n"),
|
|
273
|
-
source: "typescript",
|
|
274
|
-
};
|
|
275
|
-
})
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Get hover information at a position
|
|
281
|
-
*/
|
|
282
|
-
getHover(
|
|
283
|
-
filePath: string,
|
|
284
|
-
line: number,
|
|
285
|
-
character: number,
|
|
286
|
-
): HoverInfo | null {
|
|
287
|
-
const resolved = this.resolvePosition(filePath, line, character);
|
|
288
|
-
if (!resolved) return null;
|
|
289
|
-
const { normalized, position, ls } = resolved;
|
|
290
|
-
const info = ls.getQuickInfoAtPosition(normalized, position);
|
|
291
|
-
if (!info) return null;
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
type: ts.displayPartsToString(info.displayParts),
|
|
295
|
-
documentation: info.documentation
|
|
296
|
-
? ts.displayPartsToString(info.documentation)
|
|
297
|
-
: undefined,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Shared preamble for position-based LSP queries.
|
|
303
|
-
* Returns null if prerequisites are not met.
|
|
304
|
-
*/
|
|
305
|
-
private resolvePosition(
|
|
306
|
-
filePath: string,
|
|
307
|
-
line: number,
|
|
308
|
-
character: number,
|
|
309
|
-
): {
|
|
310
|
-
normalized: string;
|
|
311
|
-
position: number;
|
|
312
|
-
ls: import("typescript").LanguageService;
|
|
313
|
-
} | null {
|
|
314
|
-
const normalized = this.normalizePath(filePath);
|
|
315
|
-
this.ensureFile(filePath);
|
|
316
|
-
if (!this.languageService) return null;
|
|
317
|
-
const content = this.fileContents.get(normalized);
|
|
318
|
-
if (!content) return null;
|
|
319
|
-
return {
|
|
320
|
-
normalized,
|
|
321
|
-
position: this.lineCharToPosition(content, line, character),
|
|
322
|
-
ls: this.languageService,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
private withPosition<T>(
|
|
327
|
-
filePath: string,
|
|
328
|
-
line: number,
|
|
329
|
-
character: number,
|
|
330
|
-
cb: (
|
|
331
|
-
normalized: string,
|
|
332
|
-
position: number,
|
|
333
|
-
ls: ts.LanguageService,
|
|
334
|
-
) => T | undefined,
|
|
335
|
-
): T | [] {
|
|
336
|
-
const resolved = this.resolvePosition(filePath, line, character);
|
|
337
|
-
if (!resolved) return [];
|
|
338
|
-
const { normalized, position, ls } = resolved;
|
|
339
|
-
return cb(normalized, position, ls) ?? [];
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Go to definition
|
|
344
|
-
*/
|
|
345
|
-
getDefinition(filePath: string, line: number, character: number): Location[] {
|
|
346
|
-
return this.withPosition(
|
|
347
|
-
filePath,
|
|
348
|
-
line,
|
|
349
|
-
character,
|
|
350
|
-
(normalized, position, ls) => {
|
|
351
|
-
const definitions = ls.getDefinitionAtPosition(normalized, position);
|
|
352
|
-
if (!definitions) return undefined;
|
|
353
|
-
|
|
354
|
-
return definitions.map((def) => {
|
|
355
|
-
if (def.textSpan) {
|
|
356
|
-
const defFile = def.fileName || normalized;
|
|
357
|
-
const defContent = this.fileContents.get(defFile) || "";
|
|
358
|
-
if (defContent) {
|
|
359
|
-
const lines = defContent
|
|
360
|
-
.substring(0, def.textSpan.start)
|
|
361
|
-
.split("\n");
|
|
362
|
-
return {
|
|
363
|
-
file: defFile,
|
|
364
|
-
line: lines.length - 1,
|
|
365
|
-
character: lines[lines.length - 1].length,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return { file: def.fileName, line: 0, character: 0 };
|
|
370
|
-
});
|
|
371
|
-
},
|
|
372
|
-
) as Location[];
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Get type definition
|
|
377
|
-
*/
|
|
378
|
-
getTypeDefinition(
|
|
379
|
-
filePath: string,
|
|
380
|
-
line: number,
|
|
381
|
-
character: number,
|
|
382
|
-
): Location[] {
|
|
383
|
-
return this.withPosition(
|
|
384
|
-
filePath,
|
|
385
|
-
line,
|
|
386
|
-
character,
|
|
387
|
-
(normalized, position, ls) => {
|
|
388
|
-
const defs = ls.getTypeDefinitionAtPosition(normalized, position);
|
|
389
|
-
if (!defs) return undefined;
|
|
390
|
-
return this.toLocations(defs, normalized);
|
|
391
|
-
},
|
|
392
|
-
) as Location[];
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Find references
|
|
397
|
-
*/
|
|
398
|
-
getReferences(filePath: string, line: number, character: number): Location[] {
|
|
399
|
-
return this.withPosition(
|
|
400
|
-
filePath,
|
|
401
|
-
line,
|
|
402
|
-
character,
|
|
403
|
-
(normalized, position, ls) => {
|
|
404
|
-
const references = ls.getReferencesAtPosition(normalized, position);
|
|
405
|
-
if (!references) return undefined;
|
|
406
|
-
return this.toLocations(references);
|
|
407
|
-
},
|
|
408
|
-
) as Location[];
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/** Map TS definition/reference entries to Location objects. */
|
|
412
|
-
private toLocations(
|
|
413
|
-
entries: ReadonlyArray<{ fileName: string }>,
|
|
414
|
-
fallbackFile?: string,
|
|
415
|
-
): Location[] {
|
|
416
|
-
return entries.map((e) => ({
|
|
417
|
-
file: e.fileName || fallbackFile || "",
|
|
418
|
-
line: 0,
|
|
419
|
-
character: 0,
|
|
420
|
-
}));
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Shared preamble for tree-based LSP queries (symbols, folding).
|
|
425
|
-
*/
|
|
426
|
-
private resolveTree(
|
|
427
|
-
filePath: string,
|
|
428
|
-
): { normalized: string; tree: import("typescript").NavigationTree } | null {
|
|
429
|
-
const normalized = this.normalizePath(filePath);
|
|
430
|
-
this.ensureFile(filePath);
|
|
431
|
-
if (!this.languageService) return null;
|
|
432
|
-
const tree = this.languageService.getNavigationTree(normalized);
|
|
433
|
-
if (!tree) return null;
|
|
434
|
-
return { normalized, tree };
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Get document symbols
|
|
439
|
-
*/
|
|
440
|
-
getSymbols(filePath: string): SymbolInfo[] {
|
|
441
|
-
const resolved = this.resolveTree(filePath);
|
|
442
|
-
if (!resolved) return [];
|
|
443
|
-
const { tree } = resolved;
|
|
444
|
-
|
|
445
|
-
const symbols: SymbolInfo[] = [];
|
|
446
|
-
|
|
447
|
-
const extract = (node: any, container?: string) => {
|
|
448
|
-
if (node.span) {
|
|
449
|
-
symbols.push({
|
|
450
|
-
name: node.text,
|
|
451
|
-
kind: this.symbolKind(node.kind),
|
|
452
|
-
line: 0,
|
|
453
|
-
containerName: container,
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
if (node.childItems) {
|
|
457
|
-
for (const child of node.childItems) {
|
|
458
|
-
extract(child, node.text);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
extract(tree);
|
|
464
|
-
return symbols;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Get completions at a position
|
|
469
|
-
*/
|
|
470
|
-
getCompletions(
|
|
471
|
-
filePath: string,
|
|
472
|
-
line: number,
|
|
473
|
-
character: number,
|
|
474
|
-
): CompletionItem[] {
|
|
475
|
-
return this.withPosition(
|
|
476
|
-
filePath,
|
|
477
|
-
line,
|
|
478
|
-
character,
|
|
479
|
-
(normalized, position, ls) => {
|
|
480
|
-
const completions = ls.getCompletionsAtPosition(
|
|
481
|
-
normalized,
|
|
482
|
-
position,
|
|
483
|
-
{},
|
|
484
|
-
);
|
|
485
|
-
if (!completions) return undefined;
|
|
486
|
-
return completions.entries.slice(0, 50).map((entry) => ({
|
|
487
|
-
name: entry.name,
|
|
488
|
-
kind: this.completionKind(entry.kind),
|
|
489
|
-
sortText: entry.sortText,
|
|
490
|
-
}));
|
|
491
|
-
},
|
|
492
|
-
) as CompletionItem[];
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Go to implementation
|
|
497
|
-
*/
|
|
498
|
-
getImplementation(
|
|
499
|
-
filePath: string,
|
|
500
|
-
line: number,
|
|
501
|
-
character: number,
|
|
502
|
-
): Location[] {
|
|
503
|
-
return this.withPosition(
|
|
504
|
-
filePath,
|
|
505
|
-
line,
|
|
506
|
-
character,
|
|
507
|
-
(normalized, position, ls) => {
|
|
508
|
-
const implementations = ls.getImplementationAtPosition(
|
|
509
|
-
normalized,
|
|
510
|
-
position,
|
|
511
|
-
);
|
|
512
|
-
if (!implementations) return undefined;
|
|
513
|
-
return this.toLocations(implementations);
|
|
514
|
-
},
|
|
515
|
-
) as Location[];
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Get folding ranges
|
|
520
|
-
*/
|
|
521
|
-
getFoldingRanges(filePath: string): FoldingRange[] {
|
|
522
|
-
const resolved = this.resolveTree(filePath);
|
|
523
|
-
if (!resolved) return [];
|
|
524
|
-
const { tree } = resolved;
|
|
525
|
-
|
|
526
|
-
const ranges: FoldingRange[] = [];
|
|
527
|
-
|
|
528
|
-
const findFolds = (node: any) => {
|
|
529
|
-
if (!node?.span) return;
|
|
530
|
-
|
|
531
|
-
if (node.kind === "function" || node.kind === "class") {
|
|
532
|
-
ranges.push({
|
|
533
|
-
startLine: 0,
|
|
534
|
-
endLine: 0,
|
|
535
|
-
kind: node.kind,
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
if (node.childItems) {
|
|
540
|
-
for (const child of node.childItems) {
|
|
541
|
-
findFolds(child);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
findFolds(tree);
|
|
547
|
-
return ranges;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Explain an error at a specific line
|
|
552
|
-
*/
|
|
553
|
-
explainError(
|
|
554
|
-
filePath: string,
|
|
555
|
-
line: number,
|
|
556
|
-
): { message: string; code?: number } | null {
|
|
557
|
-
const diagnostics = this.getDiagnostics(filePath);
|
|
558
|
-
const errorAtLine = diagnostics.find(
|
|
559
|
-
(d) => d.range.start.line === line && d.severity === 1,
|
|
560
|
-
);
|
|
561
|
-
if (!errorAtLine) return null;
|
|
562
|
-
return { message: errorAtLine.message, code: errorAtLine.code as number };
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Get quick fixes (code actions) for a diagnostic at a position.
|
|
567
|
-
* Returns array of fix descriptions with their edit changes.
|
|
568
|
-
*/
|
|
569
|
-
getCodeFixes(
|
|
570
|
-
filePath: string,
|
|
571
|
-
line: number,
|
|
572
|
-
character: number,
|
|
573
|
-
errorCodes: number[],
|
|
574
|
-
): Array<{
|
|
575
|
-
description: string;
|
|
576
|
-
changes: Array<{
|
|
577
|
-
fileName: string;
|
|
578
|
-
textChanges: ReadonlyArray<{
|
|
579
|
-
span: { start: number; length: number };
|
|
580
|
-
newText: string;
|
|
581
|
-
}>;
|
|
582
|
-
}>;
|
|
583
|
-
}> {
|
|
584
|
-
const resolved = this.resolvePosition(filePath, line, character);
|
|
585
|
-
if (!resolved) return [];
|
|
586
|
-
const { normalized, position, ls } = resolved;
|
|
587
|
-
|
|
588
|
-
const formatOpts: ts.FormatCodeSettings = {
|
|
589
|
-
indentSize: 2,
|
|
590
|
-
tabSize: 2,
|
|
591
|
-
newLineCharacter: "\n",
|
|
592
|
-
convertTabsToSpaces: true,
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
const fixes = ls.getCodeFixesAtPosition(
|
|
596
|
-
normalized,
|
|
597
|
-
position,
|
|
598
|
-
position,
|
|
599
|
-
errorCodes,
|
|
600
|
-
formatOpts,
|
|
601
|
-
{}, // preferences
|
|
602
|
-
);
|
|
603
|
-
|
|
604
|
-
if (!fixes) return [];
|
|
605
|
-
|
|
606
|
-
return fixes.map((fix) => ({
|
|
607
|
-
description: fix.description,
|
|
608
|
-
changes:
|
|
609
|
-
fix.changes?.map((change) => ({
|
|
610
|
-
fileName: change.fileName,
|
|
611
|
-
textChanges: change.textChanges,
|
|
612
|
-
})) || [],
|
|
613
|
-
}));
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Get all quick fixes for all diagnostics in a file.
|
|
618
|
-
* Returns a map of diagnostic line → fixes.
|
|
619
|
-
*/
|
|
620
|
-
/**
|
|
621
|
-
* Accept pre-computed diagnostics to avoid a second getSemanticDiagnostics call
|
|
622
|
-
* when the caller already has them (saves ~1–2s on large files).
|
|
623
|
-
*/
|
|
624
|
-
getAllCodeFixes(
|
|
625
|
-
filePath: string,
|
|
626
|
-
precomputedDiags?: Diagnostic[],
|
|
627
|
-
): Map<
|
|
628
|
-
number,
|
|
629
|
-
Array<{
|
|
630
|
-
description: string;
|
|
631
|
-
changes: Array<{
|
|
632
|
-
fileName: string;
|
|
633
|
-
textChanges: ReadonlyArray<{
|
|
634
|
-
span: { start: number; length: number };
|
|
635
|
-
newText: string;
|
|
636
|
-
}>;
|
|
637
|
-
}>;
|
|
638
|
-
}>
|
|
639
|
-
> {
|
|
640
|
-
const fixesByLine = new Map<
|
|
641
|
-
number,
|
|
642
|
-
Array<{
|
|
643
|
-
description: string;
|
|
644
|
-
changes: Array<{
|
|
645
|
-
fileName: string;
|
|
646
|
-
textChanges: ReadonlyArray<{
|
|
647
|
-
span: { start: number; length: number };
|
|
648
|
-
newText: string;
|
|
649
|
-
}>;
|
|
650
|
-
}>;
|
|
651
|
-
}>
|
|
652
|
-
>();
|
|
653
|
-
|
|
654
|
-
const diagnostics = precomputedDiags ?? this.getDiagnostics(filePath);
|
|
655
|
-
for (const diag of diagnostics) {
|
|
656
|
-
if (diag.severity !== 1 || diag.code === undefined) continue;
|
|
657
|
-
const fixes = this.getCodeFixes(
|
|
658
|
-
filePath,
|
|
659
|
-
diag.range.start.line,
|
|
660
|
-
diag.range.start.character,
|
|
661
|
-
[diag.code as number],
|
|
662
|
-
);
|
|
663
|
-
if (fixes.length > 0) {
|
|
664
|
-
fixesByLine.set(diag.range.start.line, fixes);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return fixesByLine;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
private symbolKind(kind: string): string {
|
|
671
|
-
const map: Record<string, string> = {
|
|
672
|
-
script: "file",
|
|
673
|
-
class: "class",
|
|
674
|
-
interface: "interface",
|
|
675
|
-
function: "function",
|
|
676
|
-
method: "method",
|
|
677
|
-
property: "property",
|
|
678
|
-
variable: "variable",
|
|
679
|
-
enum: "enum",
|
|
680
|
-
module: "module",
|
|
681
|
-
};
|
|
682
|
-
return map[kind] || "unknown";
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
private completionKind(kind: string): string {
|
|
686
|
-
const map: Record<string, string> = {
|
|
687
|
-
property: "property",
|
|
688
|
-
method: "method",
|
|
689
|
-
class: "class",
|
|
690
|
-
interface: "interface",
|
|
691
|
-
enum: "enum",
|
|
692
|
-
variable: "variable",
|
|
693
|
-
function: "function",
|
|
694
|
-
keyword: "keyword",
|
|
695
|
-
};
|
|
696
|
-
return map[kind] || "text";
|
|
697
|
-
}
|
|
698
|
-
}
|