Skip to content

Commit fea9b74

Browse files
committed
fixed: the default packaged luacheck executable is not macos/linux format, try to find a valid luacheck executable using which luacheck shell command.
- #107 Ship UNIX luacheck binaries in addition to Windows ones - #106 Crashes after VSCode update - #104 LuaCoderAssist Crash - #102 Crash when luacheck is not available - #86 安裝後立即出錯,無法使用。
1 parent 2f463dc commit fea9b74

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

server/providers/diagnostic-provider.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,21 @@ class DiagnosticProvider {
9898
_run(linter, input) {
9999
return new Promise((resolve, reject) => {
100100
/*重新创建一个检查进程*/
101-
let proc = execFile(linter.cmd, linter.args, { cwd: linter.cwd }, (error, stdout, stderr) => {
102-
if (error != null) {
103-
reject({ error: error, stdout: stdout, stderr: stderr });
104-
} else {
105-
resolve({ error: error, stdout: stdout, stderr: stderr });
106-
}
107-
});
101+
try {
102+
let proc = execFile(linter.cmd, linter.args, { cwd: linter.cwd }, (error, stdout, stderr) => {
103+
if (error != null) {
104+
reject({ error: error, stdout: stdout, stderr: stderr });
105+
} else {
106+
resolve({ error: error, stdout: stdout, stderr: stderr });
107+
}
108+
});
108109

109-
proc.stdin.end(input);
110+
proc.stdin.end(input);
111+
} catch (e) {
112+
console.error(`execute '${linter.cmd} ${linter.args.join(' ')}' failed.`);
113+
console.error(e);
114+
reject({error: e});
115+
}
110116
});
111117
}
112118

server/providers/lib/linters.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22

33
const engine = require('../../lib/engine');
4+
const utils_1 = require('./utils');
45
const uri_1 = require('vscode-uri').default;
56
const langserver_1 = require('vscode-languageserver');
67
const path_1 = require('path');
78
const fs_1 = require('fs');
9+
const os = require('os')
810

911
// default to 64-bit windows luacheck.exe, from https://github.com/mpeterv/luacheck/releases
1012
const default_luacheck_executor = path_1.resolve(__dirname, '../../../3rd/luacheck/luacheck.exe');
@@ -23,9 +25,20 @@ function isFileSync(aPath) {
2325
}
2426
}
2527

28+
function getLuacheckExecutor() {
29+
let osType = os.type().toLowerCase();
30+
if (osType.includes('windows')) {
31+
return default_luacheck_executor;
32+
} else {
33+
return utils_1.getExePath('luacheck');
34+
}
35+
}
36+
2637
class Luacheck {
2738
constructor(coder) {
2839
this.coder = coder;
40+
this.exePath = getLuacheckExecutor();
41+
console.info(`[INFO] using '${this.exePath}'`)
2942
}
3043

3144
command(document) {
@@ -47,7 +60,7 @@ class Luacheck {
4760
const fileName = uri_1.parse(document.uri).fsPath;
4861
args.push("--filename", fileName, "-"); //use stdin
4962

50-
let cmd = settings.execPath || default_luacheck_executor;
63+
let cmd = settings.execPath || this.exePath;
5164
let cwd = path_1.dirname(luacheckrc_path || fileName);
5265

5366
return {

server/providers/lib/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,10 @@ function findAllReferences(references, def) {
530530
}
531531

532532
exports.findAllReferences = findAllReferences;
533+
534+
const execSync = require('child_process').execSync
535+
function getExePath(extName) {
536+
return execSync(`which ${extName}`).toString().replace(/[\r\n]/g, '');
537+
}
538+
539+
exports.getExePath = getExePath;

0 commit comments

Comments
 (0)