@mrclrchtr/supi-code-intelligence 4.10.0 → 6.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/README.md +4 -3
- package/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
- package/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
- package/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
- package/node_modules/@mrclrchtr/supi-core/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
- package/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/README.md +111 -5
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/package.json +7 -6
- package/node_modules/@mrclrchtr/supi-lsp/src/api.ts +22 -1
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-cache.ts +245 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-capabilities.ts +78 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +171 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-evidence.ts +413 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-host.ts +15 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-publication.ts +214 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-pull.ts +62 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-refresh.ts +690 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-request.ts +9 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-timing.ts +97 -16
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-waiters.ts +206 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +448 -298
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-state.ts +70 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-document-sync.ts +231 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client-file-state.ts +25 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +529 -119
- package/node_modules/@mrclrchtr/supi-lsp/src/client/transport.ts +161 -33
- package/node_modules/@mrclrchtr/supi-lsp/src/config/capabilities.ts +12 -3
- package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +5 -5
- package/node_modules/@mrclrchtr/supi-lsp/src/config/defaults.json +1 -1
- package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +3 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-extends.ts +68 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-path.ts +8 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/config/tsconfig-scope.ts +176 -24
- package/node_modules/@mrclrchtr/supi-lsp/src/debug-telemetry.ts +45 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +42 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/workspace-sentinels.ts +46 -10
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-client-state.ts +79 -9
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-diagnostics.ts +17 -7
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-recovery.ts +350 -26
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +5 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +586 -96
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-refactor-provider.ts +130 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/lsp-semantic-provider.ts +45 -329
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +57 -120
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-edit-normalizer.ts +320 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/provider/semantic-symbol-mapper.ts +207 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/readiness.ts +72 -2
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +151 -26
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostic-surface.ts +42 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-diagnostics.ts +92 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +165 -118
- package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-transition-debug.ts +49 -0
- package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +102 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +17 -7
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/api.ts +9 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +53 -13
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/request-control.ts +47 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/types.ts +13 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/api.ts +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config/config.ts +31 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/config.ts +2 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +19 -6
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug.ts +9 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/index.ts +1 -1
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +3 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/LICENSE +21 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/README.md +258 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/dist/babel.cjs +257 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/dist/jiti.cjs +1 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-cli.mjs +34 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-hooks.mjs +124 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-native.mjs +121 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-register.d.mts +1 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-register.mjs +4 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti-static.mjs +23 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.cjs +30 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.d.cts +8 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.d.mts +8 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/jiti.mjs +29 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/lib/types.d.ts +420 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/jiti/package.json +146 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +6 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/api.ts +0 -9
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/index.ts +0 -8
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/provider/tree-sitter-provider.ts +16 -12
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime-controller.ts +65 -87
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/session.ts +47 -95
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-timing.ts +147 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client-lifecycle.ts +39 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-client.ts +561 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-message-size.ts +24 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/structural-worker-protocol.ts +452 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +4 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +12 -4
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/exports.ts +4 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/imports.ts +4 -2
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/node-at.ts +5 -3
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/types.ts +33 -12
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/blocking-test-bootstrap.mjs +34 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/bootstrap.mjs +8 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/parsed-file-store-helpers.ts +23 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/parsed-file-store.ts +400 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/request-control.ts +48 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime-parser-helpers.ts +24 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime-query-helpers.ts +43 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/runtime.ts +421 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/service.ts +116 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/worker-main.ts +201 -0
- package/package.json +5 -5
- package/src/analysis/health/diagnostics.ts +221 -77
- package/src/analysis/health/file-scope.ts +184 -0
- package/src/analysis/health/recovery.ts +14 -3
- package/src/analysis/provider.ts +58 -0
- package/src/analysis/readiness.ts +34 -9
- package/src/analysis/refactor/apply.ts +45 -1
- package/src/analysis/refactor/mutation-authority.ts +143 -0
- package/src/analysis/relations/callees.ts +9 -1
- package/src/analysis/relations/types.ts +5 -2
- package/src/analysis/search/ast-scan-timing.ts +9 -2
- package/src/analysis/search/ast-scan.ts +5 -2
- package/src/analysis/search/deadline.ts +2 -2
- package/src/analysis/search/pattern-analysis.ts +54 -33
- package/src/analysis/search/pattern.ts +18 -3
- package/src/analysis/target/anchored.ts +20 -11
- package/src/analysis/target/file.ts +18 -11
- package/src/analysis/target/identity.ts +19 -3
- package/src/analysis/target/symbol.ts +36 -15
- package/src/api.ts +4 -0
- package/src/config.ts +35 -1
- package/src/diagnostics/evidence.ts +51 -0
- package/src/extension.ts +57 -14
- package/src/overview/overview-data.ts +9 -2
- package/src/overview/overview.ts +49 -30
- package/src/overview/types.ts +2 -0
- package/src/session/capability-adapter.ts +12 -3
- package/src/session/find-types.ts +2 -2
- package/src/session/find-workflow.ts +20 -9
- package/src/session/graph/collect.ts +18 -2
- package/src/session/graph-workflow.ts +19 -12
- package/src/session/health-refresh.ts +175 -0
- package/src/session/health-types.ts +43 -15
- package/src/session/health-workflow.ts +69 -54
- package/src/session/input/workflows.ts +2 -2
- package/src/session/inspect/collect.ts +20 -3
- package/src/session/inspect-workflow.ts +12 -6
- package/src/session/orientation/collect.ts +12 -3
- package/src/session/orientation/context-facts.ts +3 -1
- package/src/session/orientation/context-sections.ts +20 -7
- package/src/session/orientation/gather.ts +17 -11
- package/src/session/orientation-types.ts +4 -1
- package/src/session/orientation-workflow.ts +23 -10
- package/src/session/refactor-plans.ts +2 -0
- package/src/session/refactor-workflow.ts +61 -15
- package/src/session/session.ts +29 -2
- package/src/session/target-workflow.ts +54 -23
- package/src/session/workflow-control.ts +7 -3
- package/src/substrate/lsp/lifecycle.ts +26 -46
- package/src/substrate/lsp/maintenance.ts +284 -28
- package/src/substrate/lsp/recovery.ts +11 -5
- package/src/substrate/lsp/state.ts +2 -2
- package/src/substrate/workspace-provider-host.ts +25 -3
- package/src/tool/{find → code_find}/execute.ts +2 -16
- package/src/tool/code_find/guidance.ts +8 -0
- package/src/tool/{find → code_find}/render.ts +21 -4
- package/src/tool/{result/find.ts → code_find/result.ts} +78 -9
- package/src/tool/code_find/spec.ts +37 -0
- package/src/tool/code_find/tui.ts +41 -0
- package/src/tool/code_graph/execute.ts +24 -0
- package/src/tool/code_graph/guidance.ts +6 -0
- package/src/tool/{graph → code_graph}/markdown.ts +1 -1
- package/src/tool/{result/graph.ts → code_graph/result.ts} +111 -3
- package/src/tool/code_graph/spec.ts +39 -0
- package/src/tool/code_graph/tui.ts +117 -0
- package/src/tool/{health → code_health}/execute.ts +2 -13
- package/src/tool/code_health/guidance.ts +8 -0
- package/src/tool/{health → code_health}/markdown.ts +119 -27
- package/src/tool/code_health/refresh-status.ts +105 -0
- package/src/tool/{result/health.ts → code_health/result.ts} +80 -3
- package/src/tool/code_health/spec.ts +41 -0
- package/src/tool/{health → code_health}/tui.ts +95 -98
- package/src/tool/{inspect → code_inspect}/execute.ts +2 -16
- package/src/tool/code_inspect/guidance.ts +6 -0
- package/src/tool/{inspect → code_inspect}/markdown.ts +1 -1
- package/src/tool/{result/inspect.ts → code_inspect/result.ts} +143 -2
- package/src/tool/code_inspect/spec.ts +25 -0
- package/src/tool/code_inspect/tui.ts +44 -0
- package/src/tool/code_orientation/execute.ts +25 -0
- package/src/tool/code_orientation/guidance.ts +9 -0
- package/src/tool/{orientation → code_orientation}/markdown.ts +1 -1
- package/src/tool/code_orientation/result.ts +248 -0
- package/src/tool/code_orientation/spec.ts +25 -0
- package/src/tool/{orientation → code_orientation}/tui.ts +51 -35
- package/src/tool/code_refactor_apply/execute.ts +17 -0
- package/src/tool/code_refactor_apply/guidance.ts +5 -0
- package/src/tool/{refactor-apply/execute.ts → code_refactor_apply/result.ts} +8 -11
- package/src/tool/code_refactor_apply/spec.ts +26 -0
- package/src/tool/code_refactor_apply/tui.ts +73 -0
- package/src/tool/code_refactor_plan/execute.ts +27 -0
- package/src/tool/code_refactor_plan/guidance.ts +8 -0
- package/src/tool/{refactor-plan/execute.ts → code_refactor_plan/result.ts} +13 -22
- package/src/tool/code_refactor_plan/spec.ts +25 -0
- package/src/tool/code_refactor_plan/tui.ts +54 -0
- package/src/tool/code_resolve/execute.ts +19 -0
- package/src/tool/code_resolve/guidance.ts +8 -0
- package/src/tool/{resolve → code_resolve}/markdown.ts +1 -1
- package/src/tool/{result/resolve.ts → code_resolve/result.ts} +79 -29
- package/src/tool/code_resolve/spec.ts +25 -0
- package/src/tool/code_resolve/tui.ts +60 -0
- package/src/tool/guidance.ts +71 -52
- package/src/tool/infra/truncate.ts +40 -0
- package/src/tool/infra/workflow-control.ts +8 -0
- package/src/tool/{refactor-plan/markdown.ts → refactor-markdown.ts} +4 -7
- package/src/tool/register.ts +105 -88
- package/src/tool/result/display.ts +107 -0
- package/src/tool/result/errors.ts +20 -17
- package/src/tool/result/refactor.ts +37 -8
- package/src/tool/result/types.ts +20 -0
- package/src/tool/schemas.ts +26 -157
- package/src/tool/specs.ts +40 -126
- package/src/types/execution.ts +18 -5
- package/src/types/index.ts +8 -1
- package/src/ui/status-command.ts +5 -3
- package/src/ui/status-overlay.ts +4 -0
- package/src/ui/tui/common.ts +108 -10
- package/src/ui/tui/display.ts +48 -0
- package/node_modules/@mrclrchtr/supi-tree-sitter/src/session/runtime.ts +0 -351
- package/src/tool/find/tui.ts +0 -39
- package/src/tool/graph/execute.ts +0 -62
- package/src/tool/graph/tui.ts +0 -104
- package/src/tool/inspect/tui.ts +0 -36
- package/src/tool/orientation/execute.ts +0 -62
- package/src/tool/refactor-apply/tui.ts +0 -55
- package/src/tool/refactor-plan/tui.ts +0 -41
- package/src/tool/resolve/execute.ts +0 -36
- package/src/tool/resolve/tui.ts +0 -42
- package/src/tool/result/orientation.ts +0 -132
- /package/src/tool/{find → code_find}/ast-kinds.ts +0 -0
- /package/src/tool/{find → code_find}/markdown.ts +0 -0
- /package/src/tool/{find → code_find}/modes.ts +0 -0
- /package/src/tool/{health → code_health}/semantic-state.ts +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CodeRequestControl,
|
|
3
|
+
RefactorRequest,
|
|
4
|
+
RefactorResult,
|
|
5
|
+
SemanticProvider,
|
|
6
|
+
} from "@mrclrchtr/supi-code-runtime/api";
|
|
7
|
+
import type { CodeAction } from "../config/types.ts";
|
|
8
|
+
import type { WorkspaceLspRuntime } from "../session/runtime-registry.ts";
|
|
9
|
+
import {
|
|
10
|
+
collectCodeActionResults,
|
|
11
|
+
isDeleteDeadCodeCodeAction,
|
|
12
|
+
isExtractFunctionCodeAction,
|
|
13
|
+
isExtractVariableCodeAction,
|
|
14
|
+
isUpdateImportsCodeAction,
|
|
15
|
+
runFilteredCodeActionRefactor,
|
|
16
|
+
runRenameRefactor,
|
|
17
|
+
} from "./refactor-planning.ts";
|
|
18
|
+
|
|
19
|
+
/** Build optional refactor methods for the semantic provider adapter. */
|
|
20
|
+
export function createLspRefactorProvider(
|
|
21
|
+
lsp: WorkspaceLspRuntime,
|
|
22
|
+
): Pick<SemanticProvider, "refactor" | "rename" | "codeActions"> {
|
|
23
|
+
return {
|
|
24
|
+
refactor: (request, control) => planRefactor(lsp, request, control),
|
|
25
|
+
rename: (file, position, newName, control) =>
|
|
26
|
+
runRenameRefactor({ lsp, file, position, newName, control }),
|
|
27
|
+
async codeActions(file, position, control) {
|
|
28
|
+
const response = control
|
|
29
|
+
? await lsp.codeActions(file, position, control)
|
|
30
|
+
: await lsp.codeActions(file, position);
|
|
31
|
+
if (!response?.value) return [];
|
|
32
|
+
return collectCodeActionResults(response.value, {
|
|
33
|
+
getOpenDocumentVersion: (candidate) => lsp.getOpenDocumentVersion(candidate),
|
|
34
|
+
authorizedMutationRoots: response.authorizedMutationRoots,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function planRefactor(
|
|
41
|
+
lsp: WorkspaceLspRuntime,
|
|
42
|
+
request: RefactorRequest,
|
|
43
|
+
control?: CodeRequestControl,
|
|
44
|
+
): Promise<RefactorResult> {
|
|
45
|
+
switch (request.operation) {
|
|
46
|
+
case "rename_symbol":
|
|
47
|
+
if (!request.newName) {
|
|
48
|
+
return {
|
|
49
|
+
kind: "unavailable",
|
|
50
|
+
reason: 'Refactor operation "rename_symbol" requires `newName`.',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return runRenameRefactor({
|
|
54
|
+
lsp,
|
|
55
|
+
file: request.file,
|
|
56
|
+
position: request.position,
|
|
57
|
+
newName: request.newName,
|
|
58
|
+
control,
|
|
59
|
+
});
|
|
60
|
+
case "extract_function":
|
|
61
|
+
return runExtractRefactor({
|
|
62
|
+
lsp,
|
|
63
|
+
request,
|
|
64
|
+
operation: "extract_function",
|
|
65
|
+
matches: isExtractFunctionCodeAction,
|
|
66
|
+
control,
|
|
67
|
+
});
|
|
68
|
+
case "extract_variable":
|
|
69
|
+
return runExtractRefactor({
|
|
70
|
+
lsp,
|
|
71
|
+
request,
|
|
72
|
+
operation: "extract_variable",
|
|
73
|
+
matches: isExtractVariableCodeAction,
|
|
74
|
+
control,
|
|
75
|
+
});
|
|
76
|
+
case "update_imports":
|
|
77
|
+
return runFilteredCodeActionRefactor({
|
|
78
|
+
lsp,
|
|
79
|
+
file: request.file,
|
|
80
|
+
position: request.position,
|
|
81
|
+
operation: "update_imports",
|
|
82
|
+
matches: isUpdateImportsCodeAction,
|
|
83
|
+
control,
|
|
84
|
+
});
|
|
85
|
+
case "delete_dead_code":
|
|
86
|
+
return runFilteredCodeActionRefactor({
|
|
87
|
+
lsp,
|
|
88
|
+
file: request.file,
|
|
89
|
+
position: request.position,
|
|
90
|
+
operation: "delete_dead_code",
|
|
91
|
+
matches: isDeleteDeadCodeCodeAction,
|
|
92
|
+
control,
|
|
93
|
+
});
|
|
94
|
+
case "rename_file":
|
|
95
|
+
case "move_file":
|
|
96
|
+
return {
|
|
97
|
+
kind: "unavailable",
|
|
98
|
+
reason: `Refactor operation "${request.operation}" is not supported yet. File/resource operations are deferred.`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
kind: "unavailable",
|
|
103
|
+
reason: `Refactor operation "${request.operation}" is not supported by the active semantic provider.`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function runExtractRefactor(options: {
|
|
108
|
+
lsp: WorkspaceLspRuntime;
|
|
109
|
+
request: RefactorRequest;
|
|
110
|
+
operation: "extract_function" | "extract_variable";
|
|
111
|
+
matches: (action: CodeAction) => boolean;
|
|
112
|
+
control?: CodeRequestControl;
|
|
113
|
+
}): Promise<RefactorResult> | RefactorResult {
|
|
114
|
+
const { lsp, request, operation, matches, control } = options;
|
|
115
|
+
if (!request.range) {
|
|
116
|
+
return {
|
|
117
|
+
kind: "unavailable",
|
|
118
|
+
reason: `Refactor operation "${operation}" requires \`range\`.`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return runFilteredCodeActionRefactor({
|
|
122
|
+
lsp,
|
|
123
|
+
file: request.file,
|
|
124
|
+
position: request.position,
|
|
125
|
+
range: request.range,
|
|
126
|
+
operation,
|
|
127
|
+
matches,
|
|
128
|
+
control,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
// LSP semantic provider adapter — wraps WorkspaceLspRuntime into the shared
|
|
2
2
|
// SemanticProvider contract from supi-code-runtime.
|
|
3
3
|
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
4
|
import {
|
|
6
5
|
type CodeLocation,
|
|
7
6
|
type CodePosition,
|
|
8
7
|
type CodeQueryResult,
|
|
8
|
+
type CodeRequestControl,
|
|
9
9
|
type CodeSymbol,
|
|
10
10
|
completedCodeQuery,
|
|
11
|
-
type DeclarationNesting,
|
|
12
11
|
type DocumentCodeSymbol,
|
|
13
12
|
mapCodeQueryResult,
|
|
14
13
|
partialCodeQuery,
|
|
15
|
-
type RefactorRequest,
|
|
16
|
-
type RefactorResult,
|
|
17
14
|
type SemanticProvider,
|
|
18
15
|
type SourceRange,
|
|
19
16
|
unavailableCodeQuery,
|
|
20
17
|
} from "@mrclrchtr/supi-code-runtime/api";
|
|
21
|
-
import {
|
|
22
|
-
import type {
|
|
23
|
-
CodeAction,
|
|
24
|
-
DocumentSymbol,
|
|
25
|
-
Hover,
|
|
26
|
-
Location,
|
|
27
|
-
LocationLink,
|
|
28
|
-
MarkupContent,
|
|
29
|
-
SymbolInformation,
|
|
30
|
-
} from "../config/types.ts";
|
|
18
|
+
import type { SymbolInformation } from "../config/types.ts";
|
|
31
19
|
import type { WorkspaceLspRuntime } from "../session/runtime-registry.ts";
|
|
20
|
+
import { createLspRefactorProvider } from "./lsp-refactor-provider.ts";
|
|
32
21
|
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
runFilteredCodeActionRefactor,
|
|
39
|
-
runRenameRefactor,
|
|
40
|
-
} from "./refactor-planning.ts";
|
|
22
|
+
convertLspHover,
|
|
23
|
+
mapDocumentSymbols,
|
|
24
|
+
mapLocations,
|
|
25
|
+
toCodeSymbol,
|
|
26
|
+
} from "./semantic-symbol-mapper.ts";
|
|
41
27
|
|
|
42
28
|
/**
|
|
43
29
|
* Create a SemanticProvider backed by a WorkspaceLspRuntime.
|
|
@@ -48,343 +34,73 @@ export function createLspSemanticProvider(lsp: WorkspaceLspRuntime): SemanticPro
|
|
|
48
34
|
async definition(
|
|
49
35
|
filePath: string,
|
|
50
36
|
position: CodePosition,
|
|
37
|
+
control?: CodeRequestControl,
|
|
51
38
|
): Promise<CodeQueryResult<CodeLocation[]>> {
|
|
52
|
-
|
|
39
|
+
const result = control
|
|
40
|
+
? await lsp.definition(filePath, position, control)
|
|
41
|
+
: await lsp.definition(filePath, position);
|
|
42
|
+
return mapCodeQueryResult(result, mapLocations);
|
|
53
43
|
},
|
|
54
44
|
|
|
55
45
|
async hover(
|
|
56
46
|
filePath: string,
|
|
57
47
|
position: CodePosition,
|
|
48
|
+
control?: CodeRequestControl,
|
|
58
49
|
): Promise<CodeQueryResult<{ contents: string; range?: SourceRange } | null>> {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
const result = control
|
|
51
|
+
? await lsp.hover(filePath, position, control)
|
|
52
|
+
: await lsp.hover(filePath, position);
|
|
53
|
+
return mapCodeQueryResult(result, (hover) => (hover ? convertLspHover(hover) : null));
|
|
62
54
|
},
|
|
63
55
|
|
|
64
56
|
async references(
|
|
65
57
|
filePath: string,
|
|
66
58
|
position: CodePosition,
|
|
59
|
+
control?: CodeRequestControl,
|
|
67
60
|
): Promise<CodeQueryResult<CodeLocation[]>> {
|
|
68
|
-
|
|
61
|
+
const result = control
|
|
62
|
+
? await lsp.references(filePath, position, control)
|
|
63
|
+
: await lsp.references(filePath, position);
|
|
64
|
+
return mapCodeQueryResult(result, mapLocations);
|
|
69
65
|
},
|
|
70
66
|
|
|
71
67
|
async implementation(
|
|
72
68
|
filePath: string,
|
|
73
69
|
position: CodePosition,
|
|
70
|
+
control?: CodeRequestControl,
|
|
74
71
|
): Promise<CodeQueryResult<CodeLocation[]>> {
|
|
75
|
-
|
|
72
|
+
const result = control
|
|
73
|
+
? await lsp.implementation(filePath, position, control)
|
|
74
|
+
: await lsp.implementation(filePath, position);
|
|
75
|
+
return mapCodeQueryResult(result, mapLocations);
|
|
76
76
|
},
|
|
77
77
|
|
|
78
|
-
async documentSymbols(
|
|
79
|
-
|
|
78
|
+
async documentSymbols(
|
|
79
|
+
filePath: string,
|
|
80
|
+
control?: CodeRequestControl,
|
|
81
|
+
): Promise<CodeQueryResult<DocumentCodeSymbol[]>> {
|
|
82
|
+
const result = control
|
|
83
|
+
? await lsp.documentSymbols(filePath, control)
|
|
84
|
+
: await lsp.documentSymbols(filePath);
|
|
80
85
|
if (result.kind === "unavailable") return unavailableCodeQuery(result.reason);
|
|
81
|
-
const
|
|
82
|
-
const symbols = flattenDocumentSymbols(result.data, filePath, null, {
|
|
83
|
-
sourceLines,
|
|
84
|
-
nesting: "top-level",
|
|
85
|
-
});
|
|
86
|
+
const symbols = await mapDocumentSymbols(result.data, filePath);
|
|
86
87
|
return result.kind === "partial"
|
|
87
88
|
? partialCodeQuery(symbols, result.reason)
|
|
88
89
|
: completedCodeQuery(symbols);
|
|
89
90
|
},
|
|
90
91
|
|
|
91
|
-
async workspaceSymbols(
|
|
92
|
-
|
|
92
|
+
async workspaceSymbols(
|
|
93
|
+
query: string,
|
|
94
|
+
control?: CodeRequestControl,
|
|
95
|
+
): Promise<CodeQueryResult<CodeSymbol[]>> {
|
|
96
|
+
const result = control
|
|
97
|
+
? await lsp.workspaceSymbol(query, control)
|
|
98
|
+
: await lsp.workspaceSymbol(query);
|
|
99
|
+
return mapCodeQueryResult(result, (results) =>
|
|
93
100
|
results.map((symbol) => toCodeSymbol(symbol as SymbolInformation)),
|
|
94
101
|
);
|
|
95
102
|
},
|
|
96
103
|
|
|
97
|
-
|
|
98
|
-
switch (request.operation) {
|
|
99
|
-
case "rename_symbol":
|
|
100
|
-
if (!request.newName) {
|
|
101
|
-
return {
|
|
102
|
-
kind: "unavailable",
|
|
103
|
-
reason: 'Refactor operation "rename_symbol" requires `newName`.',
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return runRenameRefactor(lsp, request.file, request.position, request.newName);
|
|
107
|
-
case "extract_function":
|
|
108
|
-
return runExtractRefactor(lsp, request, "extract_function", isExtractFunctionCodeAction);
|
|
109
|
-
case "extract_variable":
|
|
110
|
-
return runExtractRefactor(lsp, request, "extract_variable", isExtractVariableCodeAction);
|
|
111
|
-
case "update_imports":
|
|
112
|
-
return runFilteredCodeActionRefactor({
|
|
113
|
-
lsp,
|
|
114
|
-
file: request.file,
|
|
115
|
-
position: request.position,
|
|
116
|
-
operation: "update_imports",
|
|
117
|
-
matches: isUpdateImportsCodeAction,
|
|
118
|
-
});
|
|
119
|
-
case "delete_dead_code":
|
|
120
|
-
return runFilteredCodeActionRefactor({
|
|
121
|
-
lsp,
|
|
122
|
-
file: request.file,
|
|
123
|
-
position: request.position,
|
|
124
|
-
operation: "delete_dead_code",
|
|
125
|
-
matches: isDeleteDeadCodeCodeAction,
|
|
126
|
-
});
|
|
127
|
-
case "rename_file":
|
|
128
|
-
case "move_file":
|
|
129
|
-
// TODO(TNDM-D9FEHR): Replace this explicit unavailable result once
|
|
130
|
-
// shared file/resource edits and rollback semantics exist.
|
|
131
|
-
return {
|
|
132
|
-
kind: "unavailable",
|
|
133
|
-
reason: `Refactor operation "${request.operation}" is not supported yet. File/resource operations are deferred.`,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
kind: "unavailable",
|
|
139
|
-
reason: `Refactor operation "${request.operation}" is not supported by the active semantic provider.`,
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
async rename(file: string, position: CodePosition, newName: string): Promise<RefactorResult> {
|
|
144
|
-
return runRenameRefactor(lsp, file, position, newName);
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
async codeActions(file: string, position: CodePosition): Promise<RefactorResult[]> {
|
|
148
|
-
const actions = await lsp.codeActions(file, position);
|
|
149
|
-
if (!actions) return [];
|
|
150
|
-
return collectCodeActionResults(actions);
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function runExtractRefactor(
|
|
156
|
-
lsp: WorkspaceLspRuntime,
|
|
157
|
-
request: RefactorRequest,
|
|
158
|
-
operation: "extract_function" | "extract_variable",
|
|
159
|
-
matches: (action: CodeAction) => boolean,
|
|
160
|
-
): Promise<RefactorResult> | RefactorResult {
|
|
161
|
-
if (!request.range) {
|
|
162
|
-
return {
|
|
163
|
-
kind: "unavailable",
|
|
164
|
-
reason: `Refactor operation "${operation}" requires \`range\`.`,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return runFilteredCodeActionRefactor({
|
|
169
|
-
lsp,
|
|
170
|
-
file: request.file,
|
|
171
|
-
position: request.position,
|
|
172
|
-
range: request.range,
|
|
173
|
-
operation,
|
|
174
|
-
matches,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ── Type conversion helpers ───────────────────────────────────────────
|
|
179
|
-
|
|
180
|
-
function mapLocations(value: Location | Location[] | LocationLink[] | null): CodeLocation[] {
|
|
181
|
-
if (!value) return [];
|
|
182
|
-
const locations = Array.isArray(value) ? value : [value];
|
|
183
|
-
return locations.flatMap((item) => {
|
|
184
|
-
const location = toCodeLocation(item);
|
|
185
|
-
return location ? [location] : [];
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function toCodeLocation(item: Location | LocationLink): CodeLocation | null {
|
|
190
|
-
const loc = item as Record<string, unknown>;
|
|
191
|
-
const uri = loc.uri ?? loc.targetUri;
|
|
192
|
-
if (typeof uri !== "string") return null;
|
|
193
|
-
|
|
194
|
-
// Prefer targetSelectionRange > targetRange > range
|
|
195
|
-
const range = loc.targetSelectionRange ?? loc.targetRange ?? loc.range;
|
|
196
|
-
if (!range || typeof range !== "object") return null;
|
|
197
|
-
|
|
198
|
-
const r = range as { start: Record<string, unknown>; end: Record<string, unknown> };
|
|
199
|
-
const start = r.start;
|
|
200
|
-
const end = r.end;
|
|
201
|
-
if (!start || !end) return null;
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
uri,
|
|
205
|
-
range: {
|
|
206
|
-
start: { line: (start.line as number) ?? 0, character: (start.character as number) ?? 0 },
|
|
207
|
-
end: { line: (end.line as number) ?? 0, character: (end.character as number) ?? 0 },
|
|
208
|
-
},
|
|
104
|
+
...createLspRefactorProvider(lsp),
|
|
209
105
|
};
|
|
210
106
|
}
|
|
211
|
-
|
|
212
|
-
const SYMBOL_KIND_NAMES: Record<number, string> = {
|
|
213
|
-
1: "File",
|
|
214
|
-
2: "Module",
|
|
215
|
-
3: "Namespace",
|
|
216
|
-
4: "Package",
|
|
217
|
-
5: "Class",
|
|
218
|
-
6: "Method",
|
|
219
|
-
7: "Property",
|
|
220
|
-
8: "Field",
|
|
221
|
-
9: "Constructor",
|
|
222
|
-
10: "Enum",
|
|
223
|
-
11: "Interface",
|
|
224
|
-
12: "Function",
|
|
225
|
-
13: "Variable",
|
|
226
|
-
14: "Constant",
|
|
227
|
-
15: "String",
|
|
228
|
-
16: "Number",
|
|
229
|
-
17: "Boolean",
|
|
230
|
-
18: "Array",
|
|
231
|
-
19: "Object",
|
|
232
|
-
20: "Key",
|
|
233
|
-
21: "Null",
|
|
234
|
-
22: "EnumMember",
|
|
235
|
-
23: "Struct",
|
|
236
|
-
24: "Event",
|
|
237
|
-
25: "Operator",
|
|
238
|
-
26: "TypeParameter",
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
function symbolKindName(kind: number): string {
|
|
242
|
-
return SYMBOL_KIND_NAMES[kind] ?? "Unknown";
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function flattenDocumentSymbols(
|
|
246
|
-
symbols: DocumentSymbol[] | SymbolInformation[],
|
|
247
|
-
filePath: string,
|
|
248
|
-
container: string | null,
|
|
249
|
-
context: { sourceLines: readonly string[] | null; nesting: DeclarationNesting },
|
|
250
|
-
): DocumentCodeSymbol[] {
|
|
251
|
-
const result: DocumentCodeSymbol[] = [];
|
|
252
|
-
|
|
253
|
-
for (const sym of symbols) {
|
|
254
|
-
// DocumentSymbol.range = full defining node (declaration anchor);
|
|
255
|
-
// .selectionRange = identifier token (name anchor). SymbolInformation has
|
|
256
|
-
// only location.range (declaration) and no selectionRange.
|
|
257
|
-
let document: DocumentSymbol | null = null;
|
|
258
|
-
let information: SymbolInformation | null = null;
|
|
259
|
-
if (isSymbolInformation(sym)) information = sym;
|
|
260
|
-
else document = sym;
|
|
261
|
-
const declStart = document?.range.start ?? information?.location.range.start;
|
|
262
|
-
if (!declStart) continue;
|
|
263
|
-
const nameStart = document
|
|
264
|
-
? resolveDocumentSymbolNameStart(document, context.sourceLines)
|
|
265
|
-
: null;
|
|
266
|
-
const reportedContainer = information?.containerName ?? container;
|
|
267
|
-
// SymbolInformation is flat: containerName remains metadata, not hierarchy evidence.
|
|
268
|
-
const nesting: DeclarationNesting = information ? "unknown" : context.nesting;
|
|
269
|
-
|
|
270
|
-
const symbol: DocumentCodeSymbol = {
|
|
271
|
-
name: sym.name,
|
|
272
|
-
kind: symbolKindName(sym.kind),
|
|
273
|
-
file: filePath,
|
|
274
|
-
declarationAnchor: { line: declStart.line + 1, character: declStart.character + 1 },
|
|
275
|
-
container: reportedContainer,
|
|
276
|
-
nesting,
|
|
277
|
-
};
|
|
278
|
-
if (nameStart) {
|
|
279
|
-
symbol.nameAnchor = { line: nameStart.line + 1, character: nameStart.character + 1 };
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
result.push(symbol);
|
|
283
|
-
|
|
284
|
-
if (document?.children && document.children.length > 0) {
|
|
285
|
-
result.push(
|
|
286
|
-
...flattenDocumentSymbols(document.children, filePath, sym.name, {
|
|
287
|
-
sourceLines: context.sourceLines,
|
|
288
|
-
nesting: "nested",
|
|
289
|
-
}),
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return result;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function isSymbolInformation(
|
|
298
|
-
symbol: DocumentSymbol | SymbolInformation,
|
|
299
|
-
): symbol is SymbolInformation {
|
|
300
|
-
return "location" in symbol;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async function readSourceLines(filePath: string): Promise<readonly string[] | null> {
|
|
304
|
-
try {
|
|
305
|
-
return (await readFile(filePath, "utf-8")).split(/\r?\n/);
|
|
306
|
-
} catch {
|
|
307
|
-
return null;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Validate the LSP selection range against source text. Some servers return
|
|
313
|
-
* the full overload declaration as selectionRange; recover the exact symbol
|
|
314
|
-
* token on that line rather than labeling the declaration start as a name.
|
|
315
|
-
*/
|
|
316
|
-
function resolveDocumentSymbolNameStart(
|
|
317
|
-
symbol: DocumentSymbol,
|
|
318
|
-
sourceLines: readonly string[] | null,
|
|
319
|
-
): { line: number; character: number } | null {
|
|
320
|
-
const selectionStart = symbol.selectionRange?.start;
|
|
321
|
-
if (!selectionStart) return null;
|
|
322
|
-
if (!sourceLines) return selectionStart;
|
|
323
|
-
|
|
324
|
-
const sourceLine = sourceLines[selectionStart.line];
|
|
325
|
-
if (sourceLine === undefined) return null;
|
|
326
|
-
if (
|
|
327
|
-
sourceLine.slice(selectionStart.character, selectionStart.character + symbol.name.length) ===
|
|
328
|
-
symbol.name
|
|
329
|
-
) {
|
|
330
|
-
return selectionStart;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const rangeStart = symbol.range?.start;
|
|
334
|
-
const rangeEnd = symbol.range?.end;
|
|
335
|
-
const from = rangeStart?.line === selectionStart.line ? rangeStart.character : 0;
|
|
336
|
-
const until = rangeEnd?.line === selectionStart.line ? rangeEnd.character : sourceLine.length;
|
|
337
|
-
const repairedCharacter = sourceLine.indexOf(symbol.name, from);
|
|
338
|
-
if (repairedCharacter < 0 || repairedCharacter + symbol.name.length > until) return null;
|
|
339
|
-
return { line: selectionStart.line, character: repairedCharacter };
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function toCodeSymbol(sym: SymbolInformation): CodeSymbol {
|
|
343
|
-
const uri = sym.location?.uri ?? "";
|
|
344
|
-
const start = sym.location?.range?.start;
|
|
345
|
-
return {
|
|
346
|
-
name: sym.name,
|
|
347
|
-
kind: symbolKindName(sym.kind),
|
|
348
|
-
file: uriToFile(uri),
|
|
349
|
-
// SymbolInformation has no selectionRange — nameAnchor is derived later
|
|
350
|
-
// by the orchestration layer's refine, or left absent.
|
|
351
|
-
declarationAnchor: {
|
|
352
|
-
line: start ? start.line + 1 : 0,
|
|
353
|
-
character: start ? start.character + 1 : 0,
|
|
354
|
-
},
|
|
355
|
-
container: sym.containerName ?? null,
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// ── Hover conversion helpers ─────────────────────────────────────────
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Convert an LSP Hover result into a simplified runtime shape.
|
|
363
|
-
* Extracts text from MarkupContent, MarkedString[], or plain string,
|
|
364
|
-
* and converts the optional LSP Range to a SourceRange.
|
|
365
|
-
*/
|
|
366
|
-
function convertLspHover(hover: Hover): { contents: string; range?: SourceRange } {
|
|
367
|
-
const contents = extractHoverText(hover.contents);
|
|
368
|
-
const result: { contents: string; range?: SourceRange } = { contents };
|
|
369
|
-
if (hover.range) {
|
|
370
|
-
result.range = {
|
|
371
|
-
start: { line: hover.range.start.line, character: hover.range.start.character },
|
|
372
|
-
end: { line: hover.range.end.line, character: hover.range.end.character },
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
return result;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function extractHoverText(contents: Hover["contents"]): string {
|
|
379
|
-
if (typeof contents === "string") return contents;
|
|
380
|
-
if (Array.isArray(contents)) {
|
|
381
|
-
return contents
|
|
382
|
-
.map((item) => {
|
|
383
|
-
if (typeof item === "string") return item;
|
|
384
|
-
return item.value;
|
|
385
|
-
})
|
|
386
|
-
.join("\n");
|
|
387
|
-
}
|
|
388
|
-
// MarkupContent
|
|
389
|
-
return (contents as MarkupContent).value ?? "";
|
|
390
|
-
}
|