This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.js
87 lines (69 loc) · 1.95 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
const vscode = require('vscode');
const cp = require('child_process')
let runCommand = function (command) {
cp.exec(command, (err, stdout, stderr) => {
if (err) {
logError(err);
}
});
}
let config = vscode.workspace.getConfiguration()
// fig.log is an internal setting as it's intended for developers only, this means it won't show up
// in the settings UI/editor. Add `"fig.log": true` to your settings.json and reload the window to
// enable logging.
let shouldLog = config.get('fig.log') === true;
// Ensure that any VSCode terminal session has FIG_NEW_SESSION set as an environment variable
let osxEnv = config.get("terminal.integrated.env.osx")
osxEnv["FIG_NEW_SESSION"] = "1"
config.update("terminal.integrated.env.osx", osxEnv, true)
function log(...args) {
if (shouldLog) {
console.log(`fig: ${args[0]}`, args.slice(1));
}
}
function logError(message) {
console.error(`fig: ${message}`);
}
function updateActiveTerminal(terminal) {
let activeTerminal = terminal || vscode.window.activeTerminal
if (!activeTerminal) {
noActiveTerminals()
return
}
activeTerminal.processId.then((processId) => {
if (processId) {
runCommand('fig bg:vscode code:' + processId)
}
})
}
function noActiveTerminals() {
runCommand('fig bg:vscode-no-active-terminals')
}
function activate(context) {
try {
updateActiveTerminal()
vscode.window.onDidOpenTerminal(terminal => {
log("Terminal opened. Total count: " + vscode.window.terminals.length);
});
vscode.window.onDidCloseTerminal(terminal => {
log("Terminal closed. Total count: " + vscode.window.terminals.length);
if (vscode.window.terminals.length == 0) {
noActiveTerminals()
} else {
updateActiveTerminal()
}
});
vscode.window.onDidChangeActiveTerminal(terminal => {
log(`Active terminal changed`);
updateActiveTerminal(terminal)
});
} catch (e) {
logError(e)
}
}
exports.activate = activate;
function deactivate() { }
module.exports = {
activate,
deactivate
}