This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
67 lines (56 loc) · 2.33 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
67
const vscode = require('vscode');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const gitAPI = vscode.extensions.getExtension("vscode.git").exports.getAPI(1);
let pushPull = new vscode.Disposable();
const watchGit = () => {
if (gitAPI.repositories.length > 0) {
const repoState = gitAPI.repositories[0].state;
console.log(repoState)
const watchPushPull = () => {
vscode.commands.executeCommand("setContext", "nf-touch-bar.showPush", repoState.HEAD.ahead > 0);
vscode.commands.executeCommand("setContext", "nf-touch-bar.showPull", repoState.HEAD.behind < 0);
}
watchPushPull()
pushPull = repoState.onDidChange(watchPushPull)
context.subscriptions.push(pushPull)
} else {
pushPull.dispose();
vscode.commands.executeCommand("setContext", "nf-touch-bar.showPush", false);
vscode.commands.executeCommand("setContext", "nf-touch-bar.showPull", false);
}
}
watchGit()
context.subscriptions.push(gitAPI.onDidOpenRepository(watchGit));
context.subscriptions.push(gitAPI.onDidCloseRepository(watchGit));
const config = vscode.workspace.getConfiguration("nf-touch-bar.commands")
const commandIDs = Object.entries({
"run": ["start", "debug"],
"test": ["start", "debug", "restart", "stop"],
"terminal": ["togglePanel"],
"git": ["togglePanel", "push", "forcePush", "pull"],
"folder": ["open", "openRecent", "close"]
})
let commands = {}
commandIDs.forEach(([category]) => commands[category] = {})
commandIDs.forEach(([category, command]) => command.forEach(command => {
commands[category][command] = vscode.commands.registerCommand(`nf-touch-bar.${category}.${command}`, () => vscode.commands.executeCommand(config.get(`${category}.${command}`)));
context.subscriptions.push(commands[category][command])
}));
vscode.workspace.onDidChangeConfiguration(e => {
commandIDs.forEach(([category, command]) => command.forEach(command => {
if (e.affectsConfiguration(`nf-touch-bar.commands.${category}.${command}`)) {
commands[category][command].dispose()
commands[category][command] = vscode.commands.registerCommand(`nf-touch-bar.${category}.${command}`, () => vscode.commands.executeCommand(config.get(`${category}.${command}`)));
context.subscriptions.push(commands[category][command])
}
}))
})
}
function deactivate() { }
module.exports = {
activate,
deactivate
}