pi-agent-ide 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +1 -1
- package/dist/{chunk-ZXO4D5UB.js → chunk-2AANEKFS.js} +1 -1
- package/dist/{chunk-BU7IZLKB.js → chunk-2DSY4U73.js} +1 -1
- package/dist/chunk-2YO6RVX4.js +1 -0
- package/dist/{chunk-WES2E4VR.js → chunk-33U3RUM3.js} +1 -1
- package/dist/{chunk-CJPS4GXD.js → chunk-34IYWKY5.js} +1 -1
- package/dist/{chunk-2TTSJOLO.js → chunk-4CSNQX54.js} +1 -1
- package/dist/{chunk-DAZQSXUW.js → chunk-53IV6EKV.js} +1 -1
- package/dist/{chunk-7PVDTMEM.js → chunk-5AROEOJB.js} +1 -1
- package/dist/{chunk-IG5DXVDJ.js → chunk-5D4C225L.js} +1 -1
- package/dist/{chunk-GHO6TCPJ.js → chunk-5DN2XBVI.js} +1 -1
- package/dist/{chunk-FHRHYY4M.js → chunk-5W6QQZFI.js} +1 -1
- package/dist/{chunk-5PC5INOL.js → chunk-6W4OJLCJ.js} +1 -1
- package/dist/chunk-6ZYCTWQE.js +1 -0
- package/dist/{chunk-B25LXXNV.js → chunk-72FL5FHZ.js} +1 -1
- package/dist/{chunk-BB4A5UI3.js → chunk-7JWZPJI5.js} +1 -1
- package/dist/{chunk-T3Z4KXOX.js → chunk-AMSNDWBT.js} +1 -1
- package/dist/{chunk-DFXXT6MJ.js → chunk-APWMLLSE.js} +6 -6
- package/dist/{chunk-NA2NEU4V.js → chunk-B5UJCNQU.js} +1 -1
- package/dist/chunk-BMSAVDRD.js +13 -0
- package/dist/{chunk-MPNE25CY.js → chunk-BRJIXNFU.js} +1 -1
- package/dist/chunk-C2GZLLSP.js +5 -0
- package/dist/{chunk-XCPIIDFS.js → chunk-DHOIQZUF.js} +1 -1
- package/dist/chunk-ECSMTGVM.js +6 -0
- package/dist/{chunk-DEP55R35.js → chunk-EHFWODRT.js} +1 -1
- package/dist/{chunk-6WCHBHFW.js → chunk-EWTVVPUA.js} +1 -1
- package/dist/{chunk-H3GEEOOL.js → chunk-FBR7ZLLN.js} +1 -1
- package/dist/{chunk-UD3DMY3Q.js → chunk-FGN2ZMEN.js} +1 -1
- package/dist/{chunk-MKDOT76B.js → chunk-FJSYWOE6.js} +1 -1
- package/dist/{chunk-LF325WYO.js → chunk-FTECKRK6.js} +1 -1
- package/dist/chunk-GRZTKMXQ.js +1 -0
- package/dist/chunk-H6FEBUAP.js +1 -0
- package/dist/{chunk-FYOU4RBH.js → chunk-HFCHOFLV.js} +1 -1
- package/dist/chunk-HFF4GY7R.js +3 -0
- package/dist/{chunk-QJ6V5IAY.js → chunk-HJXSEPO7.js} +14 -12
- package/dist/{chunk-SRFWT562.js → chunk-HSEDKYH4.js} +1 -1
- package/dist/{chunk-6P7LTQZT.js → chunk-II7AOJNH.js} +1 -1
- package/dist/chunk-J6CDIH3S.js +84 -0
- package/dist/{chunk-USG6WHAT.js → chunk-JHWLRL4U.js} +1 -1
- package/dist/{chunk-35LZOKEW.js → chunk-JMQ67UNK.js} +1 -1
- package/dist/{chunk-7OUML24Z.js → chunk-JRIP33PC.js} +1 -1
- package/dist/chunk-JXULBI4S.js +2 -0
- package/dist/chunk-JYITLCXC.js +1 -0
- package/dist/{chunk-4IWEKRSP.js → chunk-KJAR2WDO.js} +1 -1
- package/dist/{chunk-GS5ZRTUG.js → chunk-KQV2ZXLP.js} +1 -1
- package/dist/{chunk-AMIIOWFL.js → chunk-KX7MG72M.js} +1 -1
- package/dist/{chunk-HGCJDIRR.js → chunk-LIGOOMJS.js} +5 -5
- package/dist/{chunk-OMNKD7WW.js → chunk-LY2UANKU.js} +3 -3
- package/dist/chunk-M7P7V4WI.js +25 -0
- package/dist/chunk-N2NEFXHB.js +13 -0
- package/dist/{chunk-2TZDG2JH.js → chunk-NF74ITWT.js} +2 -2
- package/dist/{chunk-AP2BOC24.js → chunk-NQYUIQRH.js} +1 -1
- package/dist/{chunk-7C73WVPB.js → chunk-OCU6NW5Y.js} +1 -1
- package/dist/chunk-OIEA4QWF.js +4 -0
- package/dist/{chunk-FXPY3V4L.js → chunk-ON5HDFNL.js} +1 -1
- package/dist/{chunk-U2N73BUY.js → chunk-P43GGKUC.js} +5 -5
- package/dist/{chunk-5BGWNYQS.js → chunk-P7FUD4WY.js} +1 -1
- package/dist/{chunk-VMLPXSMK.js → chunk-PPCWY4BB.js} +1 -1
- package/dist/{chunk-YPYROPQF.js → chunk-QGXZ4RWX.js} +1 -1
- package/dist/chunk-S3T5NOSL.js +1 -0
- package/dist/chunk-S7E2D5K7.js +5 -0
- package/dist/{chunk-DDH3FP4G.js → chunk-SIYPD5MM.js} +3 -3
- package/dist/{chunk-6A3ORNW3.js → chunk-T5ACAOKJ.js} +3 -3
- package/dist/chunk-TILMPAF2.js +1 -0
- package/dist/{chunk-RIJRPAL2.js → chunk-TSNY2FSU.js} +1 -1
- package/dist/{chunk-UI4KSKS3.js → chunk-TWJINFQB.js} +4 -4
- package/dist/chunk-TWQ6ACOI.js +1 -0
- package/dist/chunk-UDVVKVG4.js +1 -0
- package/dist/{chunk-WQIMM4SU.js → chunk-V2D5MLGE.js} +1 -1
- package/dist/{chunk-PQWANILR.js → chunk-VDSSAP6Y.js} +1 -1
- package/dist/{chunk-AVJVTF5H.js → chunk-VHYJTAXX.js} +1 -1
- package/dist/{chunk-MJFY4RGT.js → chunk-WCSWQDJ2.js} +1 -1
- package/dist/{chunk-JWSJCEIB.js → chunk-WQTF6Q2X.js} +1 -1
- package/dist/chunk-YFPU2LRR.js +23 -0
- package/dist/{chunk-KWJD7FBS.js → chunk-YLEERRX3.js} +14 -14
- package/dist/chunk-YNOR4LIE.js +1 -0
- package/dist/{chunk-WEE3NM6L.js → chunk-YOJHCARZ.js} +1 -1
- package/dist/chunk-YPTDPMK5.js +1 -0
- package/dist/{chunk-GXL4NMHR.js → chunk-YZTVC7ME.js} +1 -1
- package/dist/entry-0.js +1 -1
- package/dist/entry-10.js +1 -1
- package/dist/entry-11.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-19.js +1 -1
- package/dist/entry-2.js +1 -1
- package/dist/entry-20.js +1 -1
- package/dist/entry-21.js +1 -1
- package/dist/entry-22.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-31.js +2 -2
- package/dist/entry-32.js +1 -1
- package/dist/entry-33.js +1 -1
- package/dist/entry-34.js +1 -1
- package/dist/entry-35.js +1 -1
- package/dist/entry-36.js +1 -1
- package/dist/entry-37.js +1 -1
- package/dist/entry-38.js +13 -13
- package/dist/entry-39.js +1 -1
- package/dist/entry-4.js +1 -1
- package/dist/entry-40.js +1 -1
- package/dist/entry-41.js +1 -1
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-48.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-57.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-63.js +1 -1
- package/dist/entry-64.js +1 -1
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-72.js +1 -1
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-77.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/entry-8.js +1 -1
- package/dist/entry-82.js +1 -1
- package/dist/entry-84.js +1 -1
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/entry-87.js +1 -1
- package/dist/entry-90.js +1 -1
- package/dist/entry-91.js +1 -1
- package/dist/entry-92.js +1 -1
- package/dist/entry-93.js +1 -1
- package/dist/entry-94.js +1 -1
- package/dist/pi-agent-ide.js +11 -11
- package/docs/development.md +2 -0
- package/docs/generated/tool-catalog/python.md +1 -0
- package/docs/tools.md +2 -0
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-doctor/src/connect-plugin.ts +2 -2
- package/node_modules/pi-agent-doctor/src/evidence.ts +1 -1
- package/node_modules/pi-agent-doctor/src/fixtures/executable-probe.ts +2 -2
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +4 -4
- package/node_modules/pi-agent-doctor/src/project-probes.ts +2 -2
- package/node_modules/pi-agent-doctor/src/workspace.ts +2 -2
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/index.ts +2 -2
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem/src/file-write-lock.ts +70 -0
- package/node_modules/pi-agent-filesystem/src/replace-file.ts +50 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +28 -8
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/index.ts +1 -1
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-jq/src/api/jq.ts +1 -1
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/index.ts +1 -1
- package/node_modules/pi-agent-ide-ast/package.json +13 -13
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +33 -11
- package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +60 -55
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +4 -3
- package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -10
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +3 -3
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +35 -8
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +161 -23
- package/node_modules/pi-agent-ide-ast/src/tool-ast-search.ts +1 -1
- package/node_modules/pi-agent-ide-changes/index.ts +9 -9
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +4 -4
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +1 -1
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +4 -4
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +1 -1
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +4 -4
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +5 -5
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +6 -6
- package/node_modules/pi-agent-ide-formatter/index.ts +5 -5
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +2 -2
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +2 -2
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +1 -1
- package/node_modules/pi-agent-ide-languages/index.ts +1 -1
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/index.ts +9 -9
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lint/src/catalog.ts +4 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +15 -6
- package/node_modules/pi-agent-ide-lint/src/diagnostics.ts +8 -14
- package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +3 -3
- package/node_modules/pi-agent-ide-lint/src/registry.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/index.ts +37 -16
- package/node_modules/pi-agent-ide-lsp/package.json +12 -12
- package/node_modules/pi-agent-ide-lsp/src/catalog.ts +12 -1
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +21 -14
- package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +63 -20
- package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +4 -4
- package/node_modules/pi-agent-ide-lsp/src/idle-timeout.ts +15 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/abort.ts +11 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +434 -80
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +121 -35
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostic-adapters.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +26 -12
- package/node_modules/pi-agent-ide-lsp/src/lsp/document-leases.ts +31 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/errors.ts +4 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/file-watchers.ts +1 -77
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +19 -19
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +5 -4
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +59 -28
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +42 -22
- package/node_modules/pi-agent-ide-lsp/src/lsp/owner-transport.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/position-map.ts +52 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +2 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +2 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +325 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +797 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/shared-servers.ts +322 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/source-changes.ts +29 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +76 -17
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +3 -3
- package/node_modules/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/manager-provider.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +16 -8
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +149 -134
- package/node_modules/pi-agent-ide-lsp/src/tool-lsp-search.ts +1 -1
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-image/src/index.ts +1 -1
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-pdf/src/index.ts +1 -1
- package/node_modules/pi-agent-read/index.ts +1 -1
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +1 -1
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +1 -1
- package/node_modules/pi-agent-read/src/api/rendering.ts +2 -2
- package/node_modules/pi-agent-read/src/api/tools/read.ts +8 -2
- package/node_modules/pi-agent-read/src/core/extension.ts +4 -4
- package/node_modules/pi-agent-read/src/core/read-core.ts +4 -4
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +2 -2
- package/node_modules/pi-agent-read/src/core/tools/read/persisted-result.ts +1 -1
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +3 -3
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +4 -4
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +21 -14
- package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +24 -18
- package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +2 -2
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +44 -18
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +4 -4
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +4 -4
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +3 -3
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +2 -2
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +2 -2
- package/node_modules/pi-agent-resource/src/index.ts +19 -19
- package/node_modules/pi-agent-resource/src/resolver.ts +1 -1
- package/node_modules/pi-agent-resource/src/resource-access.ts +1 -1
- package/node_modules/pi-agent-resource/src/resource-error.ts +1 -1
- package/node_modules/pi-agent-resource/src/resource.ts +1 -1
- package/node_modules/pi-agent-resource/src/result-images.ts +1 -1
- package/node_modules/pi-agent-resource/src/result-targets.ts +23 -2
- package/node_modules/pi-agent-resource/src/temp-resource-store.ts +2 -2
- package/node_modules/pi-agent-resource/src/tool-result.ts +2 -2
- package/node_modules/pi-agent-resource/src/validation.ts +3 -3
- package/node_modules/pi-agent-search/index.ts +1 -1
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +1 -1
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +2 -2
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-search/src/api/presentation.ts +1 -1
- package/node_modules/pi-agent-search/src/api/search-scope.ts +1 -1
- package/node_modules/pi-agent-search/src/api/search.ts +7 -7
- package/node_modules/pi-agent-search/src/core/extension.ts +7 -7
- package/node_modules/pi-agent-search/src/core/search-core.ts +3 -3
- package/node_modules/pi-agent-search-text/index.ts +8 -8
- package/node_modules/pi-agent-search-text/package.json +10 -10
- package/node_modules/pi-agent-search-text/src/doctor-plugin.ts +1 -1
- package/node_modules/pi-agent-search-text/src/file-search.ts +1 -1
- package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +2 -2
- package/node_modules/pi-agent-search-text/src/persisted-result.ts +1 -1
- package/node_modules/pi-agent-search-text/src/resolvers.ts +9 -9
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +4 -4
- package/node_modules/pi-agent-search-text/src/search-backend.ts +3 -3
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +2 -2
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +3 -3
- package/node_modules/pi-agent-search-text/src/search-result.ts +2 -2
- package/node_modules/pi-agent-search-text/src/search-session.ts +132 -67
- package/node_modules/pi-agent-search-text/src/tool-file-search.ts +1 -1
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/index.ts +7 -7
- package/node_modules/pi-agent-text/src/source-line.ts +1 -1
- package/node_modules/pi-agent-text/src/text-document.ts +50 -2
- package/node_modules/pi-agent-text-anchor-constant/index.ts +1 -1
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/index.ts +2 -2
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +63 -48
- package/node_modules/pi-agent-text-anchor-exact/src/recovery.ts +3 -3
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +2 -2
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +23 -12
- package/node_modules/pi-agent-text-editor/index.ts +5 -5
- package/node_modules/pi-agent-text-editor/package.json +9 -9
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/file-operations.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/file-transfers.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/api/native-files.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +14 -14
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +13 -13
- package/node_modules/pi-agent-text-editor/src/core/file-operation-guards.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +6 -6
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/core/image-write.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +11 -6
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +213 -20
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +39 -3
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +6 -6
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +22 -22
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/read-fragment-resolver.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/source-change-retry.ts +41 -0
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +4 -7
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +34 -21
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/text-edit-origin.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +72 -30
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +211 -159
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +7 -7
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -5
- package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +3 -3
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +2 -2
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -4
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +2 -2
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +3 -3
- package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +2 -2
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +7 -7
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +32 -9
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- package/node_modules/pi-agent-tool-ui/src/index.ts +1 -1
- package/node_modules/pi-agent-tool-ui/src/result-panel.ts +1 -1
- package/node_modules/pi-agent-web/index.ts +3 -3
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/src/doctor-plugin.ts +1 -1
- package/node_modules/pi-agent-web/src/resolver.ts +1 -1
- package/node_modules/pi-agent-web-html/index.ts +1 -1
- package/node_modules/pi-agent-web-html/package.json +2 -2
- package/node_modules/pi-agent-web-html/src/html-converter.ts +1 -1
- package/node_modules/pi-agent-web-image/package.json +3 -3
- package/node_modules/pi-agent-web-pdf/package.json +3 -3
- package/node_modules/pi-agent-web-text/package.json +3 -3
- package/package.json +36 -36
- package/src/api/code-view.ts +3 -3
- package/src/api/connect-plugin.ts +1 -1
- package/src/api/connect-tip-provider.ts +2 -2
- package/src/api/doctor-runtime.ts +1 -1
- package/src/api/doctor.ts +1 -1
- package/src/api/hooks.ts +2 -2
- package/src/api/plugin-protocol.ts +1 -1
- package/src/api/settings.ts +6 -1
- package/src/api/standalone.ts +1 -1
- package/src/api/tips.ts +1 -1
- package/src/api/tool-config/linters.json +1 -1
- package/src/api/tool-config/lsp-servers.json +11 -0
- package/src/api/tool-config.ts +45 -5
- package/src/api/toolchain.ts +3 -3
- package/src/backend/config.ts +2 -2
- package/src/backend/configured-process.ts +5 -5
- package/src/backend/dap-java-transport.ts +6 -6
- package/src/backend/dap-node-transport.ts +5 -5
- package/src/backend/dap-tcp-transport.ts +3 -3
- package/src/backend/dap-transport.ts +5 -5
- package/src/backend/debugger-registration.ts +7 -7
- package/src/backend/debugger-workspace-owner.ts +10 -10
- package/src/backend/doctor-registration.ts +5 -5
- package/src/backend/doctor-workspace.ts +13 -13
- package/src/backend/file-operation-resolver.ts +5 -5
- package/src/backend/file-revision.ts +1 -1
- package/src/backend/file-transfer.ts +4 -4
- package/src/backend/formatter-registration.ts +11 -11
- package/src/backend/git-registration.ts +4 -4
- package/src/backend/index.ts +3 -3
- package/src/backend/lint-registration.ts +11 -11
- package/src/backend/lsp-file-watchers.ts +5 -5
- package/src/backend/lsp-registration.ts +11 -11
- package/src/backend/lsp-transport.ts +7 -7
- package/src/backend/lsp-workspace-owner.ts +4 -4
- package/src/backend/object-transfer.ts +5 -5
- package/src/backend/owned-command.ts +2 -2
- package/src/backend/owned-process-stop.ts +4 -4
- package/src/backend/owned-read-command.ts +2 -2
- package/src/backend/process-environment.ts +2 -2
- package/src/backend/process-metadata.ts +2 -2
- package/src/backend/recipe-evidence.ts +2 -2
- package/src/backend/registration.ts +8 -8
- package/src/backend/registry.ts +2 -2
- package/src/backend/resource-resolver.ts +2 -2
- package/src/backend/search-environment.ts +3 -3
- package/src/backend/ssh-channel.ts +3 -3
- package/src/backend/ssh-transport.ts +2 -2
- package/src/backend/ssh.ts +6 -6
- package/src/backend/tool-config-access.ts +4 -4
- package/src/backend/tool-project.ts +5 -5
- package/src/backend/web-browser.ts +3 -3
- package/src/backend/web-http.ts +2 -2
- package/src/backend/web-owner.ts +5 -5
- package/src/backend/web-registration.ts +5 -5
- package/src/code-review/extension.ts +3 -3
- package/src/code-review/reviewer.ts +2 -2
- package/src/code-view/diagnostic-view.ts +4 -4
- package/src/composite/builtin-extensions.ts +37 -37
- package/src/composite/capabilities.ts +2 -2
- package/src/composite/capability-schemas.ts +1 -1
- package/src/composite/detached-results.ts +32 -0
- package/src/composite/extensions-config.ts +2 -2
- package/src/composite/module-settings-store.ts +2 -2
- package/src/composite/module-settings.ts +12 -12
- package/src/composite/nested-tool-rendering.ts +3 -3
- package/src/composite/output-limits.ts +6 -1
- package/src/composite/preferences.ts +10 -0
- package/src/composite/presets.ts +1 -1
- package/src/composite/reload-required.ts +6 -6
- package/src/composite/settings-documentation.ts +5 -5
- package/src/composite/settings-registry.ts +4 -4
- package/src/composite/text-results.ts +2 -2
- package/src/core/diagnostic-entry.ts +2 -2
- package/src/core/diagnostic-store.ts +3 -3
- package/src/core/extension.ts +8 -8
- package/src/core/ide-core.ts +4 -4
- package/src/doctor/config-writer.ts +3 -3
- package/src/doctor/core.ts +2 -2
- package/src/doctor/discovery.ts +4 -4
- package/src/doctor/extension.ts +7 -7
- package/src/doctor/index.ts +1 -1
- package/src/doctor/inventory.ts +1 -1
- package/src/doctor/run.ts +6 -6
- package/src/doctor/tip-provider.ts +2 -2
- package/src/documentation/extension.ts +3 -3
- package/src/documentation/registry.ts +1 -1
- package/src/documentation/search.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/api/jq.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/file-write-lock.ts +70 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/replace-file.ts +50 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +28 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/doctor-plugin.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +1 -1
- package/src/extensions/pi-agent-read/index.ts +1 -1
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/rendering.ts +2 -2
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +8 -2
- package/src/extensions/pi-agent-read/src/core/extension.ts +4 -4
- package/src/extensions/pi-agent-read/src/core/read-core.ts +4 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +2 -2
- package/src/extensions/pi-agent-read/src/core/tools/read/persisted-result.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +3 -3
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +4 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +21 -14
- package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +24 -18
- package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +2 -2
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +44 -18
- package/src/extensions/pi-agent-search/index.ts +1 -1
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +8 -8
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -10
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/doctor-plugin.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +2 -2
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/persisted-result.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +9 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +4 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +3 -3
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +2 -2
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +3 -3
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +2 -2
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +132 -67
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/tool-file-search.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +2 -2
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/presentation.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/search.ts +7 -7
- package/src/extensions/pi-agent-search/src/core/extension.ts +7 -7
- package/src/extensions/pi-agent-search/src/core/search-core.ts +3 -3
- package/src/extensions/pi-agent-text-editor/index.ts +5 -5
- package/src/extensions/pi-agent-text-editor/package.json +9 -9
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +2 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +63 -48
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/recovery.ts +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +2 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +23 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +2 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +2 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +2 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +7 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/file-operations.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/file-transfers.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/api/native-files.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +14 -14
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +13 -13
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-guards.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +6 -6
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/core/image-write.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +11 -6
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +213 -20
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +39 -3
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +6 -6
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +22 -22
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/read-fragment-resolver.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/source-change-retry.ts +41 -0
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +4 -7
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +34 -21
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-origin.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +72 -30
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +211 -159
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +7 -7
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +1 -1
- package/src/index.ts +1 -1
- package/src/pi-agent-ide.ts +22 -20
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +33 -11
- package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +60 -55
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +4 -3
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -10
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +3 -3
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +35 -8
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +161 -23
- package/src/plugins/pi-agent-ide-ast/src/tool-ast-search.ts +1 -1
- package/src/plugins/pi-agent-ide-changes/index.ts +9 -9
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +4 -4
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +1 -1
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +4 -4
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +1 -1
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +4 -4
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +5 -5
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +6 -6
- package/src/plugins/pi-agent-ide-debugger/index.ts +21 -13
- package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +1 -1
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +4 -4
- package/src/plugins/pi-agent-ide-debugger/src/java-runtime.ts +2 -2
- package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +3 -3
- package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +1 -1
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +5 -5
- package/src/plugins/pi-agent-ide-debugger/src/ui.ts +1 -1
- package/src/plugins/pi-agent-ide-debugger/src/vscode-backend.ts +1 -1
- package/src/plugins/pi-agent-ide-debugger/src/workspace-owner.ts +2 -2
- package/src/plugins/pi-agent-ide-diagnostics/index.ts +1 -1
- package/src/plugins/pi-agent-ide-formatter/index.ts +5 -5
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +2 -2
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +2 -2
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +1 -1
- package/src/plugins/pi-agent-ide-languages/index.ts +1 -1
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/index.ts +9 -9
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lint/src/catalog.ts +4 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +15 -6
- package/src/plugins/pi-agent-ide-lint/src/diagnostics.ts +8 -14
- package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +3 -3
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/index.ts +37 -16
- package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
- package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +12 -1
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +21 -14
- package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +63 -20
- package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +4 -4
- package/src/plugins/pi-agent-ide-lsp/src/idle-timeout.ts +15 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/abort.ts +11 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +434 -80
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +121 -35
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostic-adapters.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +26 -12
- package/src/plugins/pi-agent-ide-lsp/src/lsp/document-leases.ts +31 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/errors.ts +4 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/file-watchers.ts +1 -77
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +19 -19
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +5 -4
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +59 -28
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +42 -22
- package/src/plugins/pi-agent-ide-lsp/src/lsp/owner-transport.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/position-map.ts +52 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +2 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +2 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +325 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +797 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-servers.ts +322 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/source-changes.ts +29 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +76 -17
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +3 -3
- package/src/plugins/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/manager-provider.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +16 -8
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +149 -134
- package/src/plugins/pi-agent-ide-lsp/src/tool-lsp-search.ts +1 -1
- package/src/plugins/pi-agent-ide-processes/index.ts +4 -4
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +1 -1
- package/src/plugins/pi-agent-ide-semantic/src/vera-backend.ts +2 -2
- package/src/plugins/pi-agent-ide-terminal/index.ts +17 -17
- package/src/plugins/pi-agent-ide-terminal/src/origin.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -5
- package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +2 -2
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +9 -9
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +3 -3
- package/src/post-edit/gate.ts +1 -1
- package/src/semantic/extension.ts +2 -2
- package/src/semantic/index.ts +4 -4
- package/src/standalone/resource-host.ts +13 -13
- package/src/standalone/scoped-api.ts +2 -2
- package/src/tips/core.ts +1 -1
- package/src/tips/extension.ts +6 -6
- package/src/tips/setup-hint.ts +1 -1
- package/src/toolchain/diagnostic.ts +1 -1
- package/src/toolchain/registry.ts +1 -1
- package/dist/chunk-2AY526TN.js +0 -3
- package/dist/chunk-52PFWQMU.js +0 -5
- package/dist/chunk-57F5GTHO.js +0 -1
- package/dist/chunk-5S74Z6Y4.js +0 -7
- package/dist/chunk-7D7PXIVV.js +0 -1
- package/dist/chunk-BT2CFM7D.js +0 -11
- package/dist/chunk-C2JT2G5K.js +0 -1
- package/dist/chunk-DEWWWKUF.js +0 -6
- package/dist/chunk-FEZLTM4L.js +0 -1
- package/dist/chunk-G4PRFO6G.js +0 -1
- package/dist/chunk-H5Z54BEU.js +0 -25
- package/dist/chunk-HISGZD3C.js +0 -81
- package/dist/chunk-HRBUY2FF.js +0 -4
- package/dist/chunk-ICIRQLZ4.js +0 -23
- package/dist/chunk-LIQ4BVOB.js +0 -1
- package/dist/chunk-LXDF2NWX.js +0 -1
- package/dist/chunk-MDD5ORB6.js +0 -1
- package/dist/chunk-OJEIX7OZ.js +0 -1
- package/dist/chunk-S5PL5DFQ.js +0 -1
- package/dist/chunk-U7YDLVFL.js +0 -1
- package/dist/chunk-VDJSH3DQ.js +0 -2
- package/dist/chunk-XH5WN5XA.js +0 -2
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// A detached process that runs one language server for every Pi session on this machine that
|
|
3
|
+
// attaches with the same configuration. shared-servers.ts starts it and describes the protocol.
|
|
4
|
+
// Plain JavaScript so it runs outside Pi's TypeScript loader.
|
|
5
|
+
import { readFileSync, statSync } from "node:fs";
|
|
6
|
+
import { readdir, rm, stat } from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import net from "node:net";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
import spawnProcess from "cross-spawn";
|
|
12
|
+
import {
|
|
13
|
+
CancellationTokenSource,
|
|
14
|
+
createMessageConnection,
|
|
15
|
+
StreamMessageReader,
|
|
16
|
+
StreamMessageWriter,
|
|
17
|
+
} from "vscode-jsonrpc/node";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
configurationItems,
|
|
21
|
+
LspFileWatchers,
|
|
22
|
+
SHARED_SERVER_PROTOCOL,
|
|
23
|
+
} from "./server-request-handlers.mjs";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} AttachRequest
|
|
27
|
+
* @property {number} protocol
|
|
28
|
+
* @property {string} key
|
|
29
|
+
* @property {readonly string[]} command
|
|
30
|
+
* @property {string} cwd
|
|
31
|
+
* @property {Record<string, string | undefined>} env
|
|
32
|
+
* @property {unknown} settings
|
|
33
|
+
* @property {Record<string, unknown>} initialize Initialize parameters of the attaching client.
|
|
34
|
+
* @property {number} lingerMs
|
|
35
|
+
* @property {number} timeoutMs
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {object} SessionDocument
|
|
40
|
+
* @property {number} version Version the session uses for this document.
|
|
41
|
+
* @property {string} text Text the session last synchronized.
|
|
42
|
+
* @property {boolean} published Whether the session received diagnostics for this version.
|
|
43
|
+
* @property {number} syncedAt When the session sent this text, to tell it from later writes to the file.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {object} Session
|
|
48
|
+
* @property {net.Socket} socket
|
|
49
|
+
* @property {import("vscode-jsonrpc/node").MessageConnection} connection
|
|
50
|
+
* @property {Map<string, SessionDocument>} documents
|
|
51
|
+
* @property {Set<CancellationTokenSource>} requests
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {object} ServerDocument
|
|
56
|
+
* @property {string} text Text the server currently has.
|
|
57
|
+
* @property {number} version Version the server currently has.
|
|
58
|
+
* @property {Set<Session>} holders Sessions that have the document open.
|
|
59
|
+
* @property {{ version: number | undefined; current: number; diagnostics: unknown[] } | undefined} publication
|
|
60
|
+
* Latest push diagnostics and the server version that was current when they arrived.
|
|
61
|
+
* @property {ReturnType<typeof setTimeout> | undefined} closeTimer Pending close after the last holder left.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @typedef {object} Server
|
|
66
|
+
* @property {import("node:child_process").ChildProcess} process
|
|
67
|
+
* @property {import("vscode-jsonrpc/node").MessageConnection} connection
|
|
68
|
+
* @property {unknown} initializeResult
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
const NO_SESSION_TIMEOUT_MS = 30_000;
|
|
72
|
+
/** A socket that refuses connections this long after it was created belongs to a dead host. */
|
|
73
|
+
const STALE_SOCKET_MS = 60_000;
|
|
74
|
+
/** Logs of failed hosts are kept this long for diagnosis. */
|
|
75
|
+
const FAILURE_LOG_MS = 24 * 60 * 60_000;
|
|
76
|
+
const DIAGNOSTICS = "textDocument/publishDiagnostics";
|
|
77
|
+
const SERVER_STATUS = "experimental/serverStatus";
|
|
78
|
+
/**
|
|
79
|
+
* Keep a document open on the server this long after its last session closed it, never longer
|
|
80
|
+
* than the server lingers. Sessions close a document after each operation and often reopen it at
|
|
81
|
+
* once; closing and reopening would make the server analyze it again, and the clear it publishes
|
|
82
|
+
* for the close could reach the reopened document before the new report.
|
|
83
|
+
*/
|
|
84
|
+
const DOCUMENT_CLOSE_DELAY_MS = 5_000;
|
|
85
|
+
|
|
86
|
+
const socketPath = process.argv[2] ?? "";
|
|
87
|
+
const key = process.argv[3] ?? "";
|
|
88
|
+
const logPath = process.argv[4] ?? "";
|
|
89
|
+
if (!socketPath || !key || !logPath) {
|
|
90
|
+
process.exitCode = 2;
|
|
91
|
+
throw new Error("Usage: shared-server-host.mjs <socket> <key> <log>");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @type {Set<Session>} */
|
|
95
|
+
const sessions = new Set();
|
|
96
|
+
/** @type {Map<string, ServerDocument>} */
|
|
97
|
+
const documents = new Map();
|
|
98
|
+
/** @type {Promise<Server> | undefined} */
|
|
99
|
+
let server;
|
|
100
|
+
/** Set once the server is initialized; notifications are written in the order they arrive. */
|
|
101
|
+
/** @type {Server | undefined} */
|
|
102
|
+
let running;
|
|
103
|
+
/** @type {LspFileWatchers | undefined} */
|
|
104
|
+
let fileWatchers;
|
|
105
|
+
let nextVersion = 0;
|
|
106
|
+
/** Set once the server versions its diagnostics; its unversioned pushes then describe closed documents. */
|
|
107
|
+
let versionedDiagnostics = false;
|
|
108
|
+
/**
|
|
109
|
+
* Latest `experimental/serverStatus`; sessions that attach later receive it at once.
|
|
110
|
+
* @type {unknown}
|
|
111
|
+
*/
|
|
112
|
+
let serverStatus;
|
|
113
|
+
/**
|
|
114
|
+
* The server's dynamic registration of pull diagnostics; sessions that attach later receive it.
|
|
115
|
+
* @type {{ id: string; method: string; registerOptions?: unknown } | undefined}
|
|
116
|
+
*/
|
|
117
|
+
let pullRegistration;
|
|
118
|
+
let lingerMs = 10 * 60_000;
|
|
119
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
120
|
+
let stopTimer = setTimeout(() => void stop(), NO_SESSION_TIMEOUT_MS);
|
|
121
|
+
let stopping = false;
|
|
122
|
+
|
|
123
|
+
const listener = net.createServer((socket) => void accept(socket));
|
|
124
|
+
await listen();
|
|
125
|
+
void sweep();
|
|
126
|
+
for (const signal of /** @type {const} */ (["SIGTERM", "SIGINT", "SIGHUP"]))
|
|
127
|
+
process.on(signal, () => void stop());
|
|
128
|
+
process.on("uncaughtException", () => void stop(1));
|
|
129
|
+
process.on("unhandledRejection", () => void stop(1));
|
|
130
|
+
|
|
131
|
+
/** Bind the socket; another live host for this key wins, and a stale socket file is replaced. */
|
|
132
|
+
async function listen() {
|
|
133
|
+
try {
|
|
134
|
+
await bind();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code !== "EADDRINUSE") throw error;
|
|
137
|
+
if (await reachable(socketPath)) process.exit(0);
|
|
138
|
+
await rm(socketPath, { force: true });
|
|
139
|
+
await bind();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Remove files of hosts that ended without cleanup, for example when they were killed. Only
|
|
145
|
+
* old sockets are probed: a new host creates its socket file just before it listens.
|
|
146
|
+
*/
|
|
147
|
+
async function sweep() {
|
|
148
|
+
const directory = path.dirname(logPath);
|
|
149
|
+
const now = Date.now();
|
|
150
|
+
for (const name of await readdir(directory).catch(() => [])) {
|
|
151
|
+
const file = path.join(directory, name);
|
|
152
|
+
if (file === socketPath || file === logPath) continue;
|
|
153
|
+
const changed = await stat(file).then(
|
|
154
|
+
(stats) => stats.mtimeMs,
|
|
155
|
+
() => now,
|
|
156
|
+
);
|
|
157
|
+
if (name.endsWith(".log") && now - changed > FAILURE_LOG_MS) await rm(file, { force: true });
|
|
158
|
+
if (name.endsWith(".sock") && now - changed > STALE_SOCKET_MS && !(await reachable(file)))
|
|
159
|
+
await rm(file, { force: true });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** @returns {Promise<void>} */
|
|
164
|
+
function bind() {
|
|
165
|
+
return new Promise((resolve, reject) => {
|
|
166
|
+
listener.once("error", reject);
|
|
167
|
+
listener.listen(socketPath, () => {
|
|
168
|
+
listener.off("error", reject);
|
|
169
|
+
resolve();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {string} target
|
|
176
|
+
* @returns {Promise<boolean>}
|
|
177
|
+
*/
|
|
178
|
+
function reachable(target) {
|
|
179
|
+
return new Promise((resolve) => {
|
|
180
|
+
const probe = net.connect(target);
|
|
181
|
+
probe.once("connect", () => {
|
|
182
|
+
probe.destroy();
|
|
183
|
+
resolve(true);
|
|
184
|
+
});
|
|
185
|
+
probe.once("error", () => resolve(false));
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Read the one-line attach request, then speak LSP with the session on the same socket.
|
|
191
|
+
* @param {net.Socket} socket
|
|
192
|
+
*/
|
|
193
|
+
async function accept(socket) {
|
|
194
|
+
socket.on("error", () => void 0);
|
|
195
|
+
/** @type {AttachRequest} */
|
|
196
|
+
let attach;
|
|
197
|
+
try {
|
|
198
|
+
attach = /** @type {AttachRequest} */ (JSON.parse(await readLine(socket)));
|
|
199
|
+
} catch {
|
|
200
|
+
socket.destroy();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (attach.protocol !== SHARED_SERVER_PROTOCOL || attach.key !== key) {
|
|
204
|
+
socket.end(`${JSON.stringify({ error: "Shared language server configuration mismatch" })}\n`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
let started;
|
|
208
|
+
try {
|
|
209
|
+
started = await (server ??= startServer(attach));
|
|
210
|
+
running = started;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
socket.end(
|
|
213
|
+
`${JSON.stringify({ error: error instanceof Error ? error.message : String(error) })}\n`,
|
|
214
|
+
);
|
|
215
|
+
void stop(1);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (stopping || socket.destroyed) {
|
|
219
|
+
socket.destroy();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
lingerMs = attach.lingerMs;
|
|
223
|
+
clearTimeout(stopTimer);
|
|
224
|
+
stopTimer = undefined;
|
|
225
|
+
const session = openSession(socket, started);
|
|
226
|
+
socket.write(`${JSON.stringify({ pid: started.process.pid })}\n`);
|
|
227
|
+
session.connection.listen();
|
|
228
|
+
if (serverStatus !== undefined) notifySession(session, SERVER_STATUS, serverStatus);
|
|
229
|
+
registerPull(session);
|
|
230
|
+
// readLine paused the socket; a new data listener does not resume an explicitly paused stream.
|
|
231
|
+
socket.resume();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @param {net.Socket} socket
|
|
236
|
+
* @returns {Promise<string>}
|
|
237
|
+
*/
|
|
238
|
+
function readLine(socket) {
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
let buffered = Buffer.alloc(0);
|
|
241
|
+
/** @param {Buffer} chunk */
|
|
242
|
+
const onData = (chunk) => {
|
|
243
|
+
buffered = Buffer.concat([buffered, chunk]);
|
|
244
|
+
const end = buffered.indexOf(10);
|
|
245
|
+
if (end === -1) return;
|
|
246
|
+
cleanup();
|
|
247
|
+
socket.pause();
|
|
248
|
+
if (end + 1 < buffered.length) socket.unshift(buffered.subarray(end + 1));
|
|
249
|
+
resolve(buffered.subarray(0, end).toString("utf8"));
|
|
250
|
+
};
|
|
251
|
+
const onEnd = () => {
|
|
252
|
+
cleanup();
|
|
253
|
+
reject(new Error("Session closed before attaching"));
|
|
254
|
+
};
|
|
255
|
+
const cleanup = () => {
|
|
256
|
+
socket.off("data", onData);
|
|
257
|
+
socket.off("end", onEnd);
|
|
258
|
+
socket.off("close", onEnd);
|
|
259
|
+
};
|
|
260
|
+
socket.on("data", onData);
|
|
261
|
+
socket.once("end", onEnd);
|
|
262
|
+
socket.once("close", onEnd);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Start and initialize the language server with the first session's configuration.
|
|
268
|
+
* @param {AttachRequest} attach
|
|
269
|
+
* @returns {Promise<Server>}
|
|
270
|
+
*/
|
|
271
|
+
async function startServer(attach) {
|
|
272
|
+
const [command, ...args] = attach.command;
|
|
273
|
+
if (!command) throw new Error("Shared language server has no command");
|
|
274
|
+
const child = spawnProcess(command, args, {
|
|
275
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
276
|
+
cwd: attach.cwd,
|
|
277
|
+
env: attach.env,
|
|
278
|
+
});
|
|
279
|
+
let stderr = "";
|
|
280
|
+
// A server can exit before its last stderr output arrives; startup errors wait for it.
|
|
281
|
+
const stderrEnded = new Promise((resolve) => {
|
|
282
|
+
child.stderr?.once("end", resolve);
|
|
283
|
+
child.stderr?.once("close", resolve);
|
|
284
|
+
});
|
|
285
|
+
/** @type {number | null | undefined} */
|
|
286
|
+
let exitCode;
|
|
287
|
+
const exited = new Promise((resolve) => {
|
|
288
|
+
child.once("exit", (code) => {
|
|
289
|
+
exitCode = code;
|
|
290
|
+
resolve(undefined);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
child.stderr?.setEncoding("utf8");
|
|
294
|
+
child.stderr?.on("data", (/** @type {string} */ chunk) => {
|
|
295
|
+
stderr = (stderr + chunk).slice(-4096);
|
|
296
|
+
});
|
|
297
|
+
child.stdin?.on("error", () => void 0);
|
|
298
|
+
await new Promise((resolve, reject) => {
|
|
299
|
+
child.once("spawn", resolve);
|
|
300
|
+
child.once("error", reject);
|
|
301
|
+
});
|
|
302
|
+
child.on("exit", (code, signal) => {
|
|
303
|
+
if (stopping) return;
|
|
304
|
+
// The server exited on its own. Record why and fail, so that the log stays for diagnosis; a
|
|
305
|
+
// clean stop deletes it.
|
|
306
|
+
void Promise.race([stderrEnded, new Promise((resolve) => setTimeout(resolve, 250))]).then(
|
|
307
|
+
() => {
|
|
308
|
+
const output = stderr.trim();
|
|
309
|
+
process.stderr.write(
|
|
310
|
+
`${new Date().toISOString()} ${command} exited with ${signal ? `signal ${signal}` : `code ${String(code)}`}${output ? `:\n${output}` : ""}\n`,
|
|
311
|
+
);
|
|
312
|
+
void stop(1);
|
|
313
|
+
},
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const connection = createMessageConnection(
|
|
318
|
+
new StreamMessageReader(/** @type {import("node:stream").Readable} */ (child.stdout)),
|
|
319
|
+
new StreamMessageWriter(/** @type {import("node:stream").Writable} */ (child.stdin)),
|
|
320
|
+
);
|
|
321
|
+
connection.onError(() => void 0);
|
|
322
|
+
const watchers = new LspFileWatchers(
|
|
323
|
+
attach.cwd,
|
|
324
|
+
(change) =>
|
|
325
|
+
void connection
|
|
326
|
+
.sendNotification("workspace/didChangeWatchedFiles", { changes: [change] })
|
|
327
|
+
.catch(() => void 0),
|
|
328
|
+
() => void 0,
|
|
329
|
+
);
|
|
330
|
+
fileWatchers = watchers;
|
|
331
|
+
connection.onRequest(
|
|
332
|
+
"client/registerCapability",
|
|
333
|
+
async (
|
|
334
|
+
/** @type {{ registrations: { id: string; method: string; registerOptions?: { watchers?: import("./file-watchers.js").WatchPattern[] } }[] }} */ parameters,
|
|
335
|
+
) => {
|
|
336
|
+
for (const registration of parameters.registrations) {
|
|
337
|
+
if (registration.method === "workspace/didChangeConfiguration") continue;
|
|
338
|
+
if (registration.method === "textDocument/diagnostic") {
|
|
339
|
+
// Each session reads diagnostics itself, so each learns that it can pull them.
|
|
340
|
+
pullRegistration = registration;
|
|
341
|
+
for (const session of sessions) registerPull(session);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (registration.method !== "workspace/didChangeWatchedFiles")
|
|
345
|
+
throw new Error(`Unsupported dynamic capability: ${registration.method}`);
|
|
346
|
+
await watchers.register(registration.id, registration.registerOptions?.watchers ?? []);
|
|
347
|
+
}
|
|
348
|
+
return null;
|
|
349
|
+
},
|
|
350
|
+
);
|
|
351
|
+
connection.onRequest(
|
|
352
|
+
"client/unregisterCapability",
|
|
353
|
+
(/** @type {{ unregisterations: { id: string }[] }} */ parameters) => {
|
|
354
|
+
for (const registration of parameters.unregisterations) {
|
|
355
|
+
if (registration.id === pullRegistration?.id) {
|
|
356
|
+
pullRegistration = undefined;
|
|
357
|
+
for (const session of sessions)
|
|
358
|
+
void session.connection
|
|
359
|
+
.sendRequest("client/unregisterCapability", { unregisterations: [registration] })
|
|
360
|
+
.catch(() => void 0);
|
|
361
|
+
} else watchers.unregister(registration.id);
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
},
|
|
365
|
+
);
|
|
366
|
+
connection.onRequest("window/workDoneProgress/create", () => null);
|
|
367
|
+
// A pull-diagnostic server asks for new pulls after results change; pyright exits when this
|
|
368
|
+
// request fails. Each session pulls its own documents.
|
|
369
|
+
connection.onRequest("workspace/diagnostic/refresh", () => {
|
|
370
|
+
for (const session of sessions)
|
|
371
|
+
void session.connection.sendRequest("workspace/diagnostic/refresh").catch(() => void 0);
|
|
372
|
+
return null;
|
|
373
|
+
});
|
|
374
|
+
connection.onRequest(
|
|
375
|
+
"workspace/configuration",
|
|
376
|
+
(/** @type {{ items: { section?: string }[] }} */ parameters) =>
|
|
377
|
+
configurationItems(attach.settings, parameters.items),
|
|
378
|
+
);
|
|
379
|
+
connection.onRequest(
|
|
380
|
+
"workspace/workspaceFolders",
|
|
381
|
+
() => attach.initialize.workspaceFolders ?? null,
|
|
382
|
+
);
|
|
383
|
+
connection.onNotification((method, parameters) => publishToSessions(method, parameters));
|
|
384
|
+
connection.listen();
|
|
385
|
+
|
|
386
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
387
|
+
let timeout;
|
|
388
|
+
try {
|
|
389
|
+
/** @type {unknown} */
|
|
390
|
+
const initializeResult = await Promise.race([
|
|
391
|
+
connection.sendRequest(/** @type {string} */ ("initialize"), {
|
|
392
|
+
...attach.initialize,
|
|
393
|
+
processId: process.pid,
|
|
394
|
+
}),
|
|
395
|
+
new Promise((_resolve, reject) => {
|
|
396
|
+
timeout = setTimeout(
|
|
397
|
+
() => reject(new Error("Shared language server initialize timed out")),
|
|
398
|
+
attach.timeoutMs,
|
|
399
|
+
);
|
|
400
|
+
}),
|
|
401
|
+
// A server that exits does not answer; its pending initialize would wait for the timeout.
|
|
402
|
+
exited.then(() => {
|
|
403
|
+
throw new Error("Shared language server exited during startup");
|
|
404
|
+
}),
|
|
405
|
+
]);
|
|
406
|
+
await connection.sendNotification("initialized", {});
|
|
407
|
+
if (attach.settings !== undefined)
|
|
408
|
+
await connection.sendNotification("workspace/didChangeConfiguration", {
|
|
409
|
+
settings: attach.settings,
|
|
410
|
+
});
|
|
411
|
+
return { process: child, connection, initializeResult };
|
|
412
|
+
} catch (error) {
|
|
413
|
+
// A failed initialize write can precede the exit event and the server's last stderr output.
|
|
414
|
+
await Promise.race([
|
|
415
|
+
Promise.all([stderrEnded, exited]),
|
|
416
|
+
new Promise((resolve) => setTimeout(resolve, 250)),
|
|
417
|
+
]);
|
|
418
|
+
const detail = stderr.trim();
|
|
419
|
+
const exit =
|
|
420
|
+
exitCode === undefined
|
|
421
|
+
? ""
|
|
422
|
+
: `exited during startup${exitCode === null ? "" : ` with code ${exitCode}`}`;
|
|
423
|
+
if (!detail && !exit) throw error;
|
|
424
|
+
throw new Error([exit, detail].filter(Boolean).join(": "), { cause: error });
|
|
425
|
+
} finally {
|
|
426
|
+
clearTimeout(timeout);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Route one session's LSP traffic to the shared server.
|
|
432
|
+
* @param {net.Socket} socket
|
|
433
|
+
* @param {Server} started
|
|
434
|
+
* @returns {Session}
|
|
435
|
+
*/
|
|
436
|
+
function openSession(socket, started) {
|
|
437
|
+
const connection = createMessageConnection(
|
|
438
|
+
new StreamMessageReader(socket),
|
|
439
|
+
new StreamMessageWriter(socket),
|
|
440
|
+
);
|
|
441
|
+
/** @type {Session} */
|
|
442
|
+
const session = { socket, connection, documents: new Map(), requests: new Set() };
|
|
443
|
+
sessions.add(session);
|
|
444
|
+
connection.onError(() => void 0);
|
|
445
|
+
connection.onClose(() => detach(session));
|
|
446
|
+
socket.once("close", () => detach(session));
|
|
447
|
+
|
|
448
|
+
connection.onRequest("initialize", () => started.initializeResult);
|
|
449
|
+
connection.onRequest("shutdown", () => {
|
|
450
|
+
releaseDocuments(session);
|
|
451
|
+
return null;
|
|
452
|
+
});
|
|
453
|
+
connection.onNotification("exit", () => {
|
|
454
|
+
socket.end();
|
|
455
|
+
});
|
|
456
|
+
// The host initialized the server and serves settings itself.
|
|
457
|
+
connection.onNotification("initialized", () => void 0);
|
|
458
|
+
connection.onNotification("workspace/didChangeConfiguration", () => void 0);
|
|
459
|
+
connection.onNotification(
|
|
460
|
+
"textDocument/didOpen",
|
|
461
|
+
(
|
|
462
|
+
/** @type {{ textDocument: { uri: string; languageId: string; version: number; text: string } }} */ {
|
|
463
|
+
textDocument,
|
|
464
|
+
},
|
|
465
|
+
) => {
|
|
466
|
+
const existing = documents.get(textDocument.uri);
|
|
467
|
+
clearTimeout(existing?.closeTimer);
|
|
468
|
+
if (existing) existing.closeTimer = undefined;
|
|
469
|
+
else {
|
|
470
|
+
const version = ++nextVersion;
|
|
471
|
+
documents.set(textDocument.uri, {
|
|
472
|
+
text: textDocument.text,
|
|
473
|
+
version,
|
|
474
|
+
holders: new Set(),
|
|
475
|
+
publication: undefined,
|
|
476
|
+
closeTimer: undefined,
|
|
477
|
+
});
|
|
478
|
+
notifyServer("textDocument/didOpen", { textDocument: { ...textDocument, version } });
|
|
479
|
+
}
|
|
480
|
+
session.documents.set(textDocument.uri, {
|
|
481
|
+
version: textDocument.version,
|
|
482
|
+
text: textDocument.text,
|
|
483
|
+
published: false,
|
|
484
|
+
syncedAt: Date.now(),
|
|
485
|
+
});
|
|
486
|
+
documents.get(textDocument.uri)?.holders.add(session);
|
|
487
|
+
align(session, textDocument.uri);
|
|
488
|
+
},
|
|
489
|
+
);
|
|
490
|
+
connection.onNotification(
|
|
491
|
+
"textDocument/didChange",
|
|
492
|
+
(
|
|
493
|
+
/** @type {{ textDocument: { uri: string; version: number }; contentChanges: { text: string; range?: unknown }[] }} */ {
|
|
494
|
+
textDocument,
|
|
495
|
+
contentChanges,
|
|
496
|
+
},
|
|
497
|
+
) => {
|
|
498
|
+
const owned = session.documents.get(textDocument.uri);
|
|
499
|
+
const text = contentChanges.at(-1)?.text;
|
|
500
|
+
// LspClient always sends full text; ranges would make the shared text unknown.
|
|
501
|
+
if (!owned || text === undefined || contentChanges.some((change) => change.range)) return;
|
|
502
|
+
owned.version = textDocument.version;
|
|
503
|
+
owned.text = text;
|
|
504
|
+
owned.published = false;
|
|
505
|
+
owned.syncedAt = Date.now();
|
|
506
|
+
align(session, textDocument.uri);
|
|
507
|
+
},
|
|
508
|
+
);
|
|
509
|
+
connection.onNotification(
|
|
510
|
+
"textDocument/didClose",
|
|
511
|
+
(/** @type {{ textDocument: { uri: string } }} */ { textDocument }) =>
|
|
512
|
+
closeDocument(session, textDocument.uri),
|
|
513
|
+
);
|
|
514
|
+
connection.onNotification((method, parameters) => notifyServer(method, parameters));
|
|
515
|
+
connection.onRequest(async (method, parameters, token) => {
|
|
516
|
+
const uri = documentUriOf(parameters);
|
|
517
|
+
if (uri) align(session, uri);
|
|
518
|
+
// The server answers for the text it has now. Another session's text may replace it before
|
|
519
|
+
// the answer arrives, so the versions are mapped as they were when the request was sent.
|
|
520
|
+
const owned = uri === undefined ? undefined : session.documents.get(uri);
|
|
521
|
+
const document = uri === undefined ? undefined : documents.get(uri);
|
|
522
|
+
const sent =
|
|
523
|
+
uri !== undefined && owned && document && document.text === owned.text
|
|
524
|
+
? { uri, server: document.version, session: owned.version }
|
|
525
|
+
: undefined;
|
|
526
|
+
const cancellation = new CancellationTokenSource();
|
|
527
|
+
const forward = token.onCancellationRequested(() => cancellation.cancel());
|
|
528
|
+
session.requests.add(cancellation);
|
|
529
|
+
try {
|
|
530
|
+
/** @type {unknown} */
|
|
531
|
+
const result = await started.connection.sendRequest(method, parameters, cancellation.token);
|
|
532
|
+
return sessionVersions(session, result, sent);
|
|
533
|
+
} finally {
|
|
534
|
+
forward.dispose();
|
|
535
|
+
session.requests.delete(cancellation);
|
|
536
|
+
cancellation.dispose();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
return session;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Give the server this session's text before its request or after its change, then replay
|
|
544
|
+
* diagnostics the server already published for that text.
|
|
545
|
+
* @param {Session} session
|
|
546
|
+
* @param {string} uri
|
|
547
|
+
*/
|
|
548
|
+
function align(session, uri) {
|
|
549
|
+
const owned = session.documents.get(uri);
|
|
550
|
+
const document = documents.get(uri);
|
|
551
|
+
if (!owned || !document) return;
|
|
552
|
+
if (document.text !== owned.text) {
|
|
553
|
+
// Another process wrote the file after this session sent its copy, so the copy is older than
|
|
554
|
+
// the file. Putting it back would make the server reparse and cancel the other sessions'
|
|
555
|
+
// requests; that session catches up with its next request or edit. A copy sent after the
|
|
556
|
+
// file's last write, such as an unsaved proposal, still reaches the server.
|
|
557
|
+
if (olderThanFile(uri, document.text, owned)) return;
|
|
558
|
+
document.text = owned.text;
|
|
559
|
+
document.version = ++nextVersion;
|
|
560
|
+
document.publication = undefined;
|
|
561
|
+
notifyServer("textDocument/didChange", {
|
|
562
|
+
textDocument: { uri, version: document.version },
|
|
563
|
+
contentChanges: [{ text: owned.text }],
|
|
564
|
+
});
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const publication = document.publication;
|
|
568
|
+
if (publication?.current !== document.version) return;
|
|
569
|
+
owned.published = true;
|
|
570
|
+
notifySession(session, DIAGNOSTICS, {
|
|
571
|
+
uri,
|
|
572
|
+
...(publication.version !== undefined && { version: owned.version }),
|
|
573
|
+
diagnostics: publication.diagnostics,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Whether the server has the text of the document's file and a session's copy predates the
|
|
579
|
+
* file's last write. Documents that are not readable local files are never older.
|
|
580
|
+
* @param {string} uri
|
|
581
|
+
* @param {string} serverText
|
|
582
|
+
* @param {{ text: string; syncedAt: number }} owned
|
|
583
|
+
*/
|
|
584
|
+
function olderThanFile(uri, serverText, owned) {
|
|
585
|
+
if (!uri.startsWith("file:")) return false;
|
|
586
|
+
try {
|
|
587
|
+
const file = fileURLToPath(uri);
|
|
588
|
+
return (
|
|
589
|
+
statSync(file).mtimeMs > owned.syncedAt &&
|
|
590
|
+
owned.text !== serverText &&
|
|
591
|
+
readFileSync(file, "utf8") === serverText
|
|
592
|
+
);
|
|
593
|
+
} catch {
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* After the server published for its current text, give it the text of another session that
|
|
600
|
+
* still waits for diagnostics. Servers such as clangd publish nothing for a text that a newer
|
|
601
|
+
* one replaced, so without this an earlier session would wait in vain.
|
|
602
|
+
* @param {string} uri
|
|
603
|
+
*/
|
|
604
|
+
function serveWaitingSession(uri) {
|
|
605
|
+
const document = documents.get(uri);
|
|
606
|
+
if (!document) return;
|
|
607
|
+
for (const session of document.holders) {
|
|
608
|
+
const owned = session.documents.get(uri);
|
|
609
|
+
// A copy older than the file is not served; see align.
|
|
610
|
+
if (
|
|
611
|
+
owned &&
|
|
612
|
+
!owned.published &&
|
|
613
|
+
owned.text !== document.text &&
|
|
614
|
+
!olderThanFile(uri, document.text, owned)
|
|
615
|
+
) {
|
|
616
|
+
align(session, uri);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Deliver server notifications. Diagnostics of an open document reach only the sessions whose
|
|
624
|
+
* text the server has, under their own document versions; others go to every session.
|
|
625
|
+
* @param {string} method
|
|
626
|
+
* @param {unknown} parameters
|
|
627
|
+
*/
|
|
628
|
+
function publishToSessions(method, parameters) {
|
|
629
|
+
const publication = /** @type {{ uri?: unknown; version?: unknown; diagnostics?: unknown }} */ (
|
|
630
|
+
parameters ?? {}
|
|
631
|
+
);
|
|
632
|
+
const document =
|
|
633
|
+
method === DIAGNOSTICS && typeof publication.uri === "string"
|
|
634
|
+
? documents.get(publication.uri)
|
|
635
|
+
: undefined;
|
|
636
|
+
if (method === SERVER_STATUS) serverStatus = parameters;
|
|
637
|
+
const version = typeof publication.version === "number" ? publication.version : undefined;
|
|
638
|
+
if (method === DIAGNOSTICS && version !== undefined) versionedDiagnostics = true;
|
|
639
|
+
if (!document || !Array.isArray(publication.diagnostics)) {
|
|
640
|
+
for (const session of sessions) notifySession(session, method, parameters);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
// Such a server omits the version only for a document it sees as closed, so an unversioned push
|
|
644
|
+
// for an open document predates its latest didOpen, such as the clear for a close that a quick
|
|
645
|
+
// reopen followed.
|
|
646
|
+
if (version === undefined && versionedDiagnostics) return;
|
|
647
|
+
if (version !== undefined && version !== document.version) return;
|
|
648
|
+
document.publication = {
|
|
649
|
+
version,
|
|
650
|
+
current: document.version,
|
|
651
|
+
diagnostics: publication.diagnostics,
|
|
652
|
+
};
|
|
653
|
+
for (const session of document.holders) {
|
|
654
|
+
const owned = session.documents.get(/** @type {string} */ (publication.uri));
|
|
655
|
+
if (owned?.text !== document.text) continue;
|
|
656
|
+
owned.published = true;
|
|
657
|
+
notifySession(session, DIAGNOSTICS, {
|
|
658
|
+
...publication,
|
|
659
|
+
...(version !== undefined && { version: owned.version }),
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
serveWaitingSession(/** @type {string} */ (publication.uri));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Report document versions in results, such as rename edits, in the session's numbering.
|
|
667
|
+
* A version that is not the session's current text never matches one of its versions.
|
|
668
|
+
* @param {Session} session
|
|
669
|
+
* @param {unknown} value
|
|
670
|
+
* @param {{ uri: string; server: number; session: number }} [sent] the requested
|
|
671
|
+
* document's server and session versions when the request was sent
|
|
672
|
+
* @returns {unknown}
|
|
673
|
+
*/
|
|
674
|
+
function sessionVersions(session, value, sent) {
|
|
675
|
+
if (Array.isArray(value)) return value.map((item) => sessionVersions(session, item, sent));
|
|
676
|
+
if (typeof value !== "object" || value === null) return value;
|
|
677
|
+
const mapped = Object.fromEntries(
|
|
678
|
+
Object.entries(value).map(([name, item]) => [name, sessionVersions(session, item, sent)]),
|
|
679
|
+
);
|
|
680
|
+
const identifier = /** @type {{ textDocument?: { uri?: unknown; version?: unknown } }} */ (mapped)
|
|
681
|
+
.textDocument;
|
|
682
|
+
if (sent !== undefined && identifier?.uri === sent.uri && identifier.version === sent.server) {
|
|
683
|
+
mapped.textDocument = { ...identifier, version: sent.session };
|
|
684
|
+
} else if (typeof identifier?.uri === "string" && typeof identifier.version === "number") {
|
|
685
|
+
const owned = session.documents.get(identifier.uri);
|
|
686
|
+
const document = documents.get(identifier.uri);
|
|
687
|
+
const current =
|
|
688
|
+
owned && document && document.version === identifier.version && document.text === owned.text;
|
|
689
|
+
mapped.textDocument = { ...identifier, version: current ? owned.version : -1 };
|
|
690
|
+
}
|
|
691
|
+
return mapped;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** @param {unknown} parameters */
|
|
695
|
+
function documentUriOf(parameters) {
|
|
696
|
+
const uri = /** @type {{ textDocument?: { uri?: unknown } } | undefined} */ (parameters)
|
|
697
|
+
?.textDocument?.uri;
|
|
698
|
+
return typeof uri === "string" ? uri : undefined;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* @param {Session} session
|
|
703
|
+
* @param {string} uri
|
|
704
|
+
*/
|
|
705
|
+
function closeDocument(session, uri) {
|
|
706
|
+
session.documents.delete(uri);
|
|
707
|
+
const document = documents.get(uri);
|
|
708
|
+
if (!document) return;
|
|
709
|
+
document.holders.delete(session);
|
|
710
|
+
if (document.holders.size > 0) return;
|
|
711
|
+
clearTimeout(document.closeTimer);
|
|
712
|
+
document.closeTimer = setTimeout(
|
|
713
|
+
() => {
|
|
714
|
+
if (documents.get(uri) !== document || document.holders.size > 0) return;
|
|
715
|
+
documents.delete(uri);
|
|
716
|
+
notifyServer("textDocument/didClose", { textDocument: { uri } });
|
|
717
|
+
},
|
|
718
|
+
Math.min(lingerMs, DOCUMENT_CLOSE_DELAY_MS),
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** @param {Session} session */
|
|
723
|
+
function releaseDocuments(session) {
|
|
724
|
+
for (const uri of [...session.documents.keys()]) closeDocument(session, uri);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** @param {Session} session */
|
|
728
|
+
function detach(session) {
|
|
729
|
+
if (!sessions.delete(session)) return;
|
|
730
|
+
for (const request of session.requests) request.cancel();
|
|
731
|
+
releaseDocuments(session);
|
|
732
|
+
session.connection.dispose();
|
|
733
|
+
if (sessions.size === 0 && !stopping) {
|
|
734
|
+
clearTimeout(stopTimer);
|
|
735
|
+
stopTimer = setTimeout(() => void stop(), lingerMs);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* @param {string} method
|
|
741
|
+
* @param {unknown} parameters
|
|
742
|
+
*/
|
|
743
|
+
function notifyServer(method, parameters) {
|
|
744
|
+
void running?.connection.sendNotification(method, parameters).catch(() => void 0);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Tell a session that the server registered pull diagnostics.
|
|
749
|
+
* @param {Session} session
|
|
750
|
+
*/
|
|
751
|
+
function registerPull(session) {
|
|
752
|
+
if (pullRegistration === undefined) return;
|
|
753
|
+
void session.connection
|
|
754
|
+
.sendRequest("client/registerCapability", { registrations: [pullRegistration] })
|
|
755
|
+
.catch(() => void 0);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* @param {Session} session
|
|
760
|
+
* @param {string} method
|
|
761
|
+
* @param {unknown} parameters
|
|
762
|
+
*/
|
|
763
|
+
function notifySession(session, method, parameters) {
|
|
764
|
+
void session.connection.sendNotification(method, parameters).catch(() => void 0);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Stop the server, disconnect every session and remove the socket.
|
|
769
|
+
* @param {number} [exitCode]
|
|
770
|
+
*/
|
|
771
|
+
async function stop(exitCode = 0) {
|
|
772
|
+
if (stopping) return;
|
|
773
|
+
stopping = true;
|
|
774
|
+
clearTimeout(stopTimer);
|
|
775
|
+
listener.close();
|
|
776
|
+
// A new host may bind this path while the server shuts down.
|
|
777
|
+
if (process.platform !== "win32") await rm(socketPath, { force: true }).catch(() => void 0);
|
|
778
|
+
for (const session of sessions) session.socket.destroy();
|
|
779
|
+
const started = await server?.catch(() => undefined);
|
|
780
|
+
fileWatchers?.dispose();
|
|
781
|
+
if (started && started.process.exitCode === null && started.process.signalCode === null) {
|
|
782
|
+
const exited = new Promise((resolve) => started.process.once("exit", resolve));
|
|
783
|
+
await Promise.race([
|
|
784
|
+
started.connection
|
|
785
|
+
.sendRequest("shutdown")
|
|
786
|
+
.then(() => started.connection.sendNotification("exit"))
|
|
787
|
+
.catch(() => void 0),
|
|
788
|
+
new Promise((resolve) => setTimeout(resolve, 1000)),
|
|
789
|
+
]);
|
|
790
|
+
started.process.kill("SIGTERM");
|
|
791
|
+
const killed = setTimeout(() => started.process.kill("SIGKILL"), 2000);
|
|
792
|
+
await exited;
|
|
793
|
+
clearTimeout(killed);
|
|
794
|
+
}
|
|
795
|
+
if (exitCode === 0) await rm(logPath, { force: true }).catch(() => void 0);
|
|
796
|
+
process.exit(exitCode);
|
|
797
|
+
}
|