Skip to content

Commit 6d4b1e7

Browse files
committed
feat: add spawn to spawn general lsp exe
1 parent b013c51 commit 6d4b1e7

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Provide integration support for adding Language Server Protocol servers to Atom.
1515
This npm package can be used by Atom package authors wanting to integrate LSP-compatible language servers with Atom. It provides:
1616

1717
* Conversion routines between Atom and LSP types
18-
* A FlowTyped wrapper around JSON-RPC for **v3** of the LSP protocol
19-
* All necessary FlowTyped input and return structures for LSP, notifications etc.
18+
* A TypeScript wrapper around JSON-RPC for **v3** of the LSP protocol
19+
* All necessary TypeScript input and return structures for LSP, notifications etc.
2020
* A number of adapters to translate communication between Atom/Atom-IDE and the LSP's capabilities
2121
* Automatic wiring up of adapters based on the negotiated capabilities of the language server
2222
* Helper functions for downloading additional non-npm dependencies
@@ -59,9 +59,9 @@ The language server protocol consists of a number of capabilities. Some of these
5959

6060
The underlying JSON-RPC communication is handled by the [vscode-jsonrpc npm module](https://www.npmjs.com/package/vscode-jsonrpc).
6161

62-
### Minimal example
62+
### Minimal example (Nodejs-compatible LSP exe)
6363

64-
A minimal implementation can be illustrated by the Omnisharp package here which has only npm-managed dependencies. You simply provide the scope name, language name and server name as well as start your process and AutoLanguageClient takes care of interrogating your language server capabilities and wiring up the appropriate services within Atom to expose them.
64+
A minimal implementation can be illustrated by the Omnisharp package here which has only npm-managed dependencies, and the LSP is a JavaScript file. You simply provide the scope name, language name and server name as well as start your process and `AutoLanguageClient` takes care of interrogating your language server capabilities and wiring up the appropriate services within Atom to expose them.
6565

6666
```javascript
6767
const {AutoLanguageClient} = require('atom-languageclient')
@@ -83,6 +83,32 @@ You can get this code packaged up with the necessary package.json etc. from the
8383

8484
Note that you will also need to add various entries to the `providedServices` and `consumedServices` section of your package.json (for now). You can [obtain these entries here](https://github.com/atom/ide-csharp/tree/master/package.json).
8585

86+
### Minimal example (General LSP exe)
87+
88+
If the LSP is a general executable (not a JavaScript file), you should use `spawn` inside `startServerProcess`.
89+
90+
```javascript
91+
const {AutoLanguageClient} = require('atom-languageclient')
92+
const {resolve} = require('path')
93+
94+
class DLanguageClient extends AutoLanguageClient {
95+
getGrammarScopes () { return [ 'source.d' ] }
96+
getLanguageName () { return 'D' }
97+
getServerName () { return 'serve-d' }
98+
99+
startServerProcess (projectPath) {
100+
return super.spawn(
101+
resolve('./bin/serve-d'), // path to the LSP executable
102+
[], // args used for spawning
103+
{ cwd: projectPath } // child process spawn options
104+
)
105+
}
106+
}
107+
108+
module.exports = new DLanguageClient()
109+
```
110+
111+
86112
### Using other connection types
87113

88114
The default connection type is *stdio* however both *ipc* and *sockets* are also available.

lib/auto-languageclient.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ 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
285+
*/
286+
protected spawn(lspPath: string, args: string[], options: cp.SpawnOptions = {}): cp.ChildProcess {
287+
this.logger.debug(`starting "${lspPath} ${args.join(' ')}"`);
288+
return cp.spawn(lspPath, args, options);
289+
}
290+
291+
/** Spawn a language server using Atom's Nodejs process
292+
* Use this inside the `startServerProcess` override if the language server is a JavaScript file.
293+
* Also see the `spawn` method
294+
*/
282295
protected spawnChildNode(args: string[], options: cp.SpawnOptions = {}): cp.ChildProcess {
283296
this.logger.debug(`starting child Node "${args.join(' ')}"`);
284297
options.env = options.env || Object.create(process.env);

0 commit comments

Comments
 (0)