Skip to content

Commit

Permalink
[example] Example how to use the LSP client
Browse files Browse the repository at this point in the history
To run

```bash
$ cd test/server
$ npx tsc -b . && node src/simple_client.js
```
  • Loading branch information
ejgallego committed May 10, 2024
1 parent 1b884fc commit c5b937e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/server/src/simple_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as Protocol from "vscode-languageserver-protocol";
import * as Types from "vscode-languageserver-types";
import * as LS from "./LanguageServer";

async function start() {
let languageServer = LS.start();
let initializeParameters: Partial<Protocol.InitializeParams> = {
rootPath: ".",
rootUri: ".",
trace: "verbose",
workspaceFolders: null,
};
let result = await languageServer.initialize(initializeParameters);
return languageServer;
}

async function sendSimpleDoc(languageServer : LS.LanguageServer, text : string) {
let textDocument = Types.TextDocumentItem.create(
"file.v",
"coq",
0,
text,
);
await languageServer.sendNotification(
Protocol.DidOpenTextDocumentNotification.type,
{
textDocument,
},
);
}
function printDiags(params : Protocol.PublishDiagnosticsParams) {
console.log(`${params.diagnostics.length} diagnostics received`);
console.log(params.diagnostics);
}

start().then((ls) => {
console.log("Starting");
ls.onNotification(Protocol.PublishDiagnosticsNotification.type, printDiags);
sendSimpleDoc(ls, "Definition a := 3. Variable (b : nat). Error. ").then(() => {
setTimeout(() => { ls.exit(); }, 5000)
})
});

0 comments on commit c5b937e

Please sign in to comment.