diff --git a/editors/vscode/extension.js b/editors/vscode/extension.js new file mode 100644 index 0000000..a734416 --- /dev/null +++ b/editors/vscode/extension.js @@ -0,0 +1,83 @@ +const vscode = require('vscode'); +const { LanguageClient, TransportKind } = require('vscode-languageclient/node'); + +let client; + +function activate(context) { + const config = vscode.workspace.getConfiguration('wokelang'); + const serverPath = config.get('serverPath', 'woke-lsp'); + + // Server options + const serverOptions = { + run: { command: serverPath, transport: TransportKind.stdio }, + debug: { command: serverPath, transport: TransportKind.stdio } + }; + + // Client options + const clientOptions = { + documentSelector: [{ scheme: 'file', language: 'wokelang' }], + synchronize: { + configurationSection: 'wokelang' + }, + initializationOptions: { + enableDiagnostics: config.get('enableDiagnostics', true), + enableCompletion: config.get('enableCompletion', true), + enableHover: config.get('enableHover', true), + enableFormatting: config.get('enableFormatting', true) + } + }; + + // Create the language client + client = new LanguageClient( + 'wokelangLsp', + 'WokeLang Language Server', + serverOptions, + clientOptions + ); + + // Register commands + context.subscriptions.push( + vscode.commands.registerCommand('wokelang.restartServer', async () => { + if (client) { + await client.stop(); + client.start(); + vscode.window.showInformationMessage('WokeLang LSP restarted.'); + } + }), + vscode.commands.registerCommand('wokelang.showInfo', () => { + if (client) { + vscode.window.showInformationMessage(\WokeLang LSP running at: \); + } + }), + vscode.commands.registerCommand('wokelang.checkConsent', async () => { + if (client) { + const editor = vscode.window.activeTextEditor; + if (editor) { + await vscode.commands.executeCommand('wokelang.internal.checkConsent', editor.document.uri.toString()); + vscode.window.showInformationMessage('Consent check triggered.'); + } + } + }), + vscode.commands.registerCommand('wokelang.formatDocument', async () => { + const editor = vscode.window.activeTextEditor; + if (editor) { + await vscode.commands.executeCommand('editor.action.formatDocument'); + } + }) + ); + + // Start the client + client.start(); +} + +function deactivate() { + if (!client) { + return undefined; + } + return client.stop(); +} + +module.exports = { + activate, + deactivate +}; diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 9cf5a5d..5780a24 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -1,7 +1,7 @@ { "name": "wokelang", "displayName": "WokeLang", - "description": "Syntax highlighting and language configuration for WokeLang (.woke). The LSP client is temporarily removed pending reimplementation in AffineScript — see the repository issues.", + "description": "WokeLang VS Code extension providing syntax highlighting and LSP integration.", "version": "0.1.0", "publisher": "hyperpolymath", "license": "MPL-2.0", @@ -42,6 +42,103 @@ "scopeName": "source.wokelang", "path": "./syntaxes/wokelang.tmLanguage.json" } - ] + ], + "commands": [ + { + "command": "wokelang.restartServer", + "title": "WokeLang: Restart Language Server" + }, + { + "command": "wokelang.showInfo", + "title": "WokeLang: Show Server Info" + }, + { + "command": "wokelang.checkConsent", + "title": "WokeLang: Check Consent" + }, + { + "command": "wokelang.formatDocument", + "title": "WokeLang: Format Document" + } + ], + "menus": { + "editor/context": [ + { + "command": "wokelang.checkConsent", + "when": "editorLangId == wokelang", + "group": "navigation" + }, + { + "command": "wokelang.formatDocument", + "when": "editorLangId == wokelang", + "group": "1_modification" + } + ] + }, + "keybindings": [ + { + "command": "wokelang.formatDocument", + "key": "ctrl+shift+f", + "mac": "cmd+shift+f", + "when": "editorLangId == wokelang" + }, + { + "command": "wokelang.checkConsent", + "key": "ctrl+shift+c", + "mac": "cmd+shift+c", + "when": "editorLangId == wokelang" + } + ], + "configuration": { + "type": "object", + "title": "WokeLang", + "properties": { + "wokelang.serverPath": { + "type": "string", + "default": "woke-lsp", + "description": "Path to the woke-lsp executable." + }, + "wokelang.enableDiagnostics": { + "type": "boolean", + "default": true, + "description": "Enable LSP diagnostics." + }, + "wokelang.enableCompletion": { + "type": "boolean", + "default": true, + "description": "Enable LSP autocompletion." + }, + "wokelang.enableHover": { + "type": "boolean", + "default": true, + "description": "Enable LSP hover information." + }, + "wokelang.enableFormatting": { + "type": "boolean", + "default": true, + "description": "Enable LSP document formatting." + }, + "wokelang.trace.server": { + "type": "string", + "enum": [ + "off", + "messages", + "verbose" + ], + "default": "off", + "description": "Trace level for the language server." + } + } + } + }, + "main": "./extension.js", + "activationEvents": [ + "onLanguage:wokelang" + ], + "dependencies": { + "vscode-languageclient": "^9.0.1" + }, + "devDependencies": { + "@types/vscode": "^1.60.0" } -} +} \ No newline at end of file