From 0cce8636963192d29a32c4970f4069656abbedf8 Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Tue, 28 Nov 2023 17:30:02 +0100 Subject: [PATCH] [example] Example how to use the LSP client To run ```bash $ cd test/server $ npx tsc -b . && node src/simple_client.js ``` --- test/server/src/simple_client.ts | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/server/src/simple_client.ts diff --git a/test/server/src/simple_client.ts b/test/server/src/simple_client.ts new file mode 100644 index 00000000..84ced23c --- /dev/null +++ b/test/server/src/simple_client.ts @@ -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 = { + 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) + }) +});