VS Code / Cursor Editor Support
To provide developers with a modern, responsive editing experience, the official Xu ecosystem maintains an editor extension in the standalone vscode-xu repository, natively supporting both Visual Studio Code and Cursor IDE. The extension is driven by high-fidelity TextMate grammar definitions and the compiler's self-hosted Language Server Protocol (LSP) engine.
1. Core Language Server Capabilities
Powered by the compiler's built-in xu lsp (and companion tool xu-lsp), the extension provides the following language services, with the current query and edit scopes described below:
| Feature | Keybinding (macOS / Win) | Capabilities & Details |
|---|---|---|
| Syntax Highlighting | Real-time | Precise TextMate grammar aligned with official lexer rules, coloring keywords, control flow, types ($, struct, chan), statement symbols (<<, >>>, <<<, ->, <-), and annotations (@main). |
| Live Diagnostics | As-you-type squiggles | Continuous background type-checking and borrow-checker verification, surfacing compile errors and type mismatches directly inline. |
| Go to Definition | F12 / Cmd+Click |
Instantly navigates to declarations of structs, functions, global constants, methods, and interface implementations—including transparent navigation into standard library source files. |
| Hover Tooltips | Mouse hover | Hovering over any identifier reveals exact type signatures, mutability flags ($), and Markdown-formatted documentation comments. |
| IntelliSense Completion | Ctrl+Space |
Completion suggestions come mainly from keywords, built-in functions, and declarations in the current file. Semantic completion for member chains and external packages is limited. |
| Find All References | Shift+F12 |
Matches identifier text in the current file and sibling .xu files in the same directory. Results may include unrelated symbols with the same spelling. |
| Rename Symbol Refactoring | F2 |
Produces edits only for the current file using identifier text matching. Review the edit preview, including unrelated symbols with the same spelling; update other files separately. |
| Document Outline & Breadcrumbs | Cmd+Shift+O / Ctrl+Shift+O |
Hierarchical outline listing all structs, enums, and functions in the current file with fast fuzzy-search filtering. |
| ワークスペースシンボル検索 | Cmd+T / Ctrl+T |
workspace/symbol を通じてワークスペース全体のシンボルを検索し、プロジェクト横断の高速なナビゲーションを提供します。 |
| クイックフィックス Code Action | Cmd+. / Ctrl+. |
非推奨の or エラーハンドラの >>> への移行や、不変束縛への $ 可変性付与など、textDocument/codeAction クイックフィックスを提供します。 |
| Format on Save | Cmd+S / Ctrl+S |
Invokes the production xu fmt tool on file save, ensuring 100% consistent team code formatting and indentation. |
ワークスペースシンボル検索とクイックフィックス Code Action(0.15.0)
Xu 0.15.0 以降、xu-lsp は新たに 2 つの LSP 機能(workspaceSymbolProvider と codeActionProvider)を公開します。
- ワークスペースシンボル検索(
workspace/symbol):開いているワークスペース内のファイルを横断して関数・構造体・各種宣言を検索します。 - エラー構文移行クイックフィックス(
textDocument/codeAction):0.15.0で旧or (err) { }/or >>エラー処理が削除されたため、xu-lspは旧or (...)ハンドラを>>> (...)へ書き換えるReplace deprecated 'or' with '>>>'を提供します。さらに不変代入診断向けのMake '<name>' mutable ($<name>)やFormat Documentも利用できます。
2. Installation Methods
Method A: Install from VSIX Archive (Recommended)
Unpack the Xu 0.16.0 SDK and open its editors/vscode/ directory. It includes xu-language-0.3.0.vsix; the extension version is independent of the compiler version. Install through the CLI or editor UI:
# Install in VS Code via terminal
code --install-extension xu-language-0.3.0.vsix
# Install in Cursor via terminal
cursor --install-extension xu-language-0.3.0.vsix
Alternatively, open the Extensions panel in VS Code or Cursor, click the ... menu in the upper right, choose Install from VSIX..., select the downloaded file, and click Reload Window.
Method B: Build from Source
To contribute to the extension or test unreleased features, build directly from the git repository:
# Clone the official repository
git clone https://github.com/xulang-org/vscode-xu.git
cd vscode-xu
# Install dependencies and package VSIX
npm ci
npm run package
# Install the freshly built package
code --install-extension xu-language-*.vsix
3. Recommended Editor Settings (settings.json)
Press Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux), select Preferences: Open User Settings (JSON), and add the following configuration:
{
// Path to the Xu compiler binary ("xu" if in your system PATH)
"xu.languageServerPath": "xu",
// Language server trace logging level ("off", "messages", or "verbose")
"xu.trace.server": "off",
// Xu language specific editor settings
"[xu]": {
"editor.defaultFormatter": "xu-lang.xu-language",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.suggestOnTriggerCharacters": true,
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
}
}
}
4. Keyboard Shortcuts Cheat Sheet
| Action | macOS Shortcut | Windows / Linux Shortcut | Description |
|---|---|---|---|
| Go to Definition | F12 or Cmd+Click |
F12 or Ctrl+Click |
Navigate to the declaration of a function, struct, or variable |
| Find All References | Shift+F12 |
Shift+F12 |
List identifier matches in the current file and same-directory Xu files |
| Rename Symbol | F2 |
F2 |
Preview identifier replacements in the current file |
| Document Outline | Cmd+Shift+O |
Ctrl+Shift+O |
Fuzzy search functions, structs, and symbols in the active file |
| Format Document | Option+Shift+F |
Alt+Shift+F |
Format the active document using xu fmt |
| Trigger Completion | Ctrl+Space |
Ctrl+Space |
Manually display IntelliSense completion suggestions |
Open Source & Independence: The official extension is open-sourced under the MIT License. The independent vscode-xu repository evolves independently from the compiler core while remaining 100% synchronized with the latest grammar specification.