Skip to content

Commit a5c03a5

Browse files
committed
fix: merge getExePath into spawn
1 parent d57e55a commit a5c03a5

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

README.md

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

8686
### Minimal example (General LSP exe)
8787

88-
If the LSP is a general executable (not a JavaScript file), you should use `spawn` inside `startServerProcess`. `getExePath` is a cross-platform utility function to get the exe path for the given exe name (under the `bin/platform-arch/exeName` by default or `exeName` if the file doesn't exist).
88+
If the LSP is a general executable (not a JavaScript file), you should use `spawn` inside `startServerProcess`.
8989

9090
```javascript
91-
const {AutoLanguageClient, getExePath} = require('atom-languageclient')
91+
const {AutoLanguageClient} = require('atom-languageclient')
9292

9393
class DLanguageClient extends AutoLanguageClient {
9494
getGrammarScopes () { return [ 'source.d' ] }
@@ -97,7 +97,8 @@ class DLanguageClient extends AutoLanguageClient {
9797

9898
startServerProcess (projectPath) {
9999
return super.spawn(
100-
getExePath('serve-d'), // path to the LSP executable (or the exe name if it is on the PATH)
100+
'serve-d', // the `name` or `path` of the executable
101+
// if the `name` is provided it checks `bin/platform-arch/exeName` by default, and if doesn't exists uses the `exeName` on the PATH
101102
[], // args passed to spawn the exe
102103
{ cwd: projectPath } // child process spawn options
103104
)

lib/auto-languageclient.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,27 @@ export default class AutoLanguageClient {
279279
await this._serverManager.stopAllServers();
280280
}
281281

282-
/** Spawn a general language server
283-
* Use this inside the `startServerProcess` override if the language server is a general executable
284-
* Also see the `spawnChildNode` method
282+
/**
283+
* Spawn a general language server.
284+
* Use this inside the `startServerProcess` override if the language server is a general executable.
285+
* Also see the `spawnChildNode` method.
286+
* If the name is provided as the first argument, it checks `bin/platform-arch/exeName` by default, and if doesn't exists uses the exe on PATH.
287+
* For example on Windows x64, by passing `serve-d`, `bin/win32-x64/exeName.exe` is spawned by default.
288+
* @param exe the `name` or `path` of the executable
289+
* @param args args passed to spawn the exe. Defaults to `[]`.
290+
* @param options: child process spawn options. Defaults to `{}`.
291+
* @param rootPath the path of the folder of the exe file. Defaults to `join("bin", `${process.platform}-${process.arch}`)`.
292+
* @param exeExtention the extention of the exe file. Defaults to `process.platform === "win32" ? ".exe" : ""`
285293
*/
286-
protected spawn(exe: string, args: string[], options: cp.SpawnOptions = {}): LanguageServerProcess {
294+
protected spawn(
295+
exe: string,
296+
args: string[] = [],
297+
options: cp.SpawnOptions = {},
298+
rootPath = Utils.rootPathDefault,
299+
exeExtention = Utils.exeExtentionDefault
300+
): LanguageServerProcess {
287301
this.logger.debug(`starting "${exe} ${args.join(' ')}"`);
288-
return cp.spawn(exe, args, options);
302+
return cp.spawn(Utils.getExePath(exe, rootPath, exeExtention), args, options);
289303
}
290304

291305
/** Spawn a language server using Atom's Nodejs process

lib/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ export function promiseWithTimeout<T>(ms: number, promise: Promise<T>): Promise<
115115
}
116116

117117

118+
export const rootPathDefault = join("bin", `${process.platform}-${process.arch}`);
119+
export const exeExtentionDefault = process.platform === "win32" ? ".exe" : "";
120+
118121
/** Finds an exe file in the package assuming it is placed under `rootPath/platform-arch/exe`. If the exe file did not exist,
119122
* the given name is returned.
120123
* For example on Windows x64, if the `exeName` is `serve-d`, it returns the absolute path to `./bin/win32-x64/exeName.exe`, and
@@ -123,11 +126,7 @@ export function promiseWithTimeout<T>(ms: number, promise: Promise<T>): Promise<
123126
* @param rootPath the path of the folder of the exe file. Defaults to 'join("bin", `${process.platform}-${process.arch}`)'
124127
* @param exeExtention the extention of the exe file. Defaults to `process.platform === "win32" ? ".exe" : ""`
125128
*/
126-
export function getExePath(
127-
exeName: string,
128-
rootPath = join("bin", `${process.platform}-${process.arch}`),
129-
exeExtention = process.platform === "win32" ? ".exe" : ""
130-
): string {
129+
export function getExePath(exeName: string, rootPath = rootPathDefault, exeExtention = exeExtentionDefault): string {
131130
const exePath = resolve(join(rootPath, `${exeName}${exeExtention}`));
132131
if (existsSync(exePath)) {
133132
return exePath

0 commit comments

Comments
 (0)