From 99cedd6a384418a09adb90377e074f35cbd0c401 Mon Sep 17 00:00:00 2001 From: ViTeXFTW Date: Sun, 15 Dec 2024 10:13:55 +0100 Subject: [PATCH] feat(Autocompletion toggle): Added setting for toggling vscode and extension autocompletins. ver(0.1.9-hotfix1): bumped version --- client/src/extension.ts | 19 +++++++++++++++++-- package-lock.json | 4 ++-- package.json | 7 ++++++- server/src/server.ts | 25 +++++++++++++++++++------ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index db86467..ffdd79a 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -34,6 +34,7 @@ export function activate(context: vscode.ExtensionContext) { let languageServerRunning = ZSconfig.get('serverStartupSetting', false); // Default to 2 if not set let displayAlphaWarning = ZSconfig.get('displayAlphaWarning', true); let precompileTransitionKeys = ZSconfig.get('precompileTransitionKeys', false); + let doAutocompletions = ZSconfig.get('enableAutocomplete', false); context.subscriptions.push(vscode.commands.registerCommand('ZeroSyntax.stopLanguageServer', () => { if (languageServerRunning) { @@ -76,7 +77,8 @@ export function activate(context: vscode.ExtensionContext) { }, initializationOptions: { precompileTransitionKeys: precompileTransitionKeys, - forceAddModule: forceAddModule + forceAddModule: forceAddModule, + doAutocompletions: doAutocompletions // SemanticTokenTypes, // SemanticTokenModifiers }, @@ -118,11 +120,24 @@ export function activate(context: vscode.ExtensionContext) { } } -vscode.workspace.onDidChangeConfiguration((e) => { +vscode.workspace.onDidChangeConfiguration(async (e) => { if (e.affectsConfiguration('ZeroSyntax.serverStartupSetting')) { languageServerRunning = ZSconfig.get('serverStartupSetting', false); toggleLanguageServer(); } + + if(e.affectsConfiguration('ZeroSyntax.enableAutocomplete')) { + // Optionally, prompt the user before reloading + const answer = await vscode.window.showInformationMessage( + 'Autocompletion setting changed. Do you want to reload the window to apply changes?', + 'Reload', + 'Cancel' + ); + + if (answer === 'Reload') { + await vscode.commands.executeCommand('workbench.action.reloadWindow'); + } + } }); function toggleLanguageServer() { diff --git a/package-lock.json b/package-lock.json index 0abe8b1..10f758b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zerosyntax-server", - "version": "0.1.6", + "version": "0.1.9-hotfix1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "zerosyntax-server", - "version": "0.1.6", + "version": "0.1.9-hotfix1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 4a706c6..c71f5db 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "ZeroSyntax-Server", "description": "Language server for Generals Zero Hour INI files", "icon": "images/icon.png", - "version": "0.1.9", + "version": "0.1.9-hotfix1", "publisher": "ViTeXFTW", "author": { "name": "ViTeXFTW", @@ -72,6 +72,11 @@ "type": "object", "title": "ZeroSyntax Settings", "properties": { + "ZeroSyntax.enableAutocomplete": { + "type": "boolean", + "default": true, + "description": "Constrols if the extension should provide autocompletion." + }, "ZeroSyntax.indentNumber": { "type": "number", "default": 2, diff --git a/server/src/server.ts b/server/src/server.ts index 262c54e..8963ced 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -30,6 +30,7 @@ import { MapIniParser } from './utils/antlr4ng/MapIniParser'; import { MapIniLexer } from './utils/antlr4ng/MapIniLexer'; import { CharStream, CommonTokenStream, DefaultErrorStrategy } from 'antlr4ng'; import { findContextAtPosition, findTokenIndex, generateCompletionItems, getContextSpecificCompletions } from './completion/helpers'; +import { read } from 'fs'; // Create a connection for the server, using Node's IPC as a transport. // Also include all preview / proposed LSP features. @@ -51,8 +52,9 @@ const documents: TextDocuments = new TextDocuments(TextDocument); let parser: Parser = new Parser(); let currentParser: MapIniParser; -let forceAddModule: boolean = true -let precompileTransitionKeys: boolean = false +let forceAddModule: boolean = true; +let precompileTransitionKeys: boolean = false; +let doAutocompletions: boolean = false; connection.onInitialize((params: InitializeParams) => { const capabilities = params.capabilities; @@ -72,6 +74,8 @@ connection.onInitialize((params: InitializeParams) => { capabilities.textDocument.publishDiagnostics.relatedInformation ); + doAutocompletions = options.doAutocompletions !== undefined ? options.doAutocompletions : false; + const result: InitializeResult = { capabilities: { textDocumentSync: TextDocumentSyncKind.Full, @@ -79,9 +83,16 @@ connection.onInitialize((params: InitializeParams) => { // Tell the client that this server supports code completion. // definitionProvider: false, //true // hoverProvider: false, //true - completionProvider: { - resolveProvider: false - }, + + ...(doAutocompletions && { + completionProvider: { + resolveProvider: false + } + }) + + // completionProvider: { + // resolveProvider: false + // } // semanticTokensProvider: { // legend: { // tokenTypes, @@ -191,9 +202,11 @@ documents.onDidChangeContent((change) => { }, diagnosticParserDelay) }); - connection.onCompletion((_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => { // console.log(`Requesting completions!`) + if (!doAutocompletions) { + return []; + } // Retrieve the document const document = documents.get(_textDocumentPosition.textDocument.uri)!;