Skip to content

Commit 62c44f5

Browse files
committed
refactor: Adds GunController
1 parent 1fa9bba commit 62c44f5

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/extension.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
import * as vscode from 'vscode';
44

55
export function activate(context: vscode.ExtensionContext) {
6-
const intelliSenseSettings = new IntelliSenseSettings(vscode.workspace.getConfiguration())
6+
const gunControllers : GunController[] = [
7+
new IntelliSenseGunController(vscode.workspace.getConfiguration())
8+
]
79

810
let gunsOff = vscode.commands.registerCommand('withoutGuns.gunsOff', () => {
9-
vscode.window.showInformationMessage('We just took your guns. That\'s for your own good.');
10-
intelliSenseSettings.removeIntelliSense();
11+
vscode.window.showInformationMessage('We just took your guns. That\'s for your own good.');
12+
gunControllers.forEach(gunController => gunController.takeTheGun());
1113
});
1214

1315
let gunsOn = vscode.commands.registerCommand('withoutGuns.gunsOn', () => {
1416
vscode.window.showInformationMessage('You got your guns back. Be careful what you do with them.');
15-
intelliSenseSettings.applyInitialSettings();
17+
gunControllers.forEach(gunController => gunController.giveTheGunBack());
1618
});
1719

1820
context.subscriptions.push(gunsOff);
1921
context.subscriptions.push(gunsOn);
2022
}
2123

22-
class IntelliSenseSettings {
23-
private readonly configuration : vscode.WorkspaceConfiguration;
24+
interface GunController {
25+
takeTheGun();
26+
giveTheGunBack();
27+
}
28+
29+
class IntelliSenseGunController implements GunController {
30+
private readonly configuration: vscode.WorkspaceConfiguration;
2431

2532
private readonly initialQuickSuggestions : boolean;
2633
private readonly initialWordBasedSuggestions : boolean;
@@ -36,17 +43,17 @@ class IntelliSenseSettings {
3643
this.initialsuggestOnTriggerCharacters = configuration.get("editor.suggestOnTriggerCharacters");
3744
}
3845

39-
applyInitialSettings() {
40-
this.configuration.update("editor.quickSuggestions", this.initialQuickSuggestions);
41-
this.configuration.update("editor.wordBasedSuggestions", this.initialWordBasedSuggestions);
42-
this.configuration.update("editor.parameterHints", this.initialParameterHints);
43-
this.configuration.update("editor.suggestOnTriggerCharacters", this.initialsuggestOnTriggerCharacters);
44-
}
45-
46-
removeIntelliSense() {
46+
takeTheGun() {
4747
this.configuration.update("editor.quickSuggestions", false);
4848
this.configuration.update("editor.wordBasedSuggestions", false);
4949
this.configuration.update("editor.parameterHints", false);
5050
this.configuration.update("editor.suggestOnTriggerCharacters", false);
5151
}
52+
53+
giveTheGunBack() {
54+
this.configuration.update("editor.quickSuggestions", this.initialQuickSuggestions);
55+
this.configuration.update("editor.wordBasedSuggestions", this.initialWordBasedSuggestions);
56+
this.configuration.update("editor.parameterHints", this.initialParameterHints);
57+
this.configuration.update("editor.suggestOnTriggerCharacters", this.initialsuggestOnTriggerCharacters);
58+
}
5259
}

0 commit comments

Comments
 (0)