Skip to content

Commit 28e1957

Browse files
authored
Publish LSP to npm (#734)
* testing * simplify ci * fix test ci * npm publish test ci * update server cli * update server * add node-ipc * restore ci * restore ci * update * test ci * update ci * fix cmd * test matrix os * test with windows * update * update * update * add ci step to publish
1 parent 32325de commit 28e1957

File tree

8 files changed

+120
-25
lines changed

8 files changed

+120
-25
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
uses: actions/setup-node@v3
5858
with:
5959
node-version: 16
60+
registry-url: 'https://registry.npmjs.org'
6061

6162
- run: npm ci
6263
- run: opam install dune cppo
@@ -211,3 +212,10 @@ jobs:
211212
- name: Publish extension as release
212213
if: startsWith(github.ref, 'refs/tags/')
213214
run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} ${{ steps.tag_name.outputs.tag }} --no-git-tag-version
215+
216+
- name: Publish LSP to NPM
217+
if: startsWith(github.ref, 'refs/tags/')
218+
working-directory: server
219+
run: npm publish
220+
env:
221+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Thanks for your interest. Below is an informal spec of how the plugin's server c
1515
├── package.json // The extension manifest
1616
└── server // Language Server. Usable standalone
1717
├── src
18-
│ └── server.ts // Language Server entry point
18+
│ ├── server.ts // Language Server Module
19+
│ ├── cli.ts // LSP CLI
1920
└── analysis_binaries // Prod-time platform-specific analysis binaries
2021
├── darwin
2122
├── linux

client/src/extension.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
LanguageClientOptions,
1717
ServerOptions,
1818
State,
19-
TransportKind,
19+
Executable,
20+
TransportKind
2021
} from "vscode-languageclient/node";
2122

2223
import * as customCommands from "./commands";
@@ -81,7 +82,7 @@ export function activate(context: ExtensionContext) {
8182
function createLanguageClient() {
8283
// The server is implemented in node
8384
let serverModule = context.asAbsolutePath(
84-
path.join("server", "out", "server.js")
85+
path.join("server", "out", "cli.js")
8586
);
8687
// The debug options for the server
8788
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
@@ -90,9 +91,10 @@ export function activate(context: ExtensionContext) {
9091
// If the extension is launched in debug mode then the debug server options are used
9192
// Otherwise the run options are used
9293
let serverOptions: ServerOptions = {
93-
run: { module: serverModule, transport: TransportKind.ipc },
94+
run: { module: serverModule, args: ["--node-ipc"], transport: TransportKind.ipc },
9495
debug: {
9596
module: serverModule,
97+
args: ["--node-ipc"],
9698
transport: TransportKind.ipc,
9799
options: debugOptions,
98100
},

server/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ReScript Language Server
2+
3+
## Install
4+
5+
```sh
6+
npm install -g @rescript/lsp
7+
```
8+
9+
## Run
10+
11+
```sh
12+
resciptls --stdio
13+
```
14+
15+
```sh
16+
ReScript Language Server
17+
18+
Usage: rescriptls [options]
19+
20+
Options:
21+
22+
--stdio Use stdio
23+
--node-ipc Use node-ipc
24+
-v, --version Print version
25+
-h, --help Print help
26+
```

server/package-lock.json

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

server/package.json

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
{
2-
"name": "rescript-language-server",
3-
"description": "ReScript's language-server",
2+
"name": "@rescript/lsp",
3+
"description": "LSP server for ReScript",
44
"version": "1.20.0",
55
"author": "chenglou",
66
"license": "MIT",
7+
"bin": {
8+
"rescriptls": "./out/cli.js"
9+
},
10+
"keywords": [
11+
"ReScript",
12+
"LSP",
13+
"Language Server"
14+
],
15+
"files": [
16+
"out/*",
17+
"analysis_binaries",
18+
"README.md"
19+
],
720
"engines": {
821
"node": "*"
922
},
23+
"homepage": "https://github.com/rescript-lang/rescript-vscode/server/README.md",
1024
"repository": {
1125
"type": "git",
12-
"url": "https://github.com/rescript-lang/rescript-vscode"
26+
"url": "https://github.com/rescript-lang/rescript-vscode",
27+
"directory": "server"
28+
},
29+
"bugs": {
30+
"url": "https://github.com/rescript-lang/rescript-vscode/issues"
1331
},
1432
"dependencies": {
1533
"chokidar": "^3.5.1",
1634
"vscode-jsonrpc": "^8.0.1",
1735
"vscode-languageserver": "^8.0.1",
1836
"vscode-languageserver-protocol": "^3.17.1"
19-
},
20-
"scripts": {}
37+
}
2138
}

server/src/cli.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
import fs from "fs";
3+
import server from "./server";
4+
5+
const args = process.argv.slice(2)
6+
7+
const help = `ReScript Language Server
8+
9+
Usage: rescriptls [options]
10+
11+
Options:
12+
13+
--stdio Use stdio
14+
--node-ipc Use node-ipc
15+
-v, --version Print version
16+
-h, --help Print help`;
17+
18+
(() => {
19+
switch (args[0]) {
20+
case '--stdio':
21+
return server(true);
22+
case '--node-ipc':
23+
return server(false);
24+
case '--version':
25+
case '-v':
26+
console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version);
27+
process.exit(0);
28+
case '--help':
29+
case '-h':
30+
console.log(help);
31+
process.exit(0);
32+
default:
33+
console.log(help);
34+
process.exit(1)
35+
}
36+
})();

server/src/server.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,22 @@ let getOpenedFileContent = (fileUri: string) => {
400400
return content;
401401
};
402402

403-
// Start listening now!
404-
// We support two modes: the regular node RPC mode for VSCode, and the --stdio
405-
// mode for other editors The latter is _technically unsupported_. It's an
406-
// implementation detail that might change at any time
407-
if (process.argv.includes("--stdio")) {
408-
let writer = new rpc.StreamMessageWriter(process.stdout);
409-
let reader = new rpc.StreamMessageReader(process.stdin);
410-
// proper `this` scope for writer
411-
send = (msg: p.Message) => writer.write(msg);
412-
reader.listen(onMessage);
413-
} else {
414-
// proper `this` scope for process
415-
send = (msg: p.Message) => process.send!(msg);
416-
process.on("message", onMessage);
403+
export default function listen(useStdio = false) {
404+
// Start listening now!
405+
// We support two modes: the regular node RPC mode for VSCode, and the --stdio
406+
// mode for other editors The latter is _technically unsupported_. It's an
407+
// implementation detail that might change at any time
408+
if (useStdio) {
409+
let writer = new rpc.StreamMessageWriter(process.stdout);
410+
let reader = new rpc.StreamMessageReader(process.stdin);
411+
// proper `this` scope for writer
412+
send = (msg: p.Message) => writer.write(msg);
413+
reader.listen(onMessage);
414+
} else {
415+
// proper `this` scope for process
416+
send = (msg: p.Message) => process.send!(msg);
417+
process.on("message", onMessage);
418+
}
417419
}
418420

419421
function hover(msg: p.RequestMessage) {

0 commit comments

Comments
 (0)