-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.js
58 lines (52 loc) · 1.73 KB
/
util.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
const fs = require('fs');
const path = require('path');
const vscode = require('vscode');
function getDefaultSCLangExecutable() {
switch (process.platform) {
case 'darwin':
return '/Applications/SuperCollider.app/Contents/MacOS/sclang';
case 'win32':
const root = 'C:\\Program Files';
const directories = fs.readdirSync(root, { withFileTypes: true })
.filter((entry) => entry.isDirectory() && entry.name.startsWith("SuperCollider-"));
if (directories.length > 0) {
return path.join(root, directories[0].name, 'sclang.exe');
}
return 'sclang';
default:
return 'sclang';
}
}
function stringifyError(value) {
const { type, error } = value;
if (type === 'SyntaxError') {
value = `${type}: ${error.msg}`;
value += `\n line: ${error.line}, char: ${error.charPos}`;
value += `\n${error.code}`;
} else if (type === 'Error') {
const args = (error.args || [])
.map((arg) => `${arg.class} ${arg.asString}`)
.join(', ');
const receiver = error.receiver || 'no receiver';
error.errorString = error.errorString || 'UnknownError';
error.class = error.class || '';
value = error.errorString.replace('ERROR', error.class);
value += `\n receiver: ${receiver.asString}, args: [${args}]`;
}
return value;
}
function flashHighlight(editor, range, duration = 250) {
const highlightDecoration = vscode.window.createTextEditorDecorationType({
backgroundColor: 'white',
// border: '1px solid white',
});
editor.setDecorations(highlightDecoration, [{ range }]);
setTimeout(() => {
editor.setDecorations(highlightDecoration, []);
}, duration);
}
module.exports = {
flashHighlight,
stringifyError,
getDefaultSCLangExecutable,
};