Skip to content

feat: third party lsp support - #639

Open
fltLi wants to merge 11 commits into
OpenWebGAL:devfrom
fltLi:feat/third-party-lsp
Open

feat: third party lsp support#639
fltLi wants to merge 11 commits into
OpenWebGAL:devfrom
fltLi:feat/third-party-lsp

Conversation

@fltLi

@fltLi fltLi commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

概述

为脚本编辑器加入第三方 LSP 支持。

使用者可以在用户数据目录下的 third-party-ls/ 目录下存放第三方 LSP,每个 LSP 需要包含一个 start.js 作为启动脚本,并导出:

interface LspLauncher {
  name?: string;
  start(): Promise<{ reader: MessageReader; writer: MessageWriter }>;
  stop?(): Promise<void>;
}

Terre 会自动扫描第三方 LSP 列表,使用者可以在 设置 -> 代码编辑器 -> 语言服务 中查看并选择。
其中 内置语言服务 项为保留的原生实现。

动机

目前 WebGAL 社区里有多个 LSP 实现,例如 xiaoxustudio/webgal-language-tools,以及我的 fltLi/webgal-lsp

这些 LSP 都或多或少在某些方面提供了比 Terre 原生更丰富、多样化的语言服务实现。
如果能在脚本编辑中集成它们,将会为使用者在 Terre 本身完备的功能基础上带来更个性化的使用体验。

实现

后端新增一个 LSP 代理层,把 Monaco 客户端桥接到第三方 LSP 进程;内置与第三方共用同一套 LanguageServer 接口,按 languageServerId 分流。详细设计见 packages/terre2/src/Modules/lsp/README.md

  • 后端:ThirdPartyLanguageServer 转发除控制请求外的 LSP 消息,并由 chokidar 代理文件监视、UriMapper 做 URI 映射、WorkspaceEditApplier 落地 applyEdit。
  • 前端:设置面板新增「语言服务」选择菜单,切换后刷新页面重建连接。

测试

本次改动新增 7 个 spec、31 个用例,覆盖工厂分流、URI 映射、文件监视、applyEdit、launcher 扫描以及初始化 / 转发 / 生命周期,本地测试全部通过。

实际编写约 3k 行 WebGAL 脚本使用中暴露的问题均已修复。

@fltLi
fltLi marked this pull request as draft August 4, 2026 01:06
@fltLi

This comment was marked as resolved.

@fltLi
fltLi marked this pull request as ready for review August 4, 2026 04:31
@fltLi
fltLi marked this pull request as draft August 4, 2026 06:52
@fltLi

This comment was marked as resolved.

fltLi added 3 commits August 6, 2026 20:41
- 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
fltLi marked this pull request as ready for review August 6, 2026 12:55
MakinoharaShoko and others added 2 commits September 1, 2026 20:29
chokidar 5.x is ESM-only and dropped glob expansion in watch(), so the backend proxy forwarding workspace/didChangeWatchedFiles silently watched nothing in the pkg'd artifact. Local dev only worked because node_modules still carried chokidar 3.x. Pin chokidar to ^3.6.0.

Refactor the third-party LSP proxy into focused modules and share control-request plumbing with the native server: extract UriMapper, FileWatcherRegistry and WorkspaceEditApplier; add a BaseLanguageServer and a single LanguageServer interface; drop a duplicated didClose forward.
@fltLi
fltLi marked this pull request as draft September 5, 2026 09:17
@fltLi

fltLi commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

正在完成人工编写 PR 描述等任务,并审阅和优化相关实现,以便对齐最新文档指出的 AI 代码要求。

@monaco-editor/react mounts the editor with its default light theme and creates the model before the vscode services (theme + textmate grammar) finish initializing, so reloading straight into the editor — or a tab the browser discarded/awoke — left it white with plain black text.

Gate the editor mount on monaco services being ready, re-apply the vscode editor config on mount and when the page regains visibility, and fix the dark theme id typo in the store (WebGAL Dark -> WebGAL Black).
Add Jest specs for the language-server factory, URI mapping, file-watcher registry, workspace-edit applier, launcher scanner, and the native/third-party servers (34 tests).

Remove dead code and defensive branches: gateway debug logging, native config boilerplate, a no-op workspace sync block, and any types on the launcher.

Fix workspace/applyEdit rename to read oldUri/newUri per the LSP spec, and use a Dropdown for the language-service selector so no text caret appears. Document the module architecture in Modules/lsp/README.md.
@fltLi
fltLi marked this pull request as ready for review September 5, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants