VS Code 与 LSP

Lux 的编辑器支持由 lux-gmod 扩展启动选定 compiler 的 luxc lsp 提供。扩展本身保持很薄:负责启动 compiler language server、贡献语法和命令、展示 server 返回结果。Lux module resolution、realm 检查、import/export completion、hover、diagnostics 和 GMod API 智能都来自实际用于 build 的同一个 compiler 版本。

安装

扩展包名是 Althurdinok.lux-gmod。在 alpha 开发阶段,也可以从 lsp/vscode-lux workspace 本地打包 VS Code 扩展:

cd lsp\vscode-lux
npm install
npm run compile
npm run package
code --install-extension (Get-ChildItem .\lux-gmod-*.vsix | Select-Object -First 1).FullName

VSIX 不再内置独立 language server binary。请配置你希望编辑器使用的 compiler executable,或让它能从 workspace / PATH 找到:

{
  "lux.compiler.path": "C:\\Tools\\lux\\luxc.exe"
}

Server 查找顺序

扩展通过下面的命令启动 server:

luxc lsp

扩展按这个顺序查找 luxc

  1. lux.compiler.path
  2. workspace .lux/bin/luxc
  3. 用户目录 ~/.lux/bin/luxc
  4. LUXC 环境变量
  5. PATH 中的 luxc

Compiler 命令

构建和数据更新命令会使用同一个解析出来的 luxc

常用命令:

  • Lux: Compile Current Project
  • Lux: Update Garry's Mod API Database
  • Lux: Format Document
  • Lux: Show Module Exports
  • Lux: Show Active Realm
  • Lux: Show GMod API Coverage

编辑器智能

当前 server 支持:

  • parser、resolver、formatter、module graph、realm 检查和 import 诊断
  • import source completion
  • 根据 exported name 和 active realm 过滤的 import specifier completion
  • 基于 module-scope binding 的 export list completion
  • GMod API root/member completion
  • 基于 LocalPlayer()vgui.Create("DButton") 等事实推断的 method completion
  • Lux binding、export、import、跨 part 定义、导入模块 export、已知 GMod API、hook 和官方文档 hover
  • Lux function、GMod function、method、hook callback signature help
  • 已知 Lux function call 的参数数量诊断
  • multi-part module 跨文件 definition,以及通过 imported module export 跳转到真实定义
  • Lux 语法、known external、unknown external 的 semantic tokens
  • 通过 compiler formatter 格式化文档

Quick Fixes

Lux quick fixes 来自 compiler analysis 和 LSP server 数据:

  • 添加源码级 extern
  • lux.toml 添加 package-level extern
  • client { ... }server { ... } 包装 realm-specific 代码
  • 收窄无效的 export realm
  • 为 realm mismatch 打开 GMod 官方文档
  • 当 formatter 报告诊断时格式化当前文档

未知外部符号不会被当成 shared-safe。它们会以 UnknownExternal 独立跟踪,并根据 target.gmod.realm.unknown_external 报告。

官方 GMod API 数据

gmod-api-db 从 Facepunch 官方 pagelist 和单页 JSON 生成。它为每个官方页面生成 document record,并为 function、hook、class、panel、constant、enum 和 realm 生成结构化 API 索引。

这是发布门槛,不只是方便缓存:bundled database 必须证明 document_page_count == official_page_countstructured_page_count == api_candidate_countfallback_page_count == 0failed_page_count == 0。手写数据只能作为测试 fixture,或作为官方生成后叠加的、可追溯 override patch。

VS Code 扩展通过 luxc lsp 使用这些数据;扩展自身不维护 API 表。