@ttsc/vscode

@ttsc/vscodepackages/vscode)是 VS Code 扩展,把 vscode-languageclient 接到 ttscserver,暴露内建 lint/format 命令桥,并让其他插件命令 id 经语言客户端用编辑器应用的 WorkspaceEdit 执行。

三个源文件

packages/vscode/src/
├── extension.ts          # 扩展激活入口, 起语言客户端
├── serverResolution.ts   # 解析 ttscserver 二进制
└── commandEdits.ts       # 命令 -> WorkspaceEdit 应用

扩展薄:它的真正工作是 ttscserver 做的(见 LSP 代理),扩展只是把编辑器接上去。

它做什么

  • extension.ts:激活时起语言客户端,连 ttscserver,获得 tsgo 的 hover/completion/definition/diagnostics 加 ttsc 插件的诊断与 code action。
  • serverResolution.ts:解析 ttscserver 二进制(经平台包或显式路径)。
  • commandEdits.ts:当 ttsc 命令返回 WorkspaceEdit(不是发 workspace/applyEdit 请求,见 code action 与命令),扩展在编辑器侧应用它。这正是 LSP 代理"把 edit 放进 executeCommand 响应"设计的对端——ttsc 拥有两端。

编辑器配置

README(根 README.md 的 VS Code 节)给出推荐设置:

// .vscode/settings.json
"[typescript][typescriptreact]": {
  "editor.defaultFormatter": "samchon.ttsc",
  "editor.formatOnSave": true
}

lint 修复默认 off-save,opt-in:"editor.codeActionsOnSave": { "source.fixAll.ttsc": "explicit" }

format-on-save 走 textDocument/formatting,被 ttscserver 代理拦截、格式化活缓冲区(见 格式化与脏文档跟踪)。这是 ttsc 强制声明 documentFormattingProvider 的原因——tsgo 的格式化器会格式化磁盘文件、丢未保存编辑。

安装

从 Marketplace 搜 ttsc,或 npx @ttsc/vscode

不变量

  • 扩展薄,重活在 ttscserver。
  • 命令 edit 经 executeCommand 响应回、扩展应用(ttsc 拥有两端),不发 applyEdit 请求。
  • format 经 textDocument/formatting,被代理拦截格式化活缓冲区。

接下来