This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
136 lines (118 loc) · 4.59 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// 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');
// Load config
const config = vscode.workspace.getConfiguration()
const show_ghci = config.get('has-go.loadGHCiButton');
const show_run = config.get('has-go.runFileButton');
const show_stack = config.get('has-go.stackRunButton');
const tool = config.get('has-go.haskellTool');
var curr_ter = undefined;
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "has-go" is now active!');
// vscode.window.onDidChangeActiveTerminal
vscode.window.onDidChangeActiveTerminal(e => {
curr_ter = e;
});
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let runGhci = vscode.commands.registerCommand('has-go.ghci', function () {
let use_ghci = config.get('has-go.ghciInterpreter') == 'GHCi'
let ov_arg = config.get('has-go.overrideGHCiArgs');
let text = vscode.window.activeTextEditor.document
let b = text.fileName.replace('' + vscode.workspace.workspaceFolders[0].uri.path + "/", "")
let c = `\"${b}\"`
if (curr_ter == undefined || curr_ter.name != 'GHCi' || !config.get('has-go.reuseTerminal')) {
let terminal = vscode.window.createTerminal("GHCi");
if (text.languageId == 'haskell' || text.languageId == 'literate haskell') {
if (ov_arg.trim() == "") {
if (use_ghci) {
terminal.sendText('ghci');
} else {
terminal.sendText(tool.toLowerCase() + ' repl');
}
} else {
if (use_ghci) {
terminal.sendText('ghci ' + ov_arg.replace('${current}', c));
} else {
terminal.sendText(tool.toLowerCase() + ' repl ' + ov_arg.replace('${current}', c));
}
};
} else {
terminal.sendText('ghci');
};
terminal.show();
} else if (config.get('has-go.reuseTerminal')) {
curr_ter.sendText(':l ' + c.split('\\').join('\\\\'));
};
});
let runHaskell = vscode.commands.registerCommand('has-go.runfile', function () {
let terminal = vscode.window.createTerminal("Run Haskell");
let a = vscode.workspace.workspaceFolders[0].uri.path
let b = vscode.window.activeTextEditor.document.fileName
let c = b.replace(a + "/", "")
let d = `\"${c}\"`
if (config.get('has-go.ghciInterpreter') != 'GHCi' && config.get('has-go.haskellTool') == 'Stack') {
terminal.sendText('stack runghc ' + d);
} else {
terminal.sendText('runhaskell ' + d);
}
terminal.show();
});
let stackRun = vscode.commands.registerCommand('has-go.stackrun', function () {
let terminal = vscode.window.createTerminal(tool + " Run");
let stack_args = vscode.workspace.getConfiguration().get('has-go.stackArgs');
terminal.sendText(tool.toLowerCase() + ' run ' + stack_args);
terminal.show();
});
let compile = vscode.commands.registerCommand('has-go.compilefile', function () {
let terminal = vscode.window.createTerminal('Compile');
let args = vscode.workspace.getConfiguration().get('has-go.ghcArgs');
let a = vscode.workspace.workspaceFolders[0].uri.path
let b = vscode.window.activeTextEditor.document.fileName
let c = b.replace(a + "/", "")
let d = `\"${c}\"`
terminal.sendText('ghc ' + d + ' ' + args);
terminal.show();
})
if (show_ghci) {
let stat = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10);
stat.text = "Load GHCi"
stat.command = 'has-go.ghci'
stat.show()
context.subscriptions.push(stat);
}
if (show_run) {
let stat = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10);
stat.text = "Run File"
stat.command = 'has-go.runfile'
stat.show()
context.subscriptions.push(stat);
}
if (show_stack) {
let stat = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10);
stat.text = tool + " Run"
stat.command = 'has-go.stackrun'
stat.show()
context.subscriptions.push(stat);
}
context.subscriptions.push(runGhci);
context.subscriptions.push(runHaskell);
context.subscriptions.push(stackRun);
context.subscriptions.push(compile);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() { }
module.exports = {
activate,
deactivate
}