Skip to content

Commit e7439aa

Browse files
authored
refactor(extension): Optimized the destruction of some events and refactor some code (#3780)
1 parent b8627e7 commit e7439aa

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

extensions/vscode/src/common.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
161161
}
162162

163163
function activateServerMaxOldSpaceSizeChange() {
164-
vscode.workspace.onDidChangeConfiguration((e) => {
164+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e) => {
165165
if (e.affectsConfiguration('vue.server.runtime') || e.affectsConfiguration('vue.server.path')) {
166166
requestReloadVscode();
167167
}
168168
if (e.affectsConfiguration('vue')) {
169169
vscode.commands.executeCommand('volar.action.restartServer');
170170
}
171-
});
171+
}));
172172
}
173173

174174
async function activateRestartRequest() {

extensions/vscode/src/features/nameCasing.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,25 @@ export async function activate(_context: vscode.ExtensionContext, client: BaseLa
1111

1212
await client.start();
1313

14+
const disposes: vscode.Disposable[] = [];
1415
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
1516
statusBar.command = 'volar.action.nameCasing';
1617

1718
update(vscode.window.activeTextEditor?.document);
1819

19-
const d_1 = vscode.window.onDidChangeActiveTextEditor(e => {
20+
disposes.push(vscode.window.onDidChangeActiveTextEditor(e => {
2021
update(e?.document);
21-
});
22-
const d_2 = vscode.workspace.onDidChangeConfiguration(() => {
22+
}));
23+
disposes.push(vscode.workspace.onDidChangeConfiguration(() => {
2324
attrNameCasings.clear();
2425
tagNameCasings.clear();
2526
update(vscode.window.activeTextEditor?.document);
26-
});
27-
const d_3 = vscode.workspace.onDidCloseTextDocument((doc) => {
27+
}));
28+
disposes.push(vscode.workspace.onDidCloseTextDocument((doc) => {
2829
attrNameCasings.delete(doc.uri.toString());
2930
tagNameCasings.delete(doc.uri.toString());
30-
});
31-
const d_4 = vscode.commands.registerCommand('volar.action.nameCasing', async () => {
31+
}));
32+
disposes.push(vscode.commands.registerCommand('volar.action.nameCasing', async () => {
3233

3334
if (!vscode.window.activeTextEditor?.document) return;
3435

@@ -80,14 +81,11 @@ export async function activate(_context: vscode.ExtensionContext, client: BaseLa
8081
await convertAttr(vscode.window.activeTextEditor, AttrNameCasing.Camel);
8182
}
8283
updateStatusBarText();
83-
});
84+
}));
8485

8586
client.onDidChangeState(e => {
8687
if (e.newState === State.Stopped) {
87-
d_1.dispose();
88-
d_2.dispose();
89-
d_3.dispose();
90-
d_4.dispose();
88+
disposes.forEach(d => d.dispose());
9189
statusBar.dispose();
9290
}
9391
});

extensions/vscode/src/nodeClientMain.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
1818
let cancellationPipeUpdateKey: string | undefined;
1919
let serverPathStatusItem: vscode.StatusBarItem | undefined;
2020

21-
vscode.workspace.onDidChangeTextDocument((e) => {
21+
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument((e) => {
2222
let key = e.document.uri.toString() + '|' + e.document.version;
2323
if (cancellationPipeUpdateKey === undefined) {
2424
cancellationPipeUpdateKey = key;
@@ -28,7 +28,7 @@ export async function activate(context: vscode.ExtensionContext) {
2828
cancellationPipeUpdateKey = key;
2929
fs.writeFileSync(cancellationPipeName, '');
3030
}
31-
});
31+
}));
3232

3333
await commonActivate(context, (
3434
id,

0 commit comments

Comments
 (0)