Skip to content

Commit

Permalink
refactor(extension): Optimized the destruction of some events and ref…
Browse files Browse the repository at this point in the history
…actor some code (#3780)
  • Loading branch information
Simon-He95 authored and johnsoncodehk committed Dec 21, 2023
1 parent 18c4329 commit f1ce889
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions extensions/vscode/src/common.ts
Expand Up @@ -161,14 +161,14 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
}

function activateServerMaxOldSpaceSizeChange() {
vscode.workspace.onDidChangeConfiguration((e) => {
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('vue.server.runtime') || e.affectsConfiguration('vue.server.path')) {
requestReloadVscode();
}
if (e.affectsConfiguration('vue')) {
vscode.commands.executeCommand('volar.action.restartServer');
}
});
}));
}

async function activateRestartRequest() {
Expand Down
22 changes: 10 additions & 12 deletions extensions/vscode/src/features/nameCasing.ts
Expand Up @@ -11,24 +11,25 @@ export async function activate(_context: vscode.ExtensionContext, client: BaseLa

await client.start();

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

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

const d_1 = vscode.window.onDidChangeActiveTextEditor(e => {
disposes.push(vscode.window.onDidChangeActiveTextEditor(e => {
update(e?.document);
});
const d_2 = vscode.workspace.onDidChangeConfiguration(() => {
}));
disposes.push(vscode.workspace.onDidChangeConfiguration(() => {
attrNameCasings.clear();
tagNameCasings.clear();
update(vscode.window.activeTextEditor?.document);
});
const d_3 = vscode.workspace.onDidCloseTextDocument((doc) => {
}));
disposes.push(vscode.workspace.onDidCloseTextDocument((doc) => {
attrNameCasings.delete(doc.uri.toString());
tagNameCasings.delete(doc.uri.toString());
});
const d_4 = vscode.commands.registerCommand('volar.action.nameCasing', async () => {
}));
disposes.push(vscode.commands.registerCommand('volar.action.nameCasing', async () => {

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

Expand Down Expand Up @@ -80,14 +81,11 @@ export async function activate(_context: vscode.ExtensionContext, client: BaseLa
await convertAttr(vscode.window.activeTextEditor, AttrNameCasing.Camel);
}
updateStatusBarText();
});
}));

client.onDidChangeState(e => {
if (e.newState === State.Stopped) {
d_1.dispose();
d_2.dispose();
d_3.dispose();
d_4.dispose();
disposes.forEach(d => d.dispose());
statusBar.dispose();
}
});
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/nodeClientMain.ts
Expand Up @@ -18,7 +18,7 @@ export async function activate(context: vscode.ExtensionContext) {
let cancellationPipeUpdateKey: string | undefined;
let serverPathStatusItem: vscode.StatusBarItem | undefined;

vscode.workspace.onDidChangeTextDocument((e) => {
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument((e) => {
let key = e.document.uri.toString() + '|' + e.document.version;
if (cancellationPipeUpdateKey === undefined) {
cancellationPipeUpdateKey = key;
Expand All @@ -28,7 +28,7 @@ export async function activate(context: vscode.ExtensionContext) {
cancellationPipeUpdateKey = key;
fs.writeFileSync(cancellationPipeName, '');
}
});
}));

await commonActivate(context, (
id,
Expand Down

0 comments on commit f1ce889

Please sign in to comment.