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. |
| Símbolos do workspace | Cmd+T / Ctrl+T |
Consulta símbolos em todo o workspace via workspace/symbol para navegação rápida por todo o projeto. |
| Ações rápidas (Quick-Fix) | Cmd+. / Ctrl+. |
Fornece ações rápidas textDocument/codeAction, incluindo a migração de manipuladores or obsoletos para >>> e adição de mutabilidade $ em vínculos imutáveis. |
| Format on Save | Cmd+S / Ctrl+S |
Invokes the production xu fmt tool on file save, ensuring 100% consistent team code formatting and indentation. |
Símbolos do workspace e ações rápidas (0.15.0)
A partir do Xu 0.15.0, o xu-lsp expõe dois recursos adicionais de LSP (workspaceSymbolProvider e codeActionProvider):
- Busca de símbolos do workspace (
workspace/symbol): Pesquise funções, structs e declarações entre arquivos no workspace aberto. - Ação rápida de migração da sintaxe de erros (
textDocument/codeAction): Como o tratamento de erro legadoor (err) { }/or >>foi removido no0.15.0, oxu-lspoferece a ação rápidaReplace deprecated 'or' with '>>>'para reescrever manipuladoresor (...)legados como>>> (...), além deMake '<name>' mutable ($<name>)para diagnósticos de atribuição imutável eFormat 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.