-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.js
95 lines (77 loc) · 2.86 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const vscode = require('vscode');
const PinegrowVS = require('./lib/pinegrow-vs');
/**
* Called when VS Code activates your extension.
*/
let pgvs;
function activate(context) {
// Create the PinegrowVS instance.
pgvs = new PinegrowVS();
// Initialize PinegrowVS right away.
pgvs.init();
// Track the previously active editor so we can pass it to activeEditorChanged.
let activeEditor = null;
// Listen for changes in the active text editor.
vscode.window.onDidChangeActiveTextEditor((editor) => {
pgvs.activeEditorChanged(editor, activeEditor);
if (editor) {
pgvs.visibleEditorChanged(editor);
}
activeEditor = editor;
});
// Listen for text changes in any open document.
vscode.workspace.onDidChangeTextDocument((event) => {
pgvs.editorTextChanged(event);
});
// Listen for saves in any open document.
vscode.workspace.onDidSaveTextDocument((document) => {
pgvs.editorTextSaved(document);
});
// Reconnect Pinegrow when workspace folders are added or removed.
const workspaceFoldersWatcher = vscode.workspace.onDidChangeWorkspaceFolders(() => {
pgvs.reconnect();
});
// Whenever the user changes configuration, we check if pinegrow.urlWithPort was changed
// and reconnect if needed.
const configWatcher = vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('pinegrow.urlWithPort') || e.affectsConfiguration('pinegrow.enabled')) {
pgvs.reconnect();
}
});
const selectInPg = vscode.commands.registerCommand('extension.selectInPG', () => {
const editor = vscode.window.activeTextEditor;
pgvs.selectInPinegrow(editor);
});
const openInPg = vscode.commands.registerCommand('extension.openInPG', () => {
const editor = vscode.window.activeTextEditor;
pgvs.openInPinegrow(editor);
});
const reconnect = vscode.commands.registerCommand('extension.reconnect', () => {
pgvs.reconnect();
});
const detectMapping = vscode.commands.registerCommand('extension.detectMapping', () => {
pgvs.autoDetectMapping();
});
const downloadPinegrow = vscode.commands.registerCommand('extension.downloadPinegrow', () => {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://pinegrow.com'));
});
const refreshPage = vscode.commands.registerCommand('extension.refreshPage', () => {
const editor = vscode.window.activeTextEditor;
pgvs.refreshPage(editor);
});
context.subscriptions.push(
workspaceFoldersWatcher,
configWatcher,
selectInPg,
openInPg,
reconnect,
detectMapping,
downloadPinegrow,
refreshPage
);
}
function deactivate() {
pgvs.destroy();
}
exports.activate = activate;
exports.deactivate = deactivate;