Skip to content

Commit

Permalink
Merge pull request #55 from ViTeXFTW/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ViTeXFTW authored Dec 15, 2024
2 parents 706f41c + aec64c7 commit 1e3d0a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
19 changes: 17 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function activate(context: vscode.ExtensionContext) {
let languageServerRunning = ZSconfig.get<boolean>('serverStartupSetting', false); // Default to 2 if not set
let displayAlphaWarning = ZSconfig.get<boolean>('displayAlphaWarning', true);
let precompileTransitionKeys = ZSconfig.get<boolean>('precompileTransitionKeys', false);
let doAutocompletions = ZSconfig.get<boolean>('enableAutocomplete', false);

context.subscriptions.push(vscode.commands.registerCommand('ZeroSyntax.stopLanguageServer', () => {
if (languageServerRunning) {
Expand Down Expand Up @@ -76,7 +77,8 @@ export function activate(context: vscode.ExtensionContext) {
},
initializationOptions: {
precompileTransitionKeys: precompileTransitionKeys,
forceAddModule: forceAddModule
forceAddModule: forceAddModule,
doAutocompletions: doAutocompletions
// SemanticTokenTypes,
// SemanticTokenModifiers
},
Expand Down Expand Up @@ -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<boolean>('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() {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 19 additions & 6 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -51,8 +52,9 @@ const documents: TextDocuments<TextDocument> = 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;
Expand All @@ -72,16 +74,25 @@ connection.onInitialize((params: InitializeParams) => {
capabilities.textDocument.publishDiagnostics.relatedInformation
);

doAutocompletions = options.doAutocompletions !== undefined ? options.doAutocompletions : false;

const result: InitializeResult = {
capabilities: {
textDocumentSync: TextDocumentSyncKind.Full,
documentFormattingProvider: true,
// 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,
Expand Down Expand Up @@ -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)!;
Expand Down

0 comments on commit 1e3d0a3

Please sign in to comment.