feat: third party lsp support - #639
Open
fltLi wants to merge 7 commits into
Open
Conversation
fltLi
marked this pull request as draft
August 4, 2026 01:06
This comment was marked as resolved.
This comment was marked as resolved.
fltLi
marked this pull request as ready for review
August 4, 2026 04:31
fltLi
marked this pull request as draft
August 4, 2026 06:52
This comment was marked as resolved.
This comment was marked as resolved.
- Implement textDocument/didSave notification forwarding - Server-side execution of workspace/applyEdit with real file system changes - Add workspace/didChangeConfiguration notification support - Handle workspace/willRenameFiles to perform actual file rename + edits - Provide public methods for triggering didSave / didChangeConfiguration / willRename - Enhance file watcher with pending registration queue and polling fallback - Clean up debug logs and comments This proxy now covers all LSP features that cannot be directly implemented in a browser-only Monaco environment, including file saving, editing, configuration changes, and rename operations.
fltLi
marked this pull request as ready for review
August 6, 2026 12:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
本 PR 为 Terre 的脚本编辑器引入第三方语言服务器(LSP)支持。用户可通过简单的启动脚本,将自行实现的 LSP 服务器(不限语言,如 Rust、Node.js 等)接入编辑器,用以增强或替换现有的补全、诊断等语言功能。
背景与动机
Terre 内置的语言服务虽稳定可靠,但其提供的补全、诊断等能力相对基础,难以满足跨文件引用分析、更精准的语义高亮等进阶需求。通过开放 LSP 接入机制,社区成员可自由为 Terre 构建功能更丰富的语言服务。
核心设计
稳定的切换机制
切换 LSP 时,前端会自动保存所选配置并触发页面刷新,以彻底重置所有连接与状态。该设计虽然简洁,但能有效规避复杂重连逻辑可能引入的各类边界问题,保证切换过程的可靠性。刷新后编辑器会自动恢复此前打开的文件,保持工作连续性。
通用请求转发
在第三方模式下,所有非控制类 LSP 请求(如补全、悬停、定义跳转、语义高亮等)均被透明转发至外部 LSP,无需维护显式白名单。这一机制使第三方 LSP 可完整提供其所支持的全部功能,且未来新增的 LSP 方法将自动获得支持,无需修改 Terre 自身代码。
URI 映射
Monaco 编辑器内部使用
inmemory://等虚拟 URI 方案,而标准 LSP 协议要求file://格式的真实文件路径。代理层负责两者之间的透明转换,使第三方 LSP 无需关心 URI 格式差异。动态工作区更新
当用户在 Terre 中切换编辑不同项目时,代理会主动向第三方 LSP 发送工作区变更通知,并传递新的工作区信息,无需用户手动重新加载编辑器。
内置扩展协议
代理层内置了对常见文件操作请求的支持,如
workspace/fs/readFile、readDirectory、exists,使第三方 LSP 能够安全地访问项目文件。所有文件访问均经过严格的路径校验,防止越权访问。接入方式
要接入自定义 LSP,需完成以下步骤:
~/.webgal_terre/third-party-ls/<服务器名称>/目录下放置start.js文件。第三方开发者仅需掌握标准 LSP 服务器编写方法,并提供一个十余行的启动脚本,而无需深入了解 Terre 内部实现,接入门槛较低。
已有适配器示例
为验证该机制的可行性,我已为 WebGAL 语言服务器项目实现了 Terre 适配器:
实际运行效果如下:

影响范围
本次改动仅针对脚本编辑器(基于 Monaco 的文本编辑区域),图形编辑器及其他模块不受任何影响。在不使用第三方 LSP 的情况下,脚本编辑器的所有行为与之前完全一致。
涉及文件
third-party/types.ts与third-party/scanner.service.ts(后端)webgalLsp.ts,采用通用转发与动态切换thirdPartyLanguageServer.ts与nativeLanguageServer.ts,分离两种模式lsp.ts(增加刷新切换机制)、TextEditor.tsx、AppSettingsDialog.tsx此 PR 描述由 AI 生成