Skip to content

Commit 7508f42

Browse files
committed
feat: add getExePath
1 parent 6d4b1e7 commit 7508f42

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ Note that you will also need to add various entries to the `providedServices` an
8787

8888
If the LSP is a general executable (not a JavaScript file), you should use `spawn` inside `startServerProcess`.
8989

90+
`getExePath` is a cross-platform utility function to get the exe path for the given exe name (under the `bin` folder by default).
91+
9092
```javascript
91-
const {AutoLanguageClient} = require('atom-languageclient')
92-
const {resolve} = require('path')
93+
const {AutoLanguageClient, getExePath} = require('atom-languageclient')
9394

9495
class DLanguageClient extends AutoLanguageClient {
9596
getGrammarScopes () { return [ 'source.d' ] }
@@ -98,8 +99,8 @@ class DLanguageClient extends AutoLanguageClient {
9899

99100
startServerProcess (projectPath) {
100101
return super.spawn(
101-
resolve('./bin/serve-d'), // path to the LSP executable
102-
[], // args used for spawning
102+
getExePath('serve-d'), // path to the LSP executable.
103+
[], // args passed to spawn the exe
103104
{ cwd: projectPath } // child process spawn options
104105
)
105106
}

lib/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Logger, ConsoleLogger, FilteredLogger } from './logger';
99
import DownloadFile from './download-file';
1010
import LinterPushV2Adapter from './adapters/linter-push-v2-adapter';
1111
import CommandExecutionAdapter from './adapters/command-execution-adapter';
12+
export { getExePath } from "./utils"
1213

1314
export * from './auto-languageclient';
1415
export {

lib/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { join, resolve } from 'path';
12
import {
23
Point,
34
TextBuffer,
@@ -111,3 +112,18 @@ export function promiseWithTimeout<T>(ms: number, promise: Promise<T>): Promise<
111112
});
112113
});
113114
}
115+
116+
117+
/** Finds an exe file in the package assuming it is placed under `rootPath/platform/exe`
118+
* For example on Windows, if the `exeName` is `serve-d`, it returns the absolute path to `bin/win32/exeName.exe`
119+
* @param exeName name of the exe file
120+
* @param rootPath the path of the folder of the exe file. Defaults to 'bin'
121+
* @param exeExtention the extention of the exe file. Defaults to `process.platform === "win32" ? ".exe" : ""`
122+
*/
123+
export function getExePath(
124+
exeName: string,
125+
rootPath = "bin",
126+
exeExtention = process.platform === "win32" ? ".exe" : ""
127+
): string {
128+
return resolve(join(rootPath, process.platform, `${exeName}${exeExtention}`));
129+
}

0 commit comments

Comments
 (0)