KLang VS Code Extension
Official Visual Studio Code extension for the KLang programming language - The AI-Native Programming Language.
Features
🎨 Syntax Highlighting
- Complete syntax highlighting for KLang (.kl, .k, .klang files)
- Support for all language features:
- Functions (regular and async)
- Classes with inheritance
- Template literals
- Arrow functions
- Async/await
- Generators
- Import/Export
- Comments (line and block)
- All operators and keywords
📝 Code Snippets
Over 40 comprehensive code snippets for:
- Functions (regular, async, arrow, generators)
- Classes (basic, inheritance, abstract)
- Control flow (if/else, loops, try/catch)
- Async operations (promises, async/await)
- Array methods (map, filter, reduce, forEach)
- Destructuring and spread operators
- Import/Export statements
- AI and HTTP operations
⚡ Commands
Run Current File (Ctrl+Shift+R / Cmd+Shift+R)
- Execute the currently open KLang file
Build Current File (Ctrl+Shift+B / Cmd+Shift+B)
- Build the current file with the KLang compiler
Check Syntax (Ctrl+Shift+C / Cmd+Shift+C)
- Check syntax without executing
Format Document (Ctrl+Shift+F / Cmd+Shift+F)
- Format the current KLang file (when formatter is available)
Open REPL
- Launch an interactive KLang REPL session
🔍 Advanced Editor Features
- Document Symbol Outline - Navigate functions, classes, interfaces, enums, and variables
- Hover Documentation - Rich markdown documentation with examples for all keywords
- Context Menu Integration - Quick access to common commands
- Editor Title Run Button - One-click execution
- Auto-formatting on save or on-demand
- Intelligent Linting with real-time error detection
- Definition Provider to jump to symbol definitions
- Range Formatting to format selected code
🎯 Language Server Protocol (LSP)
Fully integrated Language Server with advanced features:
- Smart Code Completion - 40+ snippets with trigger characters (
., :)
- Go to Definition - Jump to function, class, and variable definitions
- Find References - Find all usages across your codebase
- Hover Information - Detailed documentation with syntax examples
- Real-time Diagnostics - Inline errors and warnings as you type
- Document Symbols - Quick navigation and outline view
- Code Formatting - Consistent code style with KLang formatter
Installation
From VSIX
- Download the
.vsix file
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Click "..." menu → "Install from VSIX..."
- Select the downloaded
.vsix file
From Source
- Clone the KLang repository
- Navigate to the
vscode-klang directory
- Run:
npm install
npm run compile
- Press F5 to open Extension Development Host
Requirements
- Visual Studio Code 1.75.0 or higher
- KLang compiler installed and available in PATH
Usage
Running KLang Files
Method 1: Command Palette
- Open a
.kl, .k, or .klang file
- Press
Ctrl+Shift+P (or Cmd+Shift+P on Mac)
- Type "KLang: Run Current File"
- Press Enter
Method 2: Keyboard Shortcut
- Open a KLang file
- Press
Ctrl+Shift+R (or Cmd+Shift+R on Mac)
Method 3: Context Menu
- Right-click in the editor
- Select "KLang: Run Current File"
Method 4: Run Button
- Click the run button in the editor title bar
Using Code Snippets
Type a snippet prefix and press Tab:
fn → Function declaration
afn → Async function
class → Class declaration
if → If statement
for → For-of loop
promise → Promise creation
map → Array map
log → Print to console
- ...and many more!
Configuration
Configure the extension in VS Code settings:
{
// Enable/disable Language Server
"klang.languageServer.enabled": true,
// Path to KLang executable (default: searches PATH)
"klang.languageServer.path": "klang",
// Language Server trace level
"klang.trace.server": "off",
// Enable/disable formatting
"klang.format.enabled": true,
// Enable/disable linting
"klang.lint.enabled": true
}
KLang Language Quick Reference
Variables
let x = 10 # Mutable variable
const y = 20 # Constant
var z = 30 # Function-scoped
Functions
# Regular function
fn add(a: int, b: int) -> int {
return a + b
}
# Arrow function
const multiply = (a, b) => a * b
# Async function
async fn fetchData() {
const data = await fetch("https://api.example.com")
return data
}
Classes
class Person {
let name: string = ""
let age: int = 0
fn init(name: string, age: int) {
this.name = name
this.age = age
}
fn greet() {
println(`Hello, I'm ${this.name}`)
}
}
let person = new Person("Alice", 30)
person.greet()
Array Methods
let numbers = [1, 2, 3, 4, 5]
let doubled = numbers.map(x => x * 2)
let evens = numbers.filter(x => x % 2 == 0)
let sum = numbers.reduce((acc, x) => acc + x, 0)
Keyboard Shortcuts
| Command |
Windows/Linux |
macOS |
| Run Current File |
Ctrl+Shift+R |
Cmd+Shift+R |
| Build Current File |
Ctrl+Shift+B |
Cmd+Shift+B |
| Check Syntax |
Ctrl+Shift+C |
Cmd+Shift+C |
| Format Document |
Ctrl+Shift+F |
Cmd+Shift+F |
Known Issues
- Some LSP features require the KLang compiler to be installed and available in PATH
- Debugger support is planned for future releases
- Some advanced refactoring features are in development
Contributing
Contributions are welcome! Please see the main KLang repository for contribution guidelines.
Development Setup
- Clone the repository
cd vscode-klang
npm install
- Press F5 to start debugging
Building VSIX
npm install
npm run compile
npm run package
This will create a .vsix file you can install.
Release Notes
See CHANGELOG.md for detailed release notes.
1.0.0
- Initial release with comprehensive features
- Full syntax highlighting for all KLang constructs
- 40+ intelligent code snippets with placeholders
- Commands for run, build, check, and format
- Language Server Protocol (LSP) integration
- Smart code completion with snippets
- Real-time diagnostics and linting
- Go to definition support
- Hover documentation with examples
- Document symbols and outline
- Advanced formatting with KLang formatter
- Real-time linting with debounced diagnostics
- Enhanced document symbol provider (functions, classes, interfaces, enums)
- Definition provider for navigation
- Range formatting support
License
MIT License - See LICENSE for details.
Links
Enjoy coding with KLang! 🚀