pi-agent-ide 0.1.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/LICENSE +21 -0
- package/README.md +53 -0
- package/assets/banner.png +0 -0
- package/docs/architecture.md +100 -0
- package/docs/configuration.md +104 -0
- package/docs/development.md +102 -0
- package/docs/evaluation.md +14 -0
- package/docs/extensions.md +298 -0
- package/docs/tools.md +104 -0
- package/node_modules/pi-agent-filesystem/index.ts +60 -0
- package/node_modules/pi-agent-filesystem/package.json +23 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
- package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-image/package.json +20 -0
- package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
- package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
- package/node_modules/pi-agent-filesystem-text/package.json +20 -0
- package/node_modules/pi-agent-ide-ast/index.ts +1 -0
- package/node_modules/pi-agent-ide-ast/package.json +39 -0
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/node_modules/pi-agent-ide-changes/index.ts +68 -0
- package/node_modules/pi-agent-ide-changes/package.json +29 -0
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
- package/node_modules/pi-agent-ide-formatter/package.json +14 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lint/index.ts +237 -0
- package/node_modules/pi-agent-ide-lint/package.json +19 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
- package/node_modules/pi-agent-ide-lsp/package.json +23 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/node_modules/pi-agent-image/package.json +18 -0
- package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
- package/node_modules/pi-agent-image/src/index.ts +6 -0
- package/node_modules/pi-agent-pdf/package.json +16 -0
- package/node_modules/pi-agent-pdf/src/index.ts +5 -0
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
- package/node_modules/pi-agent-read/index.ts +1 -0
- package/node_modules/pi-agent-read/package.json +41 -0
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/node_modules/pi-agent-resource/package.json +17 -0
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
- package/node_modules/pi-agent-resource/src/content.ts +17 -0
- package/node_modules/pi-agent-resource/src/index.ts +65 -0
- package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
- package/node_modules/pi-agent-resource/src/resource.ts +41 -0
- package/node_modules/pi-agent-resource/src/validation.ts +139 -0
- package/node_modules/pi-agent-search/index.ts +1 -0
- package/node_modules/pi-agent-search/package.json +35 -0
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/node_modules/pi-agent-search/src/api/search.ts +91 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
- package/node_modules/pi-agent-search-semantic/index.ts +105 -0
- package/node_modules/pi-agent-search-semantic/package.json +17 -0
- package/node_modules/pi-agent-search-text/index.ts +54 -0
- package/node_modules/pi-agent-search-text/package.json +33 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
- package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
- package/node_modules/pi-agent-search-web/index.ts +74 -0
- package/node_modules/pi-agent-search-web/package.json +19 -0
- package/node_modules/pi-agent-search-web/src/config.ts +499 -0
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
- package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
- package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
- package/node_modules/pi-agent-search-web/src/search.ts +434 -0
- package/node_modules/pi-agent-search-web/src/types.ts +153 -0
- package/node_modules/pi-agent-text/package.json +18 -0
- package/node_modules/pi-agent-text/src/index.ts +31 -0
- package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
- package/node_modules/pi-agent-text/src/source-line.ts +49 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
- package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
- package/node_modules/pi-agent-text/src/text-document.ts +149 -0
- package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/node_modules/pi-agent-text-editor/index.ts +19 -0
- package/node_modules/pi-agent-text-editor/package.json +92 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
- package/node_modules/pi-agent-web/index.ts +37 -0
- package/node_modules/pi-agent-web/package.json +24 -0
- package/node_modules/pi-agent-web/src/resolver.ts +182 -0
- package/node_modules/pi-agent-web-html/index.ts +15 -0
- package/node_modules/pi-agent-web-html/package.json +18 -0
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
- package/node_modules/pi-agent-web-image/index.ts +14 -0
- package/node_modules/pi-agent-web-image/package.json +17 -0
- package/node_modules/pi-agent-web-pdf/index.ts +14 -0
- package/node_modules/pi-agent-web-pdf/package.json +17 -0
- package/node_modules/pi-agent-web-text/index.ts +14 -0
- package/node_modules/pi-agent-web-text/package.json +17 -0
- package/package.json +176 -0
- package/src/api/code-view.ts +25 -0
- package/src/api/connect-plugin.ts +64 -0
- package/src/api/plugin-protocol.ts +63 -0
- package/src/api/read.ts +5 -0
- package/src/api/resource.ts +2 -0
- package/src/api/search.ts +4 -0
- package/src/api/text-editor.ts +3 -0
- package/src/api/text.ts +2 -0
- package/src/api/toolchain.ts +24 -0
- package/src/code-view/diagnostic-view.ts +82 -0
- package/src/code-view/reference.ts +113 -0
- package/src/code-view/source-view.ts +229 -0
- package/src/composite/builtin-extensions.ts +68 -0
- package/src/composite/config.ts +94 -0
- package/src/composite/selection.ts +66 -0
- package/src/core/extension.ts +48 -0
- package/src/core/ide-core.ts +117 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
- package/src/extensions/pi-agent-read/index.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +41 -0
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/src/extensions/pi-agent-search/index.ts +1 -0
- package/src/extensions/pi-agent-search/package.json +35 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
- package/src/extensions/pi-agent-text-editor/index.ts +19 -0
- package/src/extensions/pi-agent-text-editor/package.json +92 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/src/index.ts +1 -0
- package/src/pi-agent-ide.ts +17 -0
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/package.json +39 -0
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
- package/src/plugins/pi-agent-ide-changes/package.json +29 -0
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
- package/src/plugins/pi-agent-ide-lint/package.json +19 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
- package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/src/post-edit/gate.ts +153 -0
- package/src/toolchain/diagnostic.ts +7 -0
- package/src/toolchain/gate.ts +322 -0
- package/src/toolchain/registry.ts +223 -0
- package/src/toolchain/types.ts +164 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { URI } from "vscode-uri";
|
|
5
|
+
|
|
6
|
+
import { LspClient } from "./client.js";
|
|
7
|
+
import { DiagnosticSeverity, type LspDiagnostic, type ResolvedServer } from "./types.js";
|
|
8
|
+
|
|
9
|
+
import type { LspServerRegistry } from "./registry.js";
|
|
10
|
+
import type { Diagnostic } from "pi-agent-ide/api/toolchain";
|
|
11
|
+
|
|
12
|
+
export interface LspPushDiagnosticsEvent
|
|
13
|
+
{
|
|
14
|
+
serverId: string;
|
|
15
|
+
uri: string;
|
|
16
|
+
version?: number;
|
|
17
|
+
diagnostics: Diagnostic[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PushHandler = (event: LspPushDiagnosticsEvent) => void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* LspManager — server lifecycle, connection pooling, idle timeout.
|
|
24
|
+
*
|
|
25
|
+
* The process-stable instance is reconfigured for each Pi session so registered
|
|
26
|
+
* compiler, formatter, and linter adapters keep a valid manager reference.
|
|
27
|
+
*/
|
|
28
|
+
export class LspManager
|
|
29
|
+
{
|
|
30
|
+
/** Active clients keyed by serverId. */
|
|
31
|
+
private readonly _clients = new Map<string, LspClient>();
|
|
32
|
+
private readonly _clientStarts = new Map<string, Promise<LspClient>>();
|
|
33
|
+
/** Track already-opened URIs to avoid duplicate didOpen in formatter. */
|
|
34
|
+
private readonly _openDocs = new Set<string>();
|
|
35
|
+
private readonly _pushUnsubscribers = new Map<string, () => void>();
|
|
36
|
+
private readonly _pushHandlers = new Set<PushHandler>();
|
|
37
|
+
private readonly _pushFingerprints = new Map<string, string>();
|
|
38
|
+
private _disposed = false;
|
|
39
|
+
|
|
40
|
+
private static _instance: LspManager | null = null;
|
|
41
|
+
|
|
42
|
+
private constructor(private _registry: LspServerRegistry)
|
|
43
|
+
{}
|
|
44
|
+
|
|
45
|
+
static getInstance(): LspManager
|
|
46
|
+
{
|
|
47
|
+
if (!LspManager._instance)
|
|
48
|
+
{
|
|
49
|
+
throw new Error("[lsp] LspManager not initialized");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return LspManager._instance;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static getInstanceOrNull(): LspManager | null
|
|
56
|
+
{
|
|
57
|
+
return LspManager._instance;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static init(registry: LspServerRegistry): LspManager
|
|
61
|
+
{
|
|
62
|
+
const current = LspManager._instance;
|
|
63
|
+
|
|
64
|
+
if (current?._disposed)
|
|
65
|
+
{
|
|
66
|
+
current._registry = registry;
|
|
67
|
+
current._disposed = false;
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
LspManager._instance = new LspManager(registry);
|
|
72
|
+
return LspManager._instance;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static async resetForTest(): Promise<void>
|
|
76
|
+
{
|
|
77
|
+
if (LspManager._instance)
|
|
78
|
+
{
|
|
79
|
+
await LspManager._instance.shutdownAll();
|
|
80
|
+
LspManager._instance = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ── lifecycle ──────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
get clientCount(): number
|
|
87
|
+
{
|
|
88
|
+
return this._clients.size;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
onPushDiagnostics(handler: PushHandler): () => void
|
|
92
|
+
{
|
|
93
|
+
this._pushHandlers.add(handler);
|
|
94
|
+
return () => this._pushHandlers.delete(handler);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get or start the LSP client for a file extension.
|
|
99
|
+
*
|
|
100
|
+
* Resolves the extension through the registry, picks the first server
|
|
101
|
+
* that has the requested capability, spawns it if needed, and returns
|
|
102
|
+
* the ready client. Returns null if no LSP server is configured for
|
|
103
|
+
* this extension or capability.
|
|
104
|
+
*/
|
|
105
|
+
async getOrStart(
|
|
106
|
+
ext: string,
|
|
107
|
+
cwd: string,
|
|
108
|
+
capability: "diagnostics" | "symbols",
|
|
109
|
+
): Promise<LspClient | null>
|
|
110
|
+
{
|
|
111
|
+
if (this._disposed)
|
|
112
|
+
{
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const resolved = this._registry.resolve(ext);
|
|
117
|
+
const match = capability === "symbols"
|
|
118
|
+
? resolved[0]
|
|
119
|
+
: resolved.find((s) => s.config.capabilities.includes(capability));
|
|
120
|
+
|
|
121
|
+
if (!match)
|
|
122
|
+
{
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const rootUri = URI.file(cwd).toString();
|
|
127
|
+
const clientKey = `${match.serverId}:${rootUri}`;
|
|
128
|
+
const pendingClient = this._clientStarts.get(clientKey);
|
|
129
|
+
|
|
130
|
+
if (pendingClient)
|
|
131
|
+
{
|
|
132
|
+
return pendingClient;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const client = this._clients.get(clientKey);
|
|
136
|
+
|
|
137
|
+
if (client?.ready)
|
|
138
|
+
{
|
|
139
|
+
return client;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const clientStart = this._startClient(clientKey, rootUri, match, client);
|
|
143
|
+
this._clientStarts.set(clientKey, clientStart);
|
|
144
|
+
|
|
145
|
+
try
|
|
146
|
+
{
|
|
147
|
+
return await clientStart;
|
|
148
|
+
}
|
|
149
|
+
finally
|
|
150
|
+
{
|
|
151
|
+
if (this._clientStarts.get(clientKey) === clientStart)
|
|
152
|
+
{
|
|
153
|
+
this._clientStarts.delete(clientKey);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private async _startClient(
|
|
159
|
+
clientKey: string,
|
|
160
|
+
rootUri: string,
|
|
161
|
+
match: ResolvedServer,
|
|
162
|
+
client: LspClient | undefined,
|
|
163
|
+
): Promise<LspClient>
|
|
164
|
+
{
|
|
165
|
+
const startingClient = client ?? new LspClient({
|
|
166
|
+
serverId: match.serverId,
|
|
167
|
+
rootUri,
|
|
168
|
+
command: match.config.command,
|
|
169
|
+
...(match.config.initOptions ? { initOptions: match.config.initOptions } : {}),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
try
|
|
173
|
+
{
|
|
174
|
+
if (client)
|
|
175
|
+
{
|
|
176
|
+
await client.restart();
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
{
|
|
180
|
+
await startingClient.start();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (error)
|
|
184
|
+
{
|
|
185
|
+
await startingClient.shutdown().catch(() => void 0);
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (this._disposed)
|
|
190
|
+
{
|
|
191
|
+
await startingClient.shutdown();
|
|
192
|
+
throw new Error(`[lsp] ${match.serverId}: manager disposed during startup`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this._clients.set(clientKey, startingClient);
|
|
196
|
+
this._subscribeToPushDiagnostics(clientKey, startingClient);
|
|
197
|
+
return startingClient;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Start the native LSP clients that can search the current workspace.
|
|
202
|
+
*
|
|
203
|
+
* Workspace symbols are requested per language server, so a search with
|
|
204
|
+
* no file extension must query every configured language family.
|
|
205
|
+
*/
|
|
206
|
+
async getWorkspaceClients(cwd: string, capability: "symbols" = "symbols"): Promise<LspClient[]>
|
|
207
|
+
{
|
|
208
|
+
const clients = new Set<LspClient>();
|
|
209
|
+
|
|
210
|
+
for (const ext of this._registry.knownExtensions)
|
|
211
|
+
{
|
|
212
|
+
try
|
|
213
|
+
{
|
|
214
|
+
const client = await this.getOrStart(ext, cwd, capability);
|
|
215
|
+
|
|
216
|
+
if (client)
|
|
217
|
+
{
|
|
218
|
+
clients.add(client);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch
|
|
222
|
+
{
|
|
223
|
+
// A workspace may list servers that are not installed locally.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return [...clients];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Open one representative file for each configured language family. */
|
|
231
|
+
async prepareWorkspaceSymbols(cwd: string): Promise<LspClient[]>
|
|
232
|
+
{
|
|
233
|
+
const clients = await this.getWorkspaceClients(cwd);
|
|
234
|
+
const remainingExtensions = new Set(this._registry.knownExtensions);
|
|
235
|
+
const ignoredDirectories = new Set([".git", ".cache", "node_modules", "dist", "build"]);
|
|
236
|
+
|
|
237
|
+
const visit = async (directory: string): Promise<void> =>
|
|
238
|
+
{
|
|
239
|
+
if (remainingExtensions.size === 0)
|
|
240
|
+
{
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let entries;
|
|
245
|
+
|
|
246
|
+
try
|
|
247
|
+
{
|
|
248
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
249
|
+
}
|
|
250
|
+
catch
|
|
251
|
+
{
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const entry of entries)
|
|
256
|
+
{
|
|
257
|
+
if (remainingExtensions.size === 0)
|
|
258
|
+
{
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (entry.isDirectory())
|
|
263
|
+
{
|
|
264
|
+
if (!ignoredDirectories.has(entry.name))
|
|
265
|
+
{
|
|
266
|
+
await visit(path.join(directory, entry.name));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (!entry.isFile())
|
|
273
|
+
{
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const extension = path.extname(entry.name).toLowerCase();
|
|
278
|
+
|
|
279
|
+
if (!remainingExtensions.has(extension))
|
|
280
|
+
{
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const filePath = path.join(directory, entry.name);
|
|
285
|
+
const opened = await this.openFile(filePath, cwd, "symbols").catch(() => null);
|
|
286
|
+
|
|
287
|
+
if (opened)
|
|
288
|
+
{
|
|
289
|
+
remainingExtensions.delete(extension);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
await visit(cwd);
|
|
295
|
+
return clients;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Check if there's any LSP server configured for this file extension. */
|
|
299
|
+
hasServerFor(ext: string): boolean
|
|
300
|
+
{
|
|
301
|
+
return this._registry.resolve(ext).length > 0;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Resolve a file extension to its canonical LSP languageId. */
|
|
305
|
+
languageId(ext: string): string
|
|
306
|
+
{
|
|
307
|
+
return this._registry.languageId(ext);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** True if this URI was already opened via openFile. */
|
|
311
|
+
isOpen(uri: string): boolean
|
|
312
|
+
{
|
|
313
|
+
return this._openDocs.has(uri);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ── document helpers ───────────────────────────────────────────────
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Open a document in the appropriate LSP server and return the client.
|
|
320
|
+
* Returns null if no server handles this file.
|
|
321
|
+
*/
|
|
322
|
+
async openFile(
|
|
323
|
+
filePath: string,
|
|
324
|
+
cwd: string,
|
|
325
|
+
capability: "diagnostics" | "symbols" = "diagnostics",
|
|
326
|
+
): Promise<{ client: LspClient; uri: string; languageId: string; } | null>
|
|
327
|
+
{
|
|
328
|
+
const ext = filePath.slice(filePath.lastIndexOf(".")).toLowerCase();
|
|
329
|
+
const absolutePath = path.resolve(cwd, filePath);
|
|
330
|
+
const client = await this.getOrStart(ext, cwd, capability);
|
|
331
|
+
|
|
332
|
+
if (!client)
|
|
333
|
+
{
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const uri = client.toUri(absolutePath);
|
|
338
|
+
const resolved = this._registry.resolve(ext);
|
|
339
|
+
const languageId = resolved[0]?.languageId ?? "plaintext";
|
|
340
|
+
|
|
341
|
+
// Read file content for didOpen
|
|
342
|
+
// We use a minimal open — the server gets the text from disk next request
|
|
343
|
+
try
|
|
344
|
+
{
|
|
345
|
+
const { readFile } = await import("node:fs/promises");
|
|
346
|
+
const text = await readFile(absolutePath, "utf8");
|
|
347
|
+
client.openDocument(uri, text, languageId);
|
|
348
|
+
this._openDocs.add(uri);
|
|
349
|
+
}
|
|
350
|
+
catch
|
|
351
|
+
{
|
|
352
|
+
// File doesn't exist yet — server will pick it up on next change
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return { client, uri, languageId };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private _subscribeToPushDiagnostics(clientKey: string, client: LspClient): void
|
|
359
|
+
{
|
|
360
|
+
if (this._pushUnsubscribers.has(clientKey))
|
|
361
|
+
{
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const unsubscribe = client.onNotification("textDocument/publishDiagnostics", (params) =>
|
|
366
|
+
{
|
|
367
|
+
const notification = parsePushNotification(params);
|
|
368
|
+
|
|
369
|
+
if (
|
|
370
|
+
!notification || client.diagnosticMode !== "push" || client.hasActiveDiagnosticRequest(notification.uri)
|
|
371
|
+
)
|
|
372
|
+
{
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const currentVersion = client.documentVersion(notification.uri);
|
|
377
|
+
|
|
378
|
+
if (
|
|
379
|
+
notification.version !== undefined && currentVersion !== undefined
|
|
380
|
+
&& notification.version < currentVersion
|
|
381
|
+
)
|
|
382
|
+
{
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const key = `${client.serverId}:${notification.uri}`;
|
|
387
|
+
|
|
388
|
+
if (notification.diagnostics.length === 0)
|
|
389
|
+
{
|
|
390
|
+
this._pushFingerprints.delete(key);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const diagnostics = notification.diagnostics.map(toDiagnostic);
|
|
395
|
+
const fingerprint = JSON.stringify(diagnostics);
|
|
396
|
+
|
|
397
|
+
if (this._pushFingerprints.get(key) === fingerprint)
|
|
398
|
+
{
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
this._pushFingerprints.set(key, fingerprint);
|
|
403
|
+
const event: LspPushDiagnosticsEvent = {
|
|
404
|
+
serverId: client.serverId,
|
|
405
|
+
uri: notification.uri,
|
|
406
|
+
diagnostics,
|
|
407
|
+
...(notification.version === undefined ? {} : { version: notification.version }),
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
for (const handler of this._pushHandlers)
|
|
411
|
+
{
|
|
412
|
+
handler(event);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
this._pushUnsubscribers.set(clientKey, unsubscribe);
|
|
416
|
+
}
|
|
417
|
+
// ── cleanup ────────────────────────────────────────────────────────
|
|
418
|
+
|
|
419
|
+
async shutdownAll(): Promise<void>
|
|
420
|
+
{
|
|
421
|
+
this._disposed = true;
|
|
422
|
+
await Promise.allSettled(this._clientStarts.values());
|
|
423
|
+
|
|
424
|
+
const clients = [...this._clients.values()];
|
|
425
|
+
await Promise.all(clients.map((c) => c.shutdown()));
|
|
426
|
+
|
|
427
|
+
for (const unsubscribe of this._pushUnsubscribers.values())
|
|
428
|
+
{
|
|
429
|
+
unsubscribe();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
this._pushUnsubscribers.clear();
|
|
433
|
+
this._clientStarts.clear();
|
|
434
|
+
this._pushFingerprints.clear();
|
|
435
|
+
this._pushHandlers.clear();
|
|
436
|
+
this._clients.clear();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
dispose(): void
|
|
440
|
+
{
|
|
441
|
+
void this.shutdownAll();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function parsePushNotification(params: unknown): {
|
|
446
|
+
uri: string;
|
|
447
|
+
version?: number;
|
|
448
|
+
diagnostics: LspDiagnostic[];
|
|
449
|
+
} | undefined
|
|
450
|
+
{
|
|
451
|
+
if (params === null || typeof params !== "object")
|
|
452
|
+
{
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const value = params as { uri?: unknown; version?: unknown; diagnostics?: unknown; };
|
|
457
|
+
|
|
458
|
+
if (typeof value.uri !== "string" || !Array.isArray(value.diagnostics))
|
|
459
|
+
{
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return {
|
|
464
|
+
uri: value.uri,
|
|
465
|
+
diagnostics: value.diagnostics as LspDiagnostic[],
|
|
466
|
+
...(typeof value.version === "number" ? { version: value.version } : {}),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function toDiagnostic(diagnostic: LspDiagnostic): Diagnostic
|
|
471
|
+
{
|
|
472
|
+
return {
|
|
473
|
+
code: typeof diagnostic.code === "number" ? String(diagnostic.code) : (diagnostic.code ?? "LSP"),
|
|
474
|
+
message: diagnostic.message,
|
|
475
|
+
line: diagnostic.range.start.line + 1,
|
|
476
|
+
column: diagnostic.range.start.character + 1,
|
|
477
|
+
severity: diagnostic.severity === DiagnosticSeverity.Error
|
|
478
|
+
? "error"
|
|
479
|
+
: diagnostic.severity === DiagnosticSeverity.Warning
|
|
480
|
+
? "warning"
|
|
481
|
+
: diagnostic.severity === DiagnosticSeverity.Information
|
|
482
|
+
? "info"
|
|
483
|
+
: "hint",
|
|
484
|
+
};
|
|
485
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { LspClient } from "./client.js";
|
|
2
|
+
import type { LspPosition, LspRange } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export interface LspLocation
|
|
5
|
+
{
|
|
6
|
+
uri: string;
|
|
7
|
+
range: LspRange;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface LspCallHierarchyItem
|
|
11
|
+
{
|
|
12
|
+
name: string;
|
|
13
|
+
kind: number;
|
|
14
|
+
uri: string;
|
|
15
|
+
range: LspRange;
|
|
16
|
+
selectionRange: LspRange;
|
|
17
|
+
detail?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface LspIncomingCall
|
|
21
|
+
{
|
|
22
|
+
from: LspCallHierarchyItem;
|
|
23
|
+
fromRanges: LspRange[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface LspOutgoingCall
|
|
27
|
+
{
|
|
28
|
+
to: LspCallHierarchyItem;
|
|
29
|
+
fromRanges: LspRange[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LspCallHierarchyResult
|
|
33
|
+
{
|
|
34
|
+
items: LspCallHierarchyItem[];
|
|
35
|
+
incoming: LspIncomingCall[];
|
|
36
|
+
outgoing: LspOutgoingCall[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function requestReferences(
|
|
40
|
+
client: LspClient,
|
|
41
|
+
uri: string,
|
|
42
|
+
position: LspPosition,
|
|
43
|
+
): Promise<LspLocation[]>
|
|
44
|
+
{
|
|
45
|
+
const result = await client.sendRequest<LspLocation[] | null>("textDocument/references", {
|
|
46
|
+
textDocument: { uri },
|
|
47
|
+
position,
|
|
48
|
+
context: { includeDeclaration: true },
|
|
49
|
+
});
|
|
50
|
+
return result ?? [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function requestCallHierarchy(
|
|
54
|
+
client: LspClient,
|
|
55
|
+
uri: string,
|
|
56
|
+
position: LspPosition,
|
|
57
|
+
): Promise<LspCallHierarchyResult>
|
|
58
|
+
{
|
|
59
|
+
const items = await client.sendRequest<LspCallHierarchyItem[] | null>("textDocument/prepareCallHierarchy", {
|
|
60
|
+
textDocument: { uri },
|
|
61
|
+
position,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const firstItem = items?.[0];
|
|
65
|
+
|
|
66
|
+
if (!firstItem)
|
|
67
|
+
{
|
|
68
|
+
return { items: [], incoming: [], outgoing: [] };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const [incoming, outgoing] = await Promise.all([
|
|
72
|
+
client
|
|
73
|
+
.sendRequest<LspIncomingCall[] | null>("callHierarchy/incomingCalls", { item: firstItem })
|
|
74
|
+
.catch(() => []),
|
|
75
|
+
client
|
|
76
|
+
.sendRequest<LspOutgoingCall[] | null>("callHierarchy/outgoingCalls", { item: firstItem })
|
|
77
|
+
.catch(() => []),
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
items,
|
|
82
|
+
incoming: incoming ?? [],
|
|
83
|
+
outgoing: outgoing ?? [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { buildLanguageLookup, type LanguageLookup } from "./language-map.js";
|
|
5
|
+
|
|
6
|
+
import type { LspServersConfig, ResolvedServer, ServerConfig } from "./types.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* LspServerRegistry — loads lsp-servers.json and resolves
|
|
10
|
+
* file extensions to LSP server configurations.
|
|
11
|
+
*
|
|
12
|
+
* Thread-safe: all mutations happen at construction time.
|
|
13
|
+
*/
|
|
14
|
+
export class LspServerRegistry
|
|
15
|
+
{
|
|
16
|
+
private readonly _servers: Record<string, ServerConfig>;
|
|
17
|
+
private readonly _lookup: LanguageLookup;
|
|
18
|
+
|
|
19
|
+
private constructor(config: LspServersConfig)
|
|
20
|
+
{
|
|
21
|
+
this._servers = config.servers;
|
|
22
|
+
this._lookup = buildLanguageLookup(this._servers);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Load and parse the lsp-servers.json from the project package directory.
|
|
27
|
+
*/
|
|
28
|
+
static async fromPackageDir(packageDir: string): Promise<LspServerRegistry>
|
|
29
|
+
{
|
|
30
|
+
const configPath = path.join(packageDir, "lsp-servers.json");
|
|
31
|
+
const raw = await readFile(configPath, "utf8");
|
|
32
|
+
const config = JSON.parse(raw) as LspServersConfig;
|
|
33
|
+
return new LspServerRegistry(config);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create from an already-parsed config (for testing).
|
|
38
|
+
*/
|
|
39
|
+
static fromConfig(config: LspServersConfig): LspServerRegistry
|
|
40
|
+
{
|
|
41
|
+
return new LspServerRegistry(config);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a file extension (with or without leading dot) to its LSP servers.
|
|
46
|
+
* Returns empty array if no LSP server is configured for this extension.
|
|
47
|
+
*/
|
|
48
|
+
resolve(ext: string): ResolvedServer[]
|
|
49
|
+
{
|
|
50
|
+
const normalized = ext.startsWith(".") ? ext.toLowerCase() : `.${ext.toLowerCase()}`;
|
|
51
|
+
const serverIds = this._lookup.extToServerIds.get(normalized);
|
|
52
|
+
|
|
53
|
+
if (!serverIds || serverIds.length === 0)
|
|
54
|
+
{
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const languageId = this._lookup.extToLanguageId.get(normalized);
|
|
59
|
+
|
|
60
|
+
if (!languageId)
|
|
61
|
+
{
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return serverIds.map((serverId) => ({
|
|
66
|
+
serverId,
|
|
67
|
+
config: this._servers[serverId]!,
|
|
68
|
+
languageId,
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* All registered server configurations.
|
|
74
|
+
*/
|
|
75
|
+
get servers(): Readonly<Record<string, ServerConfig>>
|
|
76
|
+
{
|
|
77
|
+
return this._servers;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* All known extensions (with leading dot, lowercased).
|
|
82
|
+
*/
|
|
83
|
+
get knownExtensions(): ReadonlySet<string>
|
|
84
|
+
{
|
|
85
|
+
return new Set(this._lookup.extToLanguageId.keys());
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Resolve a file extension to the canonical LSP languageId.
|
|
90
|
+
* Returns the extension without dot as fallback if not found.
|
|
91
|
+
*/
|
|
92
|
+
languageId(ext: string): string
|
|
93
|
+
{
|
|
94
|
+
const normalized = ext.startsWith(".") ? ext.toLowerCase() : `.${ext.toLowerCase()}`;
|
|
95
|
+
return this._lookup.extToLanguageId.get(normalized) ?? ext.slice(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { LspClient } from "./client.js";
|
|
2
|
+
import type { LspPosition, LspTextEdit } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export interface LspDocumentChange
|
|
5
|
+
{
|
|
6
|
+
textDocument: { uri: string; };
|
|
7
|
+
edits: LspTextEdit[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface LspWorkspaceEdit
|
|
11
|
+
{
|
|
12
|
+
changes?: Record<string, LspTextEdit[]>;
|
|
13
|
+
documentChanges?: LspDocumentChange[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Request a rename edit set from a native LSP server. */
|
|
17
|
+
export async function requestRename(
|
|
18
|
+
client: LspClient,
|
|
19
|
+
uri: string,
|
|
20
|
+
position: LspPosition,
|
|
21
|
+
newName: string,
|
|
22
|
+
): Promise<LspWorkspaceEdit | null>
|
|
23
|
+
{
|
|
24
|
+
return await client.sendRequest<LspWorkspaceEdit | null>("textDocument/rename", {
|
|
25
|
+
textDocument: { uri },
|
|
26
|
+
position,
|
|
27
|
+
newName,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Flatten both WorkspaceEdit representations into per-file text edits. */
|
|
32
|
+
export function workspaceEditEntries(edit: LspWorkspaceEdit): { uri: string; edits: LspTextEdit[]; }[]
|
|
33
|
+
{
|
|
34
|
+
const entries = new Map<string, LspTextEdit[]>();
|
|
35
|
+
|
|
36
|
+
for (const [uri, edits] of Object.entries(edit.changes ?? {}))
|
|
37
|
+
{
|
|
38
|
+
entries.set(uri, [...(entries.get(uri) ?? []), ...edits]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const change of edit.documentChanges ?? [])
|
|
42
|
+
{
|
|
43
|
+
entries.set(change.textDocument.uri, [
|
|
44
|
+
...(entries.get(change.textDocument.uri) ?? []),
|
|
45
|
+
...change.edits,
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return [...entries].map(([uri, edits]) => ({ uri, edits }));
|
|
50
|
+
}
|