1
1
import { window , commands , workspace , QuickPickItem , ExtensionContext , Uri } from "vscode" ;
2
+ import { LanguageClient , LanguageClientOptions , ServerOptions } from 'vscode-languageclient' ;
3
+ import { Trace } from 'vscode-jsonrpc' ;
2
4
import * as chocolateyCli from "./ChocolateyCliManager" ;
3
5
import * as chocolateyOps from "./ChocolateyOperation" ;
4
6
import * as path from "path" ;
@@ -7,6 +9,13 @@ import * as fs from "fs";
7
9
var chocolateyManager : chocolateyCli . ChocolateyCliManager ;
8
10
var installed : boolean = false ;
9
11
12
+ const languageServerPaths = [
13
+ // TODO: Change path to the actually expected location of the language server
14
+ "out/.server/Chocolatey.Language.Server.dll" ,
15
+ "./src/Chocolatey.Language.Server/bin/Release/netcoreapp2.1/Chocolatey.Language.Server.dll" ,
16
+ "./src/Chocolatey.Language.Server/bin/Debug/netcoreapp2.1/Chocolatey.Language.Server.dll"
17
+ ] ;
18
+
10
19
export function activate ( context : ExtensionContext ) : void {
11
20
// register Commands
12
21
context . subscriptions . push (
@@ -18,6 +27,65 @@ export function activate(context: ExtensionContext): void {
18
27
commands . registerCommand ( "chocolatey.apikey" , ( ) => execute ( "apikey" ) ) ,
19
28
commands . registerCommand ( "chocolatey.open" , async ( uri : string ) => await commands . executeCommand ( 'vscode.open' , Uri . parse ( uri ) ) )
20
29
) ;
30
+
31
+ let config = workspace . getConfiguration ( "chocolatey.language" ) ;
32
+ let disableLanguageService : boolean | undefined = false ;
33
+
34
+ if ( config !== undefined ) {
35
+ disableLanguageService = config . get ( "disableLanguageService" )
36
+ }
37
+
38
+ // Only start the Language Service if configured to do so
39
+ if ( ! disableLanguageService ) {
40
+ let serverExe = 'dotnet' ;
41
+ let serverModule : string | null = null ;
42
+ for ( let p of languageServerPaths ) {
43
+ p = context . asAbsolutePath ( p ) ;
44
+ // console.log/p);
45
+ if ( fs . existsSync ( p ) ) {
46
+ serverModule = p ;
47
+ break ;
48
+ }
49
+ }
50
+
51
+ // TODO: Decision need to be made if the Language Server should
52
+ // be packed inside the vsix file, or downloaded during runtime.
53
+
54
+ if ( ! serverModule ) { throw new URIError ( "Cannot find the language server module." ) ; }
55
+ let workPath = path . dirname ( serverModule ) ;
56
+ console . log ( `Use ${ serverModule } as server module.` ) ;
57
+ console . log ( `Work path: ${ workPath } ` ) ;
58
+
59
+ // If the extension is launched in debug mode then the debug server options are used
60
+ // Otherwise the run options are used
61
+ let serverOptions : ServerOptions = {
62
+ run : { command : serverExe , args : [ serverModule ] , options : { cwd : workPath } } ,
63
+ debug : { command : serverExe , args : [ serverModule , "--debug" ] , options : { cwd : workPath } }
64
+ } ;
65
+
66
+ // Options to control the language client
67
+ let clientOptions : LanguageClientOptions = {
68
+ // Register the server for plain text documents
69
+ documentSelector : [
70
+ {
71
+ pattern : '**/*.nuspec' ,
72
+ }
73
+ ] ,
74
+ synchronize : {
75
+ configurationSection : 'chocolatey' ,
76
+ fileEvents : workspace . createFileSystemWatcher ( '**/*.nuspec' )
77
+ } ,
78
+ }
79
+
80
+ // Create the language client and start the client.
81
+ const client = new LanguageClient ( 'chocolatey' , 'Chocolatey Language Server' , serverOptions , clientOptions ) ;
82
+ client . trace = Trace . Verbose ;
83
+ let disposable = client . start ( ) ;
84
+
85
+ // Push the disposable to the context's subscriptions so that the
86
+ // client can be deactivated on extension deactivation
87
+ context . subscriptions . push ( disposable ) ;
88
+ }
21
89
}
22
90
23
91
function deleteNupkgs ( ) :void {
0 commit comments