-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
79 lines (63 loc) · 1.99 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
68
69
70
71
72
73
74
75
76
77
78
79
const vscode = require('vscode');
const SvnSpawn = require('svn-spawn');
const path = require('path');
const createStatusBar = () => {
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
statusBarItem.command = 'vscode-svn.showOutputChannel';
return statusBarItem;
};
const createClient = (rootPath) => {
return new SvnSpawn({
cwd: rootPath,
noAuthCache: true,
});
};
const createChannel = () => {
return vscode.window.createOutputChannel('vscode-svn');
};
const svnStatus = (client) => {
return new Promise((resolve, reject) => {
client.getStatus((err, data) => err ? reject(err) : resolve(data));
});
};
const updateStatusBar = (data, statusBar) => {
return new Promise((resolve) => {
statusBar.text = `${data.length} changes`;
statusBar.show();
resolve(data);
});
};
const checkAllFiles = (client) => {
return new Promise((resolve, reject) => {
svnStatus(client)
.then((data) => resolve(data))
.catch((err) => reject(err));
});
};
const updateOutputChannel = (data, outputChannel) => {
outputChannel.clear();
data.forEach((item) => {
const document = vscode.Uri.file(path.join(vscode.workspace.rootPath, item.$.path));
outputChannel.appendLine(document);
});
};
exports.activate = () => {
const rootPath = vscode.workspace.rootPath;
const outputChannel = createChannel();
vscode.commands.registerCommand('vscode-svn.showOutputChannel', () => outputChannel.show());
const statusBar = createStatusBar();
const client = createClient(rootPath);
const watcher = vscode.workspace.createFileSystemWatcher(`${rootPath}/**/*`);
const main = () => {
return checkAllFiles(client, statusBar)
.then((data) => updateStatusBar(data, statusBar))
.then((data) => updateOutputChannel(data, outputChannel))
.catch((err) => vscode.window.showErrorMessage(err));
};
watcher.onDidChange(main);
watcher.onDidCreate(main);
watcher.onDidDelete(main);
main();
};
exports.deactivate = () => {
};