Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
33 lines (32 loc) · 1.7 KB
/
Copy pathextension.js
File metadata and controls
33 lines (32 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { t, configure } = require('./src/i18n');
const vscode = require('vscode');
const WorkspaceService = require('./src/workspace-service');
const StatusBarManager = require('./src/status-bar');
const Commands = require('./src/commands');
let service, status;
async function activate(context) {
configure(vscode.l10n);
const report = error => vscode.window.showErrorMessage(t('Fast Node Switcher: {0}', error.message));
service = new WorkspaceService(() => status?.update().catch(report));
status = new StatusBarManager(service);
context.subscriptions.push(service, status);
new Commands(service, status).register(context);
const refreshAll = async (apply = false) => {
for (const folder of vscode.workspace.workspaceFolders || [undefined]) await service.refresh(folder, apply);
await status.update();
};
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration('fastNodeSwitcher')) refreshAll(false).catch(report);
}));
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(event => {
for (const folder of event.removed) service.remove(folder);
(async () => { for (const folder of event.added) await service.refresh(folder, true); await status.update(); })().catch(report);
}));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(() => status.update().catch(report)));
context.subscriptions.push(vscode.window.onDidChangeWindowState(state => {
if (state.focused) refreshAll(false).catch(report);
}));
await refreshAll(true);
}
function deactivate() { service?.dispose(); status?.dispose(); }
module.exports = { activate, deactivate };