Skip to content

Commit 9cccaaa

Browse files
committed
check bin and bin-<platform>
1 parent 672669a commit 9cccaaa

File tree

2 files changed

+131
-78
lines changed

2 files changed

+131
-78
lines changed

client/out/languageserver.js

Lines changed: 96 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/languageserver.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,24 @@ function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
9090
return folder;
9191
}
9292

93-
function start(context: ExtensionContext, documentSelector: DocumentSelector, folder: WorkspaceFolder) {
93+
async function chmod(path: fs.PathLike, mode: fs.Mode) {
94+
await new Promise((resolve) => {
95+
fs.chmod(path, mode, resolve)
96+
})
97+
}
98+
99+
async function exists(path: fs.PathLike) {
100+
return await new Promise((resolve) => {
101+
fs.stat(path, (err, stats) => {
102+
if (stats && stats.isDirectory()) {
103+
resolve(true);
104+
}
105+
resolve(false);
106+
})
107+
})
108+
}
109+
110+
async function start(context: ExtensionContext, documentSelector: DocumentSelector, folder: WorkspaceFolder) {
94111
// Options to control the language client
95112
let clientOptions: LanguageClientOptions = {
96113
// Register the server for plain text documents
@@ -109,12 +126,21 @@ function start(context: ExtensionContext, documentSelector: DocumentSelector, fo
109126
let commandParam: string[] = config.get("Lua.misc.parameters");
110127
let command: string;
111128
let platform: string = os.platform();
129+
let binDir: string;
130+
if (await exists(context.asAbsolutePath(
131+
path.join(
132+
'server',
133+
'bin',
134+
)
135+
))) {
136+
binDir = 'bin';
137+
}
112138
switch (platform) {
113139
case "win32":
114140
command = context.asAbsolutePath(
115141
path.join(
116142
'server',
117-
'bin-Windows',
143+
binDir ? binDir : 'bin-Windows',
118144
'lua-language-server.exe'
119145
)
120146
);
@@ -123,21 +149,21 @@ function start(context: ExtensionContext, documentSelector: DocumentSelector, fo
123149
command = context.asAbsolutePath(
124150
path.join(
125151
'server',
126-
'bin-Linux',
152+
binDir ? binDir : 'bin-Linux',
127153
'lua-language-server'
128154
)
129155
);
130-
fs.chmodSync(command, '777');
156+
await chmod(command, '777');
131157
break;
132158
case "darwin":
133159
command = context.asAbsolutePath(
134160
path.join(
135161
'server',
136-
'bin-macOS',
162+
binDir ? binDir : 'bin-macOS',
137163
'lua-language-server'
138164
)
139165
);
140-
fs.chmodSync(command, '777');
166+
await chmod(command, '777');
141167
break;
142168
}
143169

@@ -322,7 +348,7 @@ function onInlayHint(client: LanguageClient) {
322348

323349
export function activate(context: ExtensionContext) {
324350
registerCustomCommands(context);
325-
function didOpenTextDocument(document: TextDocument) {
351+
async function didOpenTextDocument(document: TextDocument) {
326352
// We are only interested in language mode text
327353
if (document.languageId !== 'lua' || (document.uri.scheme !== 'file' && document.uri.scheme !== 'untitled')) {
328354
return;
@@ -332,7 +358,7 @@ export function activate(context: ExtensionContext) {
332358
let folder = Workspace.getWorkspaceFolder(uri);
333359
// Untitled files go to a default client.
334360
if (folder == null && Workspace.workspaceFolders == null && !defaultClient) {
335-
defaultClient = start(context, [
361+
defaultClient = await start(context, [
336362
{ scheme: 'file', language: 'lua' }
337363
], null);
338364
return;
@@ -348,7 +374,7 @@ export function activate(context: ExtensionContext) {
348374

349375
if (!clients.has(folder.uri.toString())) {
350376
let pattern: string = folder.uri.fsPath.replace(/(\[|\])/g, '[$1]') + '/**/*';
351-
let client = start(context, [
377+
let client = await start(context, [
352378
{ scheme: 'file', language: 'lua', pattern: pattern }
353379
], folder);
354380
clients.set(folder.uri.toString(), client);

0 commit comments

Comments
 (0)