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,463 @@
|
|
|
1
|
+
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import spawnProcess from "cross-spawn";
|
|
4
|
+
import {
|
|
5
|
+
createMessageConnection,
|
|
6
|
+
type MessageConnection,
|
|
7
|
+
StreamMessageReader,
|
|
8
|
+
StreamMessageWriter,
|
|
9
|
+
} from "vscode-jsonrpc/node";
|
|
10
|
+
import { URI } from "vscode-uri";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generic LSP client — JSON-RPC over stdio.
|
|
14
|
+
*
|
|
15
|
+
* Language-agnostic. One instance per LSP server process.
|
|
16
|
+
* Handles initialize → initialized → keep-alive → shutdown lifecycle.
|
|
17
|
+
*/
|
|
18
|
+
export class LspClient
|
|
19
|
+
{
|
|
20
|
+
private _process: ChildProcess | null = null;
|
|
21
|
+
private _connection: MessageConnection | null = null;
|
|
22
|
+
private _initialized = false;
|
|
23
|
+
private _serverCapabilities: Record<string, unknown> | null = null;
|
|
24
|
+
private _disposed = false;
|
|
25
|
+
|
|
26
|
+
private _crashed = false;
|
|
27
|
+
private readonly _handlers = new Map<string, ((params: unknown) => void)[]>();
|
|
28
|
+
private readonly _documentVersions = new Map<string, number>();
|
|
29
|
+
private _diagnosticMode: "unknown" | "pull" | "push" = "unknown";
|
|
30
|
+
private readonly _activeDiagnosticRequests = new Set<string>();
|
|
31
|
+
|
|
32
|
+
readonly serverId: string;
|
|
33
|
+
readonly rootUri: string;
|
|
34
|
+
private readonly _command: string[];
|
|
35
|
+
private readonly _args: string[];
|
|
36
|
+
private readonly _env: Record<string, string>;
|
|
37
|
+
private readonly _initOptions: Record<string, unknown> | undefined;
|
|
38
|
+
|
|
39
|
+
constructor(params: {
|
|
40
|
+
serverId: string;
|
|
41
|
+
rootUri: string;
|
|
42
|
+
command: string[];
|
|
43
|
+
env?: Record<string, string>;
|
|
44
|
+
initOptions?: Record<string, unknown>;
|
|
45
|
+
})
|
|
46
|
+
{
|
|
47
|
+
this.serverId = params.serverId;
|
|
48
|
+
this.rootUri = params.rootUri;
|
|
49
|
+
this._command = params.command;
|
|
50
|
+
this._args = params.command.slice(1);
|
|
51
|
+
this._env = params.env ?? {};
|
|
52
|
+
this._initOptions = params.initOptions;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── lifecycle ──────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
get ready(): boolean
|
|
58
|
+
{
|
|
59
|
+
return this._initialized && !this._disposed;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get crashed(): boolean
|
|
63
|
+
{
|
|
64
|
+
return this._crashed;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get pid(): number | null
|
|
68
|
+
{
|
|
69
|
+
return this._process?.pid ?? null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get diagnosticMode(): "unknown" | "pull" | "push"
|
|
73
|
+
{
|
|
74
|
+
return this._diagnosticMode;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setDiagnosticMode(mode: "pull" | "push"): void
|
|
78
|
+
{
|
|
79
|
+
this._diagnosticMode = mode;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get hasServerDiagnosticsCapability(): boolean
|
|
83
|
+
{
|
|
84
|
+
if (!this._serverCapabilities)
|
|
85
|
+
{
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const td = this._serverCapabilities.textDocument as Record<string, unknown> | undefined;
|
|
90
|
+
|
|
91
|
+
if (!td)
|
|
92
|
+
{
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Pull-model diagnostic (LSP 3.17+)
|
|
97
|
+
if (td.diagnostic)
|
|
98
|
+
{
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Push-model publishDiagnostics
|
|
103
|
+
if (td.publishDiagnostics)
|
|
104
|
+
{
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get hasFoldingRangeCapability(): boolean
|
|
112
|
+
{
|
|
113
|
+
const provider = this._serverCapabilities?.foldingRangeProvider;
|
|
114
|
+
return provider === true || (typeof provider === "object" && provider !== null);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
documentVersion(uri: string): number | undefined
|
|
118
|
+
{
|
|
119
|
+
return this._documentVersions.get(uri);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
beginDiagnosticRequest(uri: string): void
|
|
123
|
+
{
|
|
124
|
+
this._activeDiagnosticRequests.add(uri);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
endDiagnosticRequest(uri: string): void
|
|
128
|
+
{
|
|
129
|
+
this._activeDiagnosticRequests.delete(uri);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
hasActiveDiagnosticRequest(uri: string): boolean
|
|
133
|
+
{
|
|
134
|
+
return this._activeDiagnosticRequests.has(uri);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async start(): Promise<void>
|
|
138
|
+
{
|
|
139
|
+
if (this._initialized)
|
|
140
|
+
{
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (this._disposed)
|
|
145
|
+
{
|
|
146
|
+
throw new Error(`[lsp] ${this.serverId}: disposed`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const bin = this._command[0]!;
|
|
150
|
+
|
|
151
|
+
const childProcess = spawnProcess(bin, this._args, {
|
|
152
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
153
|
+
cwd: URI.parse(this.rootUri).fsPath,
|
|
154
|
+
env: { ...process.env, ...this._env },
|
|
155
|
+
});
|
|
156
|
+
this._process = childProcess;
|
|
157
|
+
const spawnPromise = waitForSpawn(childProcess);
|
|
158
|
+
|
|
159
|
+
// Consume process stream errors so a failed optional server cannot
|
|
160
|
+
// become an uncaught exception in the host process.
|
|
161
|
+
childProcess.stdin?.on("error", () => void 0);
|
|
162
|
+
childProcess.stdout?.on("error", () => void 0);
|
|
163
|
+
childProcess.stderr?.on("error", () => void 0);
|
|
164
|
+
|
|
165
|
+
childProcess.on("error", (err) =>
|
|
166
|
+
{
|
|
167
|
+
const code = "code" in err ? (err as { code?: unknown; }).code : undefined;
|
|
168
|
+
|
|
169
|
+
if (code !== "ENOENT")
|
|
170
|
+
{
|
|
171
|
+
console.error(`[lsp] ${this.serverId}: spawn failed:`, err);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this._crashed = true;
|
|
175
|
+
this._connection?.dispose();
|
|
176
|
+
this._connection = null;
|
|
177
|
+
this._process = null;
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
childProcess.on("exit", (code, _signal) =>
|
|
181
|
+
{
|
|
182
|
+
if (!this._disposed && code !== 0 && code !== null)
|
|
183
|
+
{
|
|
184
|
+
this._crashed = true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this._connection?.dispose();
|
|
188
|
+
this._connection = null;
|
|
189
|
+
this._process = null;
|
|
190
|
+
this._initialized = false;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await spawnPromise;
|
|
194
|
+
this._connection = createMessageConnection(
|
|
195
|
+
new StreamMessageReader(childProcess.stdout!),
|
|
196
|
+
new StreamMessageWriter(childProcess.stdin!),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
this._connection.onError((err) =>
|
|
200
|
+
{
|
|
201
|
+
console.error(`[lsp] ${this.serverId}: connection error:`, err);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
this._connection.listen();
|
|
205
|
+
|
|
206
|
+
// Forward all incoming notifications to registered handlers
|
|
207
|
+
this._connection.onNotification((method, ...params) =>
|
|
208
|
+
{
|
|
209
|
+
for (const handler of this._handlers.get(method) ?? [])
|
|
210
|
+
{
|
|
211
|
+
handler(params[0] as unknown);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
interface InitResult
|
|
216
|
+
{
|
|
217
|
+
capabilities: Record<string, unknown>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const initResult: InitResult = await this._connection.sendRequest("initialize", {
|
|
221
|
+
processId: process.pid,
|
|
222
|
+
rootUri: this.rootUri,
|
|
223
|
+
capabilities: {
|
|
224
|
+
workspace: {
|
|
225
|
+
applyEdit: false,
|
|
226
|
+
symbol: { dynamicRegistration: false },
|
|
227
|
+
},
|
|
228
|
+
textDocument: {
|
|
229
|
+
synchronization: { didOpen: true, didChange: true, didClose: true },
|
|
230
|
+
publishDiagnostics: { relatedInformation: true },
|
|
231
|
+
documentSymbol: { hierarchicalDocumentSymbolSupport: true },
|
|
232
|
+
foldingRange: { lineFoldingOnly: true },
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
initializationOptions: this._initOptions,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
void this._connection.sendNotification("initialized", {
|
|
239
|
+
capabilities: initResult.capabilities,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
this._initialized = true;
|
|
243
|
+
this._serverCapabilities = initResult.capabilities;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
touch(): void
|
|
247
|
+
{
|
|
248
|
+
// LSP server lives for the session duration — no idle timeout
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async restart(): Promise<void>
|
|
252
|
+
{
|
|
253
|
+
this._connection?.dispose();
|
|
254
|
+
this._connection = null;
|
|
255
|
+
this._process = null;
|
|
256
|
+
this._initialized = false;
|
|
257
|
+
this._crashed = false;
|
|
258
|
+
this._disposed = false;
|
|
259
|
+
this._documentVersions.clear();
|
|
260
|
+
this._diagnosticMode = "unknown";
|
|
261
|
+
this._activeDiagnosticRequests.clear();
|
|
262
|
+
this._serverCapabilities = null;
|
|
263
|
+
await this.start();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── LSP protocol ───────────────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
async sendRequest<T = unknown>(method: string, params: unknown): Promise<T>
|
|
269
|
+
{
|
|
270
|
+
this._assertReady();
|
|
271
|
+
return this._connection!.sendRequest(method, params);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
sendNotification(method: string, params: unknown): void
|
|
275
|
+
{
|
|
276
|
+
this._assertReady();
|
|
277
|
+
void this._connection!.sendNotification(method, params);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Register a handler for an incoming notification.
|
|
282
|
+
*
|
|
283
|
+
* Multiple handlers can be registered for the same method.
|
|
284
|
+
* Returns a function to unregister.
|
|
285
|
+
*/
|
|
286
|
+
onNotification(method: string, handler: (params: unknown) => void): () => void
|
|
287
|
+
{
|
|
288
|
+
const list = this._handlers.get(method) ?? [];
|
|
289
|
+
list.push(handler);
|
|
290
|
+
this._handlers.set(method, list);
|
|
291
|
+
return () =>
|
|
292
|
+
{
|
|
293
|
+
const idx = list.indexOf(handler);
|
|
294
|
+
|
|
295
|
+
if (idx !== -1)
|
|
296
|
+
{
|
|
297
|
+
list.splice(idx, 1);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ── document management ────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
toUri(input: string): string
|
|
305
|
+
{
|
|
306
|
+
if (input.startsWith("file://"))
|
|
307
|
+
{
|
|
308
|
+
return input;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return URI.file(input).toString();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
openDocument(uri: string, text: string, languageId: string, version = 1): void
|
|
315
|
+
{
|
|
316
|
+
const currentVersion = this._documentVersions.get(uri);
|
|
317
|
+
|
|
318
|
+
if (currentVersion !== undefined)
|
|
319
|
+
{
|
|
320
|
+
this.changeDocument(uri, text, Math.max(version, currentVersion + 1));
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
this.sendNotification("textDocument/didOpen", {
|
|
325
|
+
textDocument: { uri, languageId, version, text },
|
|
326
|
+
});
|
|
327
|
+
this._documentVersions.set(uri, version);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
syncDocument(uri: string, text: string, languageId: string): void
|
|
331
|
+
{
|
|
332
|
+
const currentVersion = this._documentVersions.get(uri);
|
|
333
|
+
|
|
334
|
+
if (currentVersion === undefined)
|
|
335
|
+
{
|
|
336
|
+
this.openDocument(uri, text, languageId);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
this.changeDocument(uri, text, currentVersion + 1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
changeDocument(uri: string, text: string, version: number): void
|
|
344
|
+
{
|
|
345
|
+
const currentVersion = this._documentVersions.get(uri);
|
|
346
|
+
const nextVersion = Math.max(version, (currentVersion ?? 0) + 1);
|
|
347
|
+
this.sendNotification("textDocument/didChange", {
|
|
348
|
+
textDocument: { uri, version: nextVersion },
|
|
349
|
+
contentChanges: [{ text }],
|
|
350
|
+
});
|
|
351
|
+
this._documentVersions.set(uri, nextVersion);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
closeDocument(uri: string): void
|
|
355
|
+
{
|
|
356
|
+
this.sendNotification("textDocument/didClose", { textDocument: { uri } });
|
|
357
|
+
this._documentVersions.delete(uri);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ── cleanup ────────────────────────────────────────────────────────
|
|
361
|
+
|
|
362
|
+
async shutdown(): Promise<void>
|
|
363
|
+
{
|
|
364
|
+
if (this._disposed)
|
|
365
|
+
{
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
this._disposed = true;
|
|
370
|
+
|
|
371
|
+
if (this._connection && this._initialized)
|
|
372
|
+
{
|
|
373
|
+
try
|
|
374
|
+
{
|
|
375
|
+
await this._connection.sendRequest("shutdown");
|
|
376
|
+
await this._connection.sendNotification("exit").catch(() =>
|
|
377
|
+
{/* ok */});
|
|
378
|
+
}
|
|
379
|
+
catch
|
|
380
|
+
{
|
|
381
|
+
/* server already dead */
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
this._connection?.dispose();
|
|
386
|
+
this._connection = null;
|
|
387
|
+
|
|
388
|
+
if (this._process && !this._process.killed)
|
|
389
|
+
{
|
|
390
|
+
this._process.kill("SIGTERM");
|
|
391
|
+
setTimeout(() =>
|
|
392
|
+
{
|
|
393
|
+
if (this._process && !this._process.killed)
|
|
394
|
+
{
|
|
395
|
+
this._process.kill("SIGKILL");
|
|
396
|
+
}
|
|
397
|
+
}, 2000).unref();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
this._initialized = false;
|
|
401
|
+
this._documentVersions.clear();
|
|
402
|
+
this._diagnosticMode = "unknown";
|
|
403
|
+
this._activeDiagnosticRequests.clear();
|
|
404
|
+
this._serverCapabilities = null;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
dispose(): void
|
|
408
|
+
{
|
|
409
|
+
void this.shutdown();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ── internal ───────────────────────────────────────────────────────
|
|
413
|
+
|
|
414
|
+
private _assertReady(): void
|
|
415
|
+
{
|
|
416
|
+
if (this._disposed)
|
|
417
|
+
{
|
|
418
|
+
throw new Error(`[lsp] ${this.serverId}: disposed`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (this._crashed)
|
|
422
|
+
{
|
|
423
|
+
throw new Error(`[lsp] ${this.serverId}: crashed — call restart()`);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (!this._initialized)
|
|
427
|
+
{
|
|
428
|
+
throw new Error(`[lsp] ${this.serverId}: not started — call start()`);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (!this._connection)
|
|
432
|
+
{
|
|
433
|
+
throw new Error(`[lsp] ${this.serverId}: connection lost`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function waitForSpawn(childProcess: ChildProcess): Promise<void>
|
|
439
|
+
{
|
|
440
|
+
return new Promise<void>((resolve, reject) =>
|
|
441
|
+
{
|
|
442
|
+
const cleanup = () =>
|
|
443
|
+
{
|
|
444
|
+
childProcess.off("spawn", onSpawn);
|
|
445
|
+
childProcess.off("error", onError);
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const onSpawn = () =>
|
|
449
|
+
{
|
|
450
|
+
cleanup();
|
|
451
|
+
resolve();
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const onError = (error: Error) =>
|
|
455
|
+
{
|
|
456
|
+
cleanup();
|
|
457
|
+
reject(error);
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
childProcess.once("spawn", onSpawn);
|
|
461
|
+
childProcess.once("error", onError);
|
|
462
|
+
});
|
|
463
|
+
}
|