-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
66 lines (56 loc) · 1.74 KB
/
extension.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const vscode = require('vscode');
const { vsCodeUpdateSettingsFile } = require('./helpers')
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
// Check if the workspace is already open when the extension is activated
if (vscode.workspace.workspaceFolders) {
vsCodeUpdateSettingsFile();
setupWatcher(context);
}
// Listen for the onDidChangeWorkspaceFolders event
context.subscriptions.push(
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
if (event.added.length > 0) {
vsCodeUpdateSettingsFile();
setupWatcher(context);
}
})
);
// Listen for the command updateSettings
context.subscriptions.push(
vscode.commands.registerCommand('vs-code-settings-os.updateSettings', async () => {
vsCodeUpdateSettingsFile();
})
);
}
let previousWatcher
/**
* Listen for changes to OS settings files
* @param {vscode.ExtensionContext} context
*/
function setupWatcher(context) {
if (previousWatcher) {
previousWatcher.dispose()
previousWatcher = undefined
}
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.workspace.workspaceFolders[0].uri, '.vscode/settings.*.json'))
watcher.onDidChange(function() {
vsCodeUpdateSettingsFile();
})
watcher.onDidCreate(function() {
vsCodeUpdateSettingsFile();
})
watcher.onDidDelete(function() {
vsCodeUpdateSettingsFile();
})
context.subscriptions.push(watcher)
previousWatcher = watcher
}
// This method is called when your extension is deactivated
function deactivate() { }
module.exports = {
activate,
deactivate
}