Skip to content

Commit bec4d90

Browse files
committed
feat: Add on change events to determine when a certain user setting has been changed, and show an information message to the user.
Also re-configures the comment blocks when the active editor language has been changed.
1 parent 6df1b47 commit bec4d90

File tree

1 file changed

+74
-9
lines changed

1 file changed

+74
-9
lines changed

src/extension.ts

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,82 @@
1-
'use strict';
1+
"use strict";
22

3-
import { languages, commands, workspace, ExtensionContext, IndentAction, LanguageConfiguration, OnEnterRule, Disposable } from 'vscode';
4-
import { Configuration } from './configuration';
3+
import * as vscode from "vscode";
4+
5+
import {Configuration} from "./configuration";
56

6-
let fs = require('fs');
77
let configuration = new Configuration();
88

9-
export function activate(context: ExtensionContext) {
10-
9+
export function activate(context: vscode.ExtensionContext) {
1110
configuration.configureCommentBlocks(context);
1211
configuration.registerCommands();
13-
}
1412

15-
export function deactivate() {
16-
13+
const extensionNames = configuration.getExtensionNames();
14+
15+
const extensionName = extensionNames.name;
16+
const extensionDisplayName = extensionNames.displayName;
17+
18+
let disabledLangConfig: string[] = configuration.getConfiguration().get("disabledLanguages");
19+
20+
if (disabledLangConfig.length > 0) {
21+
vscode.window.showInformationMessage(`${disabledLangConfig.join(", ")} languages are disabled for ${extensionDisplayName}.`);
22+
}
23+
24+
/**
25+
* When the configuration/user settings are changed, set the extension
26+
* to reflect the settings and output a message to the user.
27+
*/
28+
vscode.workspace.onDidChangeConfiguration((event: any) => {
29+
/**
30+
* Blade Override Comments
31+
*/
32+
// If the affected setting is bladeOverrideComments...
33+
if (event.affectsConfiguration(`${extensionName}.bladeOverrideComments`)) {
34+
// Get the setting.
35+
let bladeOverrideComments: boolean = configuration.getConfiguration().get("bladeOverrideComments");
36+
37+
configuration.setBladeComments(bladeOverrideComments);
38+
39+
if (!configuration.isLangIdDisabled("blade")) {
40+
vscode.window.showInformationMessage(`${bladeOverrideComments === false ? "Disabled" : "Enabled"} Blade Override Comments setting.`);
41+
}
42+
}
43+
44+
/**
45+
* Disabled Languages
46+
*/
47+
if (event.affectsConfiguration(`${extensionName}.disabledLanguages`)) {
48+
vscode.window
49+
.showInformationMessage(
50+
`The ${extensionName}.disabledLanguages setting has been changed. Please reload the Extension Host to take effect.`,
51+
"Reload"
52+
)
53+
.then((selection) => {
54+
if (selection === "Reload") {
55+
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
56+
}
57+
});
58+
}
59+
60+
/**
61+
* Override Default Language Block Comments
62+
*/
63+
if (event.affectsConfiguration(`${extensionName}.overrideDefaultLanguageMultiLineComments`)) {
64+
vscode.window
65+
.showInformationMessage(
66+
`The ${extensionName}.overrideDefaultLanguageMultiLineComments setting has been changed. Please reload the Extension Host to take effect.`,
67+
"Reload"
68+
)
69+
.then((selection) => {
70+
if (selection === "Reload") {
71+
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
72+
}
73+
});
74+
}
75+
});
76+
77+
// Called when active editor language is changed, so re-configure the comment blocks.
78+
vscode.workspace.onDidOpenTextDocument(() => {
79+
configuration.configureCommentBlocks(context);
80+
});
1781
}
82+
export function deactivate() {}

0 commit comments

Comments
 (0)