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. |
| Symboles de l’espace de travail | Cmd+T / Ctrl+T |
Recherche des symboles dans tout l’espace de travail via workspace/symbol pour une navigation rapide dans le projet. |
| Actions rapides (Quick-Fix) | Cmd+. / Ctrl+. |
Fournit des actions de code textDocument/codeAction, dont la migration des anciens gestionnaires d’erreur or vers >>> et l’ajout de la mutabilité $ sur les liaisons immuables. |
| Format on Save | Cmd+S / Ctrl+S |
Invokes the production xu fmt tool on file save, ensuring 100% consistent team code formatting and indentation. |
Symboles de l’espace de travail et actions rapides (0.15.0)
À partir de Xu 0.15.0, xu-lsp expose deux capacités LSP supplémentaires (workspaceSymbolProvider et codeActionProvider) :
- Recherche de symboles dans l’espace de travail (
workspace/symbol) : recherchez des fonctions, structures et déclarations dans tous les fichiers de l’espace de travail ouvert. - Correction rapide de migration de syntaxe d’erreur (
textDocument/codeAction) : comme l’ancienne gestion d’erreuror (err) { }/or >>est supprimée en0.15.0,xu-lsppropose l’action rapideReplace deprecated 'or' with '>>>'pour réécrire les anciens gestionnairesor (...)en>>> (...), ainsi queMake '<name>' mutable ($<name>)pour les diagnostics d’assignation immuable etFormat 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.