-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Example how to use the LSP client
To run ```bash $ cd test/server $ npx tsc -b . && node src/simple_client.js ```
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}); |