-
Notifications
You must be signed in to change notification settings - Fork 0
Editor VS Code
Lexicon does not currently ship a first-party VS Code extension. VS Code can still use lexicon-lsp, but it needs a language-client extension because VS Code does not attach arbitrary stdio language servers from settings alone.
Use one of these approaches:
- Recommended for product use: create a thin workspace or project extension using
vscode-languageclient. - Fast experiment: use a generic LSP client extension and point it at
lexicon-lsp. - Baseline without LSP: use CLI validation tasks.
swift build -c release --product lexicon-lspKeep the absolute path:
/absolute/path/to/Lexicon/.build/release/lexicon-lsp
At the workspace root:
{
"lexicon": "lexicons/commerce.lexicon"
}Save it as lexicon-lsp.json.
Create a small extension that registers .lexicon, Go, and Rust documents with lexicon-lsp.
package.json:
{
"name": "lexicon-vscode",
"displayName": "Lexicon",
"version": "0.0.1",
"engines": { "vscode": "^1.90.0" },
"activationEvents": [
"onLanguage:lexicon",
"onLanguage:go",
"onLanguage:rust"
],
"contributes": {
"languages": [
{
"id": "lexicon",
"aliases": ["Lexicon"],
"extensions": [".lexicon"]
}
],
"configuration": {
"title": "Lexicon",
"properties": {
"lexicon.languageServer.path": {
"type": "string",
"default": "lexicon-lsp"
}
}
}
},
"main": "./out/extension.js",
"dependencies": {
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@types/vscode": "^1.90.0",
"typescript": "^5.0.0"
}
}src/extension.ts:
import * as vscode from "vscode";
import {
LanguageClient,
LanguageClientOptions,
ServerOptions
} from "vscode-languageclient/node";
let client: LanguageClient | undefined;
export function activate(context: vscode.ExtensionContext) {
const config = vscode.workspace.getConfiguration("lexicon");
const command = config.get<string>("languageServer.path") || "lexicon-lsp";
const serverOptions: ServerOptions = { command };
const clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: "file", language: "lexicon" },
{ scheme: "file", language: "go" },
{ scheme: "file", language: "rust" }
]
};
client = new LanguageClient("lexicon-lsp", "Lexicon LSP", serverOptions, clientOptions);
context.subscriptions.push(client);
client.start();
}
export function deactivate(): Thenable<void> | undefined {
return client?.stop();
}Build and launch the extension in an Extension Development Host using the workflow from VS Code's official Language Server Extension Guide.
Workspace settings:
{
"lexicon.languageServer.path": "/absolute/path/to/Lexicon/.build/release/lexicon-lsp"
}For experimentation, install a generic LSP client extension from the Marketplace and configure it to launch lexicon-lsp over stdio.
This is useful for testing, but a dedicated extension is better for team use because it can:
- register
.lexiconas a language - control activation
- choose the exact document selectors
- provide workspace settings
- include tasks and troubleshooting commands
Even without editor LSP support, add validation tasks.
.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "lexicon: lint",
"type": "shell",
"command": "swift run lexicon lint lexicons/commerce.lexicon",
"group": "test",
"problemMatcher": []
},
{
"label": "lexicon: generate",
"type": "shell",
"command": "swift run lexicon-generate lexicons/commerce.lexicon --type ts -o src/generated/commerce-lexicon",
"group": "build",
"problemMatcher": []
}
]
}With a client attached, lexicon-lsp provides completions and diagnostics in:
-
.lexiconreferences - Go
l("...")exact-path calls - Rust
l!(...)exact-path macros
Normal VS Code language extensions continue to handle Go, Rust, and TypeScript language features.