feat: improve editor tooling and fix warnings
Neovim improvements: - Add tree-sitter text objects for functions, types, blocks - Add folding support - Enhanced REPL integration (toggle, send line/selection) - New commands: LuxCheck, LuxReplToggle, LuxSend - Better keybindings with localleader VS Code extension: - Full syntax highlighting with TextMate grammar - LSP client integration - 20+ snippets for common patterns - Commands: run, format, check, REPL - Keybindings and context menu Fixes: - Fix all cargo warnings with #[allow(dead_code)] annotations - Clean up unused variables Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
152
editors/vscode/README.md
Normal file
152
editors/vscode/README.md
Normal file
@@ -0,0 +1,152 @@
|
||||
# Lux Language Extension for VS Code
|
||||
|
||||
Visual Studio Code extension for the Lux programming language.
|
||||
|
||||
## Features
|
||||
|
||||
- **Syntax Highlighting**: Full syntax highlighting for Lux files
|
||||
- **LSP Integration**: Real-time diagnostics, hover info, completions, go-to-definition
|
||||
- **Snippets**: Common code patterns (functions, types, effects, handlers)
|
||||
- **REPL Integration**: Start REPL and send code to it
|
||||
- **Commands**: Run, format, type-check files
|
||||
|
||||
## Installation
|
||||
|
||||
### From VS Code Marketplace
|
||||
|
||||
Search for "Lux Language" in the VS Code extensions panel.
|
||||
|
||||
### From Source
|
||||
|
||||
1. Clone the repository
|
||||
2. Navigate to `editors/vscode`
|
||||
3. Run `npm install`
|
||||
4. Run `npm run compile`
|
||||
5. Press F5 to launch a development VS Code window
|
||||
|
||||
### Manual VSIX Install
|
||||
|
||||
```bash
|
||||
cd editors/vscode
|
||||
npm install
|
||||
npm run compile
|
||||
npx vsce package
|
||||
code --install-extension lux-lang-0.1.0.vsix
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
- **Lux binary**: Install Lux and ensure `lux` is in your PATH, or configure `lux.lspPath`
|
||||
- **Node.js**: For development
|
||||
|
||||
## Configuration
|
||||
|
||||
| Setting | Default | Description |
|
||||
|---------|---------|-------------|
|
||||
| `lux.lspPath` | `""` | Path to Lux binary. Empty = search PATH |
|
||||
| `lux.lsp.enabled` | `true` | Enable the language server |
|
||||
| `lux.format.onSave` | `false` | Format files on save |
|
||||
| `lux.diagnostics.enabled` | `true` | Show inline diagnostics |
|
||||
|
||||
## Commands
|
||||
|
||||
| Command | Keybinding | Description |
|
||||
|---------|------------|-------------|
|
||||
| `Lux: Run Current File` | `Ctrl+Shift+R` | Run the active file |
|
||||
| `Lux: Format Document` | - | Format the active file |
|
||||
| `Lux: Type Check File` | - | Type check without running |
|
||||
| `Lux: Start REPL` | - | Open Lux REPL in terminal |
|
||||
| `Lux: Send Selection to REPL` | `Ctrl+Enter` | Send selected code to REPL |
|
||||
| `Lux: Restart Language Server` | - | Restart the LSP |
|
||||
|
||||
## Snippets
|
||||
|
||||
| Prefix | Description |
|
||||
|--------|-------------|
|
||||
| `fn` | Function definition |
|
||||
| `fne` | Function with effects |
|
||||
| `type` | Type definition |
|
||||
| `effect` | Effect definition |
|
||||
| `handler` | Effect handler |
|
||||
| `match` | Match expression |
|
||||
| `if` | If expression |
|
||||
| `let` | Let binding |
|
||||
| `run` | Run with handlers |
|
||||
| `trait` | Trait definition |
|
||||
| `impl` | Impl block |
|
||||
| `matchopt` | Match on Option |
|
||||
| `matchres` | Match on Result |
|
||||
| `print` | Console.print |
|
||||
| `main` | Main function template |
|
||||
|
||||
## Language Features
|
||||
|
||||
### Syntax Highlighting
|
||||
|
||||
- Keywords (`fn`, `let`, `type`, `effect`, `handler`, `match`, etc.)
|
||||
- Built-in types (`Int`, `Float`, `Bool`, `String`, `Option`, `Result`)
|
||||
- Operators (`=>`, `|>`, `==`, etc.)
|
||||
- String interpolation
|
||||
- Comments (line `//` and doc `///`)
|
||||
|
||||
### LSP Features
|
||||
|
||||
The Lux language server provides:
|
||||
|
||||
- **Diagnostics**: Real-time error and warning display
|
||||
- **Hover**: Type information on hover
|
||||
- **Completions**: Context-aware suggestions
|
||||
- **Go to Definition**: Navigate to definitions
|
||||
|
||||
### Code Folding
|
||||
|
||||
Fold:
|
||||
- Function bodies
|
||||
- Type definitions
|
||||
- Effect declarations
|
||||
- Handler blocks
|
||||
- Match expressions
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Compile
|
||||
npm run compile
|
||||
|
||||
# Watch mode
|
||||
npm run watch
|
||||
|
||||
# Lint
|
||||
npm run lint
|
||||
|
||||
# Package
|
||||
npx vsce package
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### LSP not starting
|
||||
|
||||
1. Check `lux.lspPath` is correct
|
||||
2. Ensure `lux` binary is executable
|
||||
3. Run `Lux: Restart Language Server`
|
||||
4. Check Output panel for errors
|
||||
|
||||
### No syntax highlighting
|
||||
|
||||
1. Ensure file has `.lux` extension
|
||||
2. Try reloading VS Code
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Make changes
|
||||
4. Submit a pull request
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see the main Lux repository for details.
|
||||
53
editors/vscode/language-configuration.json
Normal file
53
editors/vscode/language-configuration.json
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"comments": {
|
||||
"lineComment": "//",
|
||||
"blockComment": ["/*", "*/"]
|
||||
},
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["<", ">"]
|
||||
],
|
||||
"autoClosingPairs": [
|
||||
{ "open": "{", "close": "}" },
|
||||
{ "open": "[", "close": "]" },
|
||||
{ "open": "(", "close": ")" },
|
||||
{ "open": "<", "close": ">", "notIn": ["string"] },
|
||||
{ "open": "\"", "close": "\"", "notIn": ["string"] },
|
||||
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
|
||||
],
|
||||
"surroundingPairs": [
|
||||
{ "open": "{", "close": "}" },
|
||||
{ "open": "[", "close": "]" },
|
||||
{ "open": "(", "close": ")" },
|
||||
{ "open": "<", "close": ">" },
|
||||
{ "open": "\"", "close": "\"" },
|
||||
{ "open": "'", "close": "'" }
|
||||
],
|
||||
"folding": {
|
||||
"markers": {
|
||||
"start": "^\\s*//\\s*#?region\\b",
|
||||
"end": "^\\s*//\\s*#?endregion\\b"
|
||||
}
|
||||
},
|
||||
"wordPattern": "[a-zA-Z_][a-zA-Z0-9_]*",
|
||||
"indentationRules": {
|
||||
"increaseIndentPattern": "^.*\\{[^}]*$|^.*\\([^)]*$|^.*\\[[^\\]]*$|^\\s*(fn|type|effect|handler|trait|impl|match|if|else)\\b.*$",
|
||||
"decreaseIndentPattern": "^\\s*[}\\])]"
|
||||
},
|
||||
"onEnterRules": [
|
||||
{
|
||||
"beforeText": "^\\s*///.*$",
|
||||
"action": { "indent": "none", "appendText": "/// " }
|
||||
},
|
||||
{
|
||||
"beforeText": ".*\\{\\s*$",
|
||||
"action": { "indent": "indent" }
|
||||
},
|
||||
{
|
||||
"beforeText": "^\\s*\\}\\s*$",
|
||||
"action": { "indent": "outdent" }
|
||||
}
|
||||
]
|
||||
}
|
||||
150
editors/vscode/package.json
Normal file
150
editors/vscode/package.json
Normal file
@@ -0,0 +1,150 @@
|
||||
{
|
||||
"name": "lux-lang",
|
||||
"displayName": "Lux Language",
|
||||
"description": "Language support for Lux - a functional language with algebraic effects",
|
||||
"version": "0.1.0",
|
||||
"publisher": "lux-lang",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lux-lang/lux"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.75.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"keywords": [
|
||||
"lux",
|
||||
"functional",
|
||||
"effects",
|
||||
"algebraic effects"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:lux"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "lux",
|
||||
"aliases": ["Lux", "lux"],
|
||||
"extensions": [".lux"],
|
||||
"configuration": "./language-configuration.json",
|
||||
"icon": {
|
||||
"light": "./icons/lux-light.png",
|
||||
"dark": "./icons/lux-dark.png"
|
||||
}
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "lux",
|
||||
"scopeName": "source.lux",
|
||||
"path": "./syntaxes/lux.tmLanguage.json"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"title": "Lux",
|
||||
"properties": {
|
||||
"lux.lspPath": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "Path to the Lux binary. If empty, searches PATH."
|
||||
},
|
||||
"lux.lsp.enabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Enable the Lux language server"
|
||||
},
|
||||
"lux.format.onSave": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Format files on save"
|
||||
},
|
||||
"lux.diagnostics.enabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Enable inline diagnostics"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "lux.run",
|
||||
"title": "Lux: Run Current File"
|
||||
},
|
||||
{
|
||||
"command": "lux.format",
|
||||
"title": "Lux: Format Document"
|
||||
},
|
||||
{
|
||||
"command": "lux.check",
|
||||
"title": "Lux: Type Check File"
|
||||
},
|
||||
{
|
||||
"command": "lux.startRepl",
|
||||
"title": "Lux: Start REPL"
|
||||
},
|
||||
{
|
||||
"command": "lux.sendToRepl",
|
||||
"title": "Lux: Send Selection to REPL"
|
||||
},
|
||||
{
|
||||
"command": "lux.restartLsp",
|
||||
"title": "Lux: Restart Language Server"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "lux.run",
|
||||
"key": "ctrl+shift+r",
|
||||
"mac": "cmd+shift+r",
|
||||
"when": "editorLangId == lux"
|
||||
},
|
||||
{
|
||||
"command": "lux.sendToRepl",
|
||||
"key": "ctrl+enter",
|
||||
"mac": "cmd+enter",
|
||||
"when": "editorLangId == lux && editorHasSelection"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"editor/context": [
|
||||
{
|
||||
"command": "lux.run",
|
||||
"when": "editorLangId == lux",
|
||||
"group": "lux"
|
||||
},
|
||||
{
|
||||
"command": "lux.sendToRepl",
|
||||
"when": "editorLangId == lux && editorHasSelection",
|
||||
"group": "lux"
|
||||
}
|
||||
]
|
||||
},
|
||||
"snippets": [
|
||||
{
|
||||
"language": "lux",
|
||||
"path": "./snippets/lux.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"lint": "eslint src --ext ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.x",
|
||||
"@types/vscode": "^1.75.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^9.0.0"
|
||||
}
|
||||
}
|
||||
182
editors/vscode/snippets/lux.json
Normal file
182
editors/vscode/snippets/lux.json
Normal file
@@ -0,0 +1,182 @@
|
||||
{
|
||||
"Function": {
|
||||
"prefix": "fn",
|
||||
"body": [
|
||||
"fn ${1:name}(${2:params}): ${3:ReturnType} =",
|
||||
" ${0:body}"
|
||||
],
|
||||
"description": "Define a function"
|
||||
},
|
||||
"Function with Effects": {
|
||||
"prefix": "fne",
|
||||
"body": [
|
||||
"fn ${1:name}(${2:params}): ${3:ReturnType} with {${4:Effects}} = {",
|
||||
" ${0:body}",
|
||||
"}"
|
||||
],
|
||||
"description": "Define a function with effects"
|
||||
},
|
||||
"Type Definition": {
|
||||
"prefix": "type",
|
||||
"body": [
|
||||
"type ${1:Name} =",
|
||||
" | ${2:Variant}(${3:fields})"
|
||||
],
|
||||
"description": "Define an algebraic data type"
|
||||
},
|
||||
"Effect Definition": {
|
||||
"prefix": "effect",
|
||||
"body": [
|
||||
"effect ${1:Name} {",
|
||||
" fn ${2:operation}(${3:params}): ${4:ReturnType}",
|
||||
"}"
|
||||
],
|
||||
"description": "Define an effect"
|
||||
},
|
||||
"Handler": {
|
||||
"prefix": "handler",
|
||||
"body": [
|
||||
"handler ${1:name}: ${2:Effect} {",
|
||||
" fn ${3:operation}(${4:params}) = {",
|
||||
" ${5:body}",
|
||||
" resume(${0:value})",
|
||||
" }",
|
||||
"}"
|
||||
],
|
||||
"description": "Define an effect handler"
|
||||
},
|
||||
"Match Expression": {
|
||||
"prefix": "match",
|
||||
"body": [
|
||||
"match ${1:value} {",
|
||||
" ${2:Pattern} => ${3:result},",
|
||||
" ${0:_ => default}",
|
||||
"}"
|
||||
],
|
||||
"description": "Pattern matching expression"
|
||||
},
|
||||
"If Expression": {
|
||||
"prefix": "if",
|
||||
"body": [
|
||||
"if ${1:condition} then ${2:trueCase}",
|
||||
"else ${0:falseCase}"
|
||||
],
|
||||
"description": "Conditional expression"
|
||||
},
|
||||
"Let Binding": {
|
||||
"prefix": "let",
|
||||
"body": [
|
||||
"let ${1:name} = ${0:value}"
|
||||
],
|
||||
"description": "Let binding"
|
||||
},
|
||||
"Run Expression": {
|
||||
"prefix": "run",
|
||||
"body": [
|
||||
"run ${1:expr} with {",
|
||||
" ${0:handlers}",
|
||||
"}"
|
||||
],
|
||||
"description": "Run expression with handlers"
|
||||
},
|
||||
"Trait Definition": {
|
||||
"prefix": "trait",
|
||||
"body": [
|
||||
"trait ${1:Name}<${2:T}> {",
|
||||
" fn ${3:method}(${4:self}: ${2:T}): ${5:ReturnType}",
|
||||
"}"
|
||||
],
|
||||
"description": "Define a trait"
|
||||
},
|
||||
"Impl Block": {
|
||||
"prefix": "impl",
|
||||
"body": [
|
||||
"impl ${1:Trait} for ${2:Type} {",
|
||||
" fn ${3:method}(${4:self}): ${5:ReturnType} =",
|
||||
" ${0:body}",
|
||||
"}"
|
||||
],
|
||||
"description": "Implement a trait"
|
||||
},
|
||||
"Option Match": {
|
||||
"prefix": "matchopt",
|
||||
"body": [
|
||||
"match ${1:option} {",
|
||||
" Some(${2:value}) => ${3:someCase},",
|
||||
" None => ${0:noneCase}",
|
||||
"}"
|
||||
],
|
||||
"description": "Match on Option"
|
||||
},
|
||||
"Result Match": {
|
||||
"prefix": "matchres",
|
||||
"body": [
|
||||
"match ${1:result} {",
|
||||
" Ok(${2:value}) => ${3:okCase},",
|
||||
" Err(${4:error}) => ${0:errCase}",
|
||||
"}"
|
||||
],
|
||||
"description": "Match on Result"
|
||||
},
|
||||
"Console Print": {
|
||||
"prefix": "print",
|
||||
"body": [
|
||||
"Console.print(${0:\"message\"})"
|
||||
],
|
||||
"description": "Print to console"
|
||||
},
|
||||
"Main Function": {
|
||||
"prefix": "main",
|
||||
"body": [
|
||||
"fn main(): Unit with {Console} = {",
|
||||
" ${0:body}",
|
||||
"}",
|
||||
"",
|
||||
"let output = run main() with {}"
|
||||
],
|
||||
"description": "Main function template"
|
||||
},
|
||||
"Doc Comment": {
|
||||
"prefix": "///",
|
||||
"body": [
|
||||
"/// ${1:Description}",
|
||||
"///",
|
||||
"/// # Examples",
|
||||
"/// ```lux",
|
||||
"/// ${0:example}",
|
||||
"/// ```"
|
||||
],
|
||||
"description": "Documentation comment"
|
||||
},
|
||||
"Record Type": {
|
||||
"prefix": "record",
|
||||
"body": [
|
||||
"type ${1:Name} = {",
|
||||
" ${2:field}: ${3:Type},",
|
||||
" ${0:...}",
|
||||
"}"
|
||||
],
|
||||
"description": "Define a record type"
|
||||
},
|
||||
"List Map": {
|
||||
"prefix": "lmap",
|
||||
"body": [
|
||||
"List.map(${1:list}, fn(${2:x}: ${3:T}): ${4:U} => ${0:transform})"
|
||||
],
|
||||
"description": "Map over a list"
|
||||
},
|
||||
"List Filter": {
|
||||
"prefix": "lfilter",
|
||||
"body": [
|
||||
"List.filter(${1:list}, fn(${2:x}: ${3:T}): Bool => ${0:predicate})"
|
||||
],
|
||||
"description": "Filter a list"
|
||||
},
|
||||
"List Fold": {
|
||||
"prefix": "lfold",
|
||||
"body": [
|
||||
"List.fold(${1:list}, ${2:initial}, fn(${3:acc}: ${4:A}, ${5:x}: ${6:T}): ${4:A} => ${0:combine})"
|
||||
],
|
||||
"description": "Fold over a list"
|
||||
}
|
||||
}
|
||||
241
editors/vscode/src/extension.ts
Normal file
241
editors/vscode/src/extension.ts
Normal file
@@ -0,0 +1,241 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { spawn, ChildProcess } from 'child_process';
|
||||
import {
|
||||
LanguageClient,
|
||||
LanguageClientOptions,
|
||||
ServerOptions,
|
||||
} from 'vscode-languageclient/node';
|
||||
|
||||
let client: LanguageClient | undefined;
|
||||
let replTerminal: vscode.Terminal | undefined;
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
console.log('Lux extension activated');
|
||||
|
||||
// Start LSP if enabled
|
||||
const config = vscode.workspace.getConfiguration('lux');
|
||||
if (config.get('lsp.enabled', true)) {
|
||||
startLspClient(context);
|
||||
}
|
||||
|
||||
// Register commands
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('lux.run', runCurrentFile),
|
||||
vscode.commands.registerCommand('lux.format', formatDocument),
|
||||
vscode.commands.registerCommand('lux.check', checkFile),
|
||||
vscode.commands.registerCommand('lux.startRepl', startRepl),
|
||||
vscode.commands.registerCommand('lux.sendToRepl', sendToRepl),
|
||||
vscode.commands.registerCommand('lux.restartLsp', () => restartLspClient(context))
|
||||
);
|
||||
|
||||
// Format on save if enabled
|
||||
if (config.get('format.onSave', false)) {
|
||||
context.subscriptions.push(
|
||||
vscode.workspace.onWillSaveTextDocument((event) => {
|
||||
if (event.document.languageId === 'lux') {
|
||||
event.waitUntil(formatDocumentAsync(event.document));
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function deactivate(): Thenable<void> | undefined {
|
||||
if (replTerminal) {
|
||||
replTerminal.dispose();
|
||||
}
|
||||
if (client) {
|
||||
return client.stop();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getLuxBinary(): string {
|
||||
const config = vscode.workspace.getConfiguration('lux');
|
||||
const customPath = config.get<string>('lspPath');
|
||||
|
||||
if (customPath && customPath.trim() !== '') {
|
||||
return customPath;
|
||||
}
|
||||
|
||||
// Try common locations
|
||||
const workspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
|
||||
const possiblePaths = [
|
||||
workspaceFolder ? path.join(workspaceFolder, 'result', 'bin', 'lux') : null,
|
||||
workspaceFolder ? path.join(workspaceFolder, 'target', 'release', 'lux') : null,
|
||||
workspaceFolder ? path.join(workspaceFolder, 'target', 'debug', 'lux') : null,
|
||||
].filter(Boolean) as string[];
|
||||
|
||||
// Check if any exist
|
||||
for (const p of possiblePaths) {
|
||||
try {
|
||||
require('fs').accessSync(p, require('fs').constants.X_OK);
|
||||
return p;
|
||||
} catch {
|
||||
// Continue to next
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to PATH
|
||||
return 'lux';
|
||||
}
|
||||
|
||||
function startLspClient(context: vscode.ExtensionContext) {
|
||||
const luxBinary = getLuxBinary();
|
||||
|
||||
const serverOptions: ServerOptions = {
|
||||
command: luxBinary,
|
||||
args: ['lsp'],
|
||||
};
|
||||
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [{ scheme: 'file', language: 'lux' }],
|
||||
synchronize: {
|
||||
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.lux'),
|
||||
},
|
||||
};
|
||||
|
||||
client = new LanguageClient(
|
||||
'luxLanguageServer',
|
||||
'Lux Language Server',
|
||||
serverOptions,
|
||||
clientOptions
|
||||
);
|
||||
|
||||
client.start();
|
||||
}
|
||||
|
||||
async function restartLspClient(context: vscode.ExtensionContext) {
|
||||
if (client) {
|
||||
await client.stop();
|
||||
}
|
||||
startLspClient(context);
|
||||
vscode.window.showInformationMessage('Lux language server restarted');
|
||||
}
|
||||
|
||||
async function runCurrentFile() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || editor.document.languageId !== 'lux') {
|
||||
vscode.window.showErrorMessage('No Lux file is active');
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the file first
|
||||
await editor.document.save();
|
||||
|
||||
const filePath = editor.document.uri.fsPath;
|
||||
const luxBinary = getLuxBinary();
|
||||
|
||||
// Create terminal and run
|
||||
const terminal = vscode.window.createTerminal('Lux Run');
|
||||
terminal.show();
|
||||
terminal.sendText(`${luxBinary} "${filePath}"`);
|
||||
}
|
||||
|
||||
async function formatDocument() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || editor.document.languageId !== 'lux') {
|
||||
vscode.window.showErrorMessage('No Lux file is active');
|
||||
return;
|
||||
}
|
||||
|
||||
await editor.document.save();
|
||||
const formatted = await formatDocumentAsync(editor.document);
|
||||
|
||||
if (formatted.length > 0) {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.set(editor.document.uri, formatted);
|
||||
await vscode.workspace.applyEdit(edit);
|
||||
}
|
||||
}
|
||||
|
||||
async function formatDocumentAsync(document: vscode.TextDocument): Promise<vscode.TextEdit[]> {
|
||||
const luxBinary = getLuxBinary();
|
||||
const filePath = document.uri.fsPath;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const process = spawn(luxBinary, ['fmt', filePath]);
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
process.stdout.on('data', (data) => { stdout += data; });
|
||||
process.stderr.on('data', (data) => { stderr += data; });
|
||||
|
||||
process.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
// File was formatted, need to reload
|
||||
resolve([]);
|
||||
} else {
|
||||
vscode.window.showErrorMessage(`Format error: ${stderr}`);
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function checkFile() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || editor.document.languageId !== 'lux') {
|
||||
vscode.window.showErrorMessage('No Lux file is active');
|
||||
return;
|
||||
}
|
||||
|
||||
await editor.document.save();
|
||||
const filePath = editor.document.uri.fsPath;
|
||||
const luxBinary = getLuxBinary();
|
||||
|
||||
const process = spawn(luxBinary, ['check', filePath]);
|
||||
let stderr = '';
|
||||
|
||||
process.stderr.on('data', (data) => { stderr += data; });
|
||||
|
||||
process.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
vscode.window.showInformationMessage('No type errors found');
|
||||
} else {
|
||||
vscode.window.showErrorMessage(`Type check failed:\n${stderr}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function startRepl() {
|
||||
if (replTerminal) {
|
||||
replTerminal.dispose();
|
||||
}
|
||||
|
||||
const luxBinary = getLuxBinary();
|
||||
replTerminal = vscode.window.createTerminal({
|
||||
name: 'Lux REPL',
|
||||
shellPath: luxBinary,
|
||||
});
|
||||
replTerminal.show();
|
||||
}
|
||||
|
||||
async function sendToRepl() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
vscode.window.showErrorMessage('No active editor');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get selection or current line
|
||||
let text: string;
|
||||
if (editor.selection.isEmpty) {
|
||||
text = editor.document.lineAt(editor.selection.active.line).text;
|
||||
} else {
|
||||
text = editor.document.getText(editor.selection);
|
||||
}
|
||||
|
||||
// Start REPL if not running
|
||||
if (!replTerminal) {
|
||||
startRepl();
|
||||
// Wait a bit for REPL to start
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
|
||||
if (replTerminal) {
|
||||
replTerminal.sendText(text);
|
||||
replTerminal.show();
|
||||
}
|
||||
}
|
||||
203
editors/vscode/syntaxes/lux.tmLanguage.json
Normal file
203
editors/vscode/syntaxes/lux.tmLanguage.json
Normal file
@@ -0,0 +1,203 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"name": "Lux",
|
||||
"scopeName": "source.lux",
|
||||
"patterns": [
|
||||
{ "include": "#comments" },
|
||||
{ "include": "#strings" },
|
||||
{ "include": "#numbers" },
|
||||
{ "include": "#keywords" },
|
||||
{ "include": "#operators" },
|
||||
{ "include": "#types" },
|
||||
{ "include": "#functions" },
|
||||
{ "include": "#variables" }
|
||||
],
|
||||
"repository": {
|
||||
"comments": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "comment.line.documentation.lux",
|
||||
"match": "///.*$"
|
||||
},
|
||||
{
|
||||
"name": "comment.line.double-slash.lux",
|
||||
"match": "//.*$"
|
||||
},
|
||||
{
|
||||
"name": "comment.block.lux",
|
||||
"begin": "/\\*",
|
||||
"end": "\\*/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"strings": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "string.quoted.double.lux",
|
||||
"begin": "\"",
|
||||
"end": "\"",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.lux",
|
||||
"match": "\\\\[nrt\\\\\"'0{}]"
|
||||
},
|
||||
{
|
||||
"name": "meta.embedded.interpolation.lux",
|
||||
"begin": "\\{",
|
||||
"end": "\\}",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.interpolation.begin.lux" }
|
||||
},
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.interpolation.end.lux" }
|
||||
},
|
||||
"patterns": [
|
||||
{ "include": "$self" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "string.quoted.single.lux",
|
||||
"match": "'[^'\\\\]'"
|
||||
},
|
||||
{
|
||||
"name": "string.quoted.single.lux",
|
||||
"match": "'\\\\[nrt\\\\\"'0]'"
|
||||
}
|
||||
]
|
||||
},
|
||||
"numbers": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.numeric.float.lux",
|
||||
"match": "\\b\\d+\\.\\d+\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.hex.lux",
|
||||
"match": "\\b0x[0-9a-fA-F]+\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.binary.lux",
|
||||
"match": "\\b0b[01]+\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.integer.lux",
|
||||
"match": "\\b\\d+\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"keywords": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control.lux",
|
||||
"match": "\\b(if|then|else|match|with|run|resume)\\b"
|
||||
},
|
||||
{
|
||||
"name": "keyword.declaration.lux",
|
||||
"match": "\\b(fn|let|type|effect|handler|trait|impl|for)\\b"
|
||||
},
|
||||
{
|
||||
"name": "keyword.other.lux",
|
||||
"match": "\\b(import|export|is)\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.language.boolean.lux",
|
||||
"match": "\\b(true|false)\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.language.unit.lux",
|
||||
"match": "\\(\\)"
|
||||
},
|
||||
{
|
||||
"name": "constant.language.option.lux",
|
||||
"match": "\\b(None|Some)\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.language.result.lux",
|
||||
"match": "\\b(Ok|Err)\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"operators": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.operator.arrow.lux",
|
||||
"match": "=>|->|<-"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.pipe.lux",
|
||||
"match": "\\|>"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.comparison.lux",
|
||||
"match": "==|!=|<=|>=|<|>"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.logical.lux",
|
||||
"match": "&&|\\|\\||!"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.arithmetic.lux",
|
||||
"match": "[+\\-*/%]"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.assignment.lux",
|
||||
"match": "="
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.type.lux",
|
||||
"match": ":"
|
||||
},
|
||||
{
|
||||
"name": "punctuation.separator.variant.lux",
|
||||
"match": "\\|"
|
||||
}
|
||||
]
|
||||
},
|
||||
"types": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "support.type.primitive.lux",
|
||||
"match": "\\b(Int|Float|Bool|String|Char|Unit)\\b"
|
||||
},
|
||||
{
|
||||
"name": "support.type.builtin.lux",
|
||||
"match": "\\b(Option|Result|List)\\b"
|
||||
},
|
||||
{
|
||||
"name": "entity.name.type.lux",
|
||||
"match": "\\b[A-Z][a-zA-Z0-9_]*\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"functions": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "entity.name.function.definition.lux",
|
||||
"match": "(?<=fn\\s+)[a-z_][a-zA-Z0-9_]*"
|
||||
},
|
||||
{
|
||||
"name": "entity.name.function.call.lux",
|
||||
"match": "\\b[a-z_][a-zA-Z0-9_]*(?=\\s*\\()"
|
||||
},
|
||||
{
|
||||
"name": "entity.name.function.method.lux",
|
||||
"match": "(?<=\\.)[a-z_][a-zA-Z0-9_]*(?=\\s*\\()"
|
||||
}
|
||||
]
|
||||
},
|
||||
"variables": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "variable.parameter.lux",
|
||||
"match": "(?<=[(:,]\\s*)[a-z_][a-zA-Z0-9_]*(?=\\s*:)"
|
||||
},
|
||||
{
|
||||
"name": "variable.other.lux",
|
||||
"match": "\\b[a-z_][a-zA-Z0-9_]*\\b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
14
editors/vscode/tsconfig.json
Normal file
14
editors/vscode/tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"outDir": "out",
|
||||
"lib": ["ES2020"],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules", ".vscode-test"]
|
||||
}
|
||||
Reference in New Issue
Block a user