1- // The module 'vscode' contains the VS Code extensibility API
2- // Import the module and reference it with the alias vscode in your code below
31import * as vscode from 'vscode' ;
2+ import { workspace , ExtensionContext } from 'vscode' ;
43
5- // this method is called when your extension is activated
6- // your extension is activated the very first time the command is executed
7- export function activate ( context : vscode . ExtensionContext ) {
4+ import {
5+ LanguageClient ,
6+ LanguageClientOptions ,
7+ ServerOptions
8+ } from 'vscode-languageclient/node' ;
89
9- // Use the console to output diagnostic information (console.log) and errors (console.error)
10- // This line of code will only be executed once when your extension is activated
11- console . log ( 'Congratulations, your extension "zk-vscode" is now active!' ) ;
10+ let client : LanguageClient ;
1211
13- // The command has been defined in the package.json file
14- // Now provide the implementation of the command with registerCommand
15- // The commandId parameter must match the command field in package.json
16- let disposable = vscode . commands . registerCommand ( 'zk-vscode.helloWorld' , ( ) => {
17- // The code you place here will be executed every time your command is executed
12+ export function activate ( context : ExtensionContext ) {
13+ const clientName = "zk"
14+ const clientId = "zk"
1815
19- // Display a message box to the user
20- vscode . window . showInformationMessage ( 'Hello World from zk-vscode!' ) ;
21- } ) ;
16+ // If the extension is launched in debug mode then the debug server options are used
17+ // Otherwise the run options are used
18+ let serverOptions : ServerOptions = {
19+ run : { command : "zk" , args : [ "lsp" ] } ,
20+ debug : { command : "zk" , args : [ "lsp" , "--log" , "/tmp/zk-lsp.log" ] }
21+ } ;
2222
23- context . subscriptions . push ( disposable ) ;
23+ let clientOptions : LanguageClientOptions = {
24+ // Register the server for Markdown documents.
25+ documentSelector : [ { scheme : 'file' , language : 'markdown' } ] ,
26+ } ;
27+
28+ client = new LanguageClient ( clientId , clientName , serverOptions , clientOptions ) ;
29+
30+
31+ // Start the client. This will also launch the server.
32+ client . start ( ) ;
2433}
2534
26- // this method is called when your extension is deactivated
27- export function deactivate ( ) { }
35+ export function deactivate ( ) : Thenable < void > | undefined {
36+ if ( ! client ) {
37+ return undefined ;
38+ }
39+ return client . stop ( ) ;
40+ }
0 commit comments