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 Dec 14, 2023
1 parent b8627e7 commit e7439aa
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e7439aa

Please sign in to comment.