-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
45 lines (40 loc) · 1.37 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
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const Uri = vscode.Uri;
let cache = {};
const EXTENSION_NAMESPACE = 'extension.diffTool';
const cb = (textEditor) => {
if (!cache.left) {
cache.left = textEditor.document.uri;
return;
}
if (!cache.right) {
cache.right = textEditor.document.uri;
}
if (cache.left && cache.right) {
vscode.commands.executeCommand('vscode.diff', cache.left, cache.right, 'diff');
cache = {};
}
}
const registerMenuActions = (context) => {
const commandMap = new Map([
[`${EXTENSION_NAMESPACE}.diffToolLeft`, cb],
[`${EXTENSION_NAMESPACE}.diffToolRight`, cb]
]);
commandMap.forEach((command, commandName) => {
const disposable = vscode.commands.registerTextEditorCommand(commandName, command);
context.subscriptions.push(disposable);
});
}
const registerCommand = (context) => {
var disposable = vscode.commands.registerCommand(EXTENSION_NAMESPACE, function () {
vscode.window.showInformationMessage("插件可以正常运行。");
});
context.subscriptions.push(disposable);
}
exports.activate = (context) => {
registerMenuActions(context);
registerCommand(context);
};
exports.deactivate = ()=> {};