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 Nov 28, 2023
1 parent 75a92e0 commit 0cce863
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 0cce863

Please sign in to comment.