Skip to content

Commit

Permalink
Added dedicated class for vscode context keys
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Jul 18, 2024
1 parent 59d4507 commit 0110c96
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
47 changes: 47 additions & 0 deletions editors/vscode/src/context_keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as vscode from 'vscode';


export function getContextKeys() {
if (instance == undefined) {
instance = new ContextKeys();
}

return instance;
}

let instance: ContextKeys;

export class ContextKeys {
private _debugFeaturesEnabled!: boolean;
private _languageServerActive!: boolean;

constructor() {
this.debugFeaturesEnabled = false;
this.languageServerActive = false;
}


get debugFeaturesEnabled(): boolean {
return this._debugFeaturesEnabled;
}

set debugFeaturesEnabled(value: boolean) {
this._debugFeaturesEnabled = value;
this.setContextKey('debugFeaturesEnabled', value);
}


get languageServerActive(): boolean {
return this._languageServerActive;
}

set languageServerActive(value: boolean) {
this._languageServerActive = value;
this.setContextKey('languageServerActive', value);
}


private setContextKey(key: string, value: any) {
vscode.commands.executeCommand('setContext', `witcherscript-ide.${key}`, value);
}
}
8 changes: 5 additions & 3 deletions editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import * as config from './config';
import * as providers from './providers';
import * as lc from './lsp/lang_client';
import * as state from './state';
import { getContextKeys } from './context_keys';


export function activate(context: vscode.ExtensionContext) {
const cfg = config.getConfiguration();
const ctxKeys = getContextKeys();

vscode.commands.executeCommand('setContext', 'witcherscript-ide.debugFeaturesEnabled', cfg.enableDebugFeatures);
vscode.commands.executeCommand('setContext', 'witcherscript-ide.languageServerActive', false);
ctxKeys.debugFeaturesEnabled = cfg.enableDebugFeatures;
ctxKeys.languageServerActive = false;

commands.registerCommands(context);
providers.registerProviders(context);
Expand All @@ -20,7 +22,7 @@ export function activate(context: vscode.ExtensionContext) {

if (cfg.enableLanguageServer) {
lc.createLanguageClient(context, cfg).then(() => {
vscode.commands.executeCommand('setContext', 'witcherscript-ide.languageServerActive', true);
ctxKeys.languageServerActive = true;
});
}
}
Expand Down

0 comments on commit 0110c96

Please sign in to comment.