Cnext Language Support for VS Code
Syntax highlighting, snippets, linting, formatting, and build tasks for the Cnext programming language.
Installation
Option 1: From VSIX (Recommended)
Install the Cnext compiler first:
# Linux/macOS
curl -fsSL https://raw.githubusercontent.com/Melton122/cnext/main/install.sh | bash
# Windows
install.bat
Package and install the extension:
cd vscode-extension
npm install -g @vscode/vsce
vsce package
code --install-extension cnext-10.0.2.vsix
Option 2: Manual Installation
- Copy this
vscode-extension/ folder to your extensions directory:
- Windows:
%USERPROFILE%\.vscode\extensions\cnext-10.0.2
- macOS/Linux:
~/.vscode/extensions/cnext-10.0.0
- Restart VS Code
Option 3: From Marketplace
Search for "Cnext" in the VS Code Extensions panel (Ctrl+Shift+X).
Features
- Syntax Highlighting — Full syntax highlighting for all Cnext language features (keywords, types, builtins, string interpolation, doc comments)
- Code Snippets — 25+ snippets for common patterns (classes, functions, closures, etc.)
- IntelliSense (LSP) — Real-time diagnostics, autocomplete, hover docs, and go-to-definition via the bundled language server
- Format — Format on save or with
Shift+Alt+F (LSP for in-place edits, compiler fallback)
- Build Tasks — Run, build, and test Cnext files with keyboard shortcuts
- New Project — Create a new Cnext project from VS Code
- REPL — Start an interactive REPL from the command palette
- Doctor — Check your environment for common issues
- Status Bar — Shows the language server status; click to run the environment check
Language Server (LSP)
The extension ships a Python-based language server (lsp/server.py) that provides:
- Diagnostics — compile errors/warnings from the Cnext compiler appear as you type (debounced)
- Autocomplete — keywords, types, ~150 builtins, and identifiers from the open file
- Hover — quick docs for keywords, types, and builtins
- Go to Definition — jump to declarations in the current file
- Format Document — in-place formatting (no revert-and-reopen)
Requires a Python 3 interpreter on your PATH (or set cnext.lsp.pythonPath).
If Python is unavailable, all other features still work.
Commands
Open the Command Palette (Ctrl+Shift+P) and type "Cnext":
| Command |
Description |
Shortcut |
| Cnext: Run File |
Compile and run the current file |
Ctrl+Shift+R |
| Cnext: Build File |
Build to executable |
Ctrl+Shift+B |
| Cnext: Build Release |
Build optimized release |
- |
| Cnext: Run Tests |
Run project tests |
Ctrl+Shift+T |
| Cnext: Format File |
Format the current file |
Shift+Alt+F |
| Cnext: Lint File |
Check for issues |
- |
| Cnext: New Project |
Create a new project |
- |
| Cnext: Doctor |
Check environment |
- |
| Cnext: Start REPL |
Start interactive REPL |
- |
| Cnext: Restart Language Server |
Restart the LSP server |
- |
| Cnext: Show LSP Log |
Show LSP activity in the output panel |
- |
Snippets
Type a prefix and press Tab to insert:
| Prefix |
Description |
main |
Main block |
func |
Function declaration |
func => |
Arrow function |
class |
Class declaration |
struct |
Struct declaration |
enum |
Enum declaration |
trait |
Trait declaration |
interface |
Interface declaration |
if |
If statement |
ifelse |
If-else statement |
while |
While loop |
for |
For loop |
forin |
For-in loop |
match |
Match expression |
try |
Try-catch block |
lambda |
Lambda expression |
generator |
Generator function |
async |
Async function |
import |
Import statement |
test |
Test block |
Configuration
Open Settings (Ctrl+,) and search for "Cnext":
| Setting |
Default |
Description |
cnext.compilerPath |
cnext |
Path to the Cnext compiler |
cnext.autoRun |
false |
Automatically run file after save |
cnext.autoFormat |
false |
Automatically format file after save |
cnext.lsp.enable |
true |
Enable the language server |
cnext.lsp.pythonPath |
(auto) |
Python interpreter for the language server |
cnext.lsp.serverPath |
(bundled) |
Path to the language server script |
Requirements
- Cnext compiler installed and in PATH
- GCC or Clang compiler for building Cnext programs
Troubleshooting
"cnext: command not found"
Set the compiler path in VS Code settings:
- Open Settings (Ctrl+,)
- Search for "Cnext Compiler Path"
- Set the full path to your
cnext executable
Syntax highlighting not working
Make sure the file has the .cn extension and the language mode is set to "Cnext" (bottom-right corner of VS Code).
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
MIT License