@@ -69,7 +69,44 @@ let client: LanguageClient;
6969// });
7070
7171export function activate ( context : ExtensionContext ) {
72- function attachCodeAnalysis ( client : LanguageClient ) {
72+ function createLanguageClient ( ) {
73+ // The server is implemented in node
74+ let serverModule = context . asAbsolutePath (
75+ path . join ( "server" , "out" , "server.js" )
76+ ) ;
77+ // The debug options for the server
78+ // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
79+ let debugOptions = { execArgv : [ "--nolazy" , "--inspect=6009" ] } ;
80+
81+ // If the extension is launched in debug mode then the debug server options are used
82+ // Otherwise the run options are used
83+ let serverOptions : ServerOptions = {
84+ run : { module : serverModule , transport : TransportKind . ipc } ,
85+ debug : {
86+ module : serverModule ,
87+ transport : TransportKind . ipc ,
88+ options : debugOptions ,
89+ } ,
90+ } ;
91+
92+ // Options to control the language client
93+ let clientOptions : LanguageClientOptions = {
94+ documentSelector : [ { scheme : "file" , language : "rescript" } ] ,
95+ // We'll send the initial configuration in here, but this might be
96+ // problematic because every consumer of the LS will need to mimic this.
97+ // We'll leave it like this for now, but might be worth revisiting later on.
98+ initializationOptions : {
99+ extensionConfiguration : workspace . getConfiguration ( "rescript.settings" ) ,
100+ } ,
101+ } ;
102+
103+ const client = new LanguageClient (
104+ "ReScriptLSP" ,
105+ "ReScript Language Server" ,
106+ serverOptions ,
107+ clientOptions
108+ ) ;
109+
73110 // This sets up a listener that, if we're in code analysis mode, triggers
74111 // code analysis as the LS server reports that ReScript compilation has
75112 // finished. This is needed because code analysis must wait until
@@ -89,55 +126,10 @@ export function activate(context: ExtensionContext) {
89126 } )
90127 ) ;
91128 } ) ;
92- }
93129
94- /** creates a language client and attaches code analysis */
95- function createLanguageClient ( ) {
96- const client = new LanguageClient (
97- "ReScriptLSP" ,
98- "ReScript Language Server" ,
99- serverOptions ,
100- clientOptions
101- ) ;
102- attachCodeAnalysis ( client ) ;
103130 return client ;
104131 }
105132
106- // The server is implemented in node
107- let serverModule = context . asAbsolutePath (
108- path . join ( "server" , "out" , "server.js" )
109- ) ;
110- // The debug options for the server
111- // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
112- let debugOptions = { execArgv : [ "--nolazy" , "--inspect=6009" ] } ;
113-
114- // If the extension is launched in debug mode then the debug server options are used
115- // Otherwise the run options are used
116- let serverOptions : ServerOptions = {
117- run : { module : serverModule , transport : TransportKind . ipc } ,
118- debug : {
119- module : serverModule ,
120- transport : TransportKind . ipc ,
121- options : debugOptions ,
122- } ,
123- } ;
124-
125- // Options to control the language client
126- let clientOptions : LanguageClientOptions = {
127- // Register the server for plain text documents
128- documentSelector : [ { scheme : "file" , language : "rescript" } ] ,
129- synchronize : {
130- // Notify the server about file changes to '.clientrc files contained in the workspace
131- fileEvents : workspace . createFileSystemWatcher ( "**/.clientrc" ) ,
132- } ,
133- // We'll send the initial configuration in here, but this might be
134- // problematic because every consumer of the LS will need to mimic this.
135- // We'll leave it like this for now, but might be worth revisiting later on.
136- initializationOptions : {
137- extensionConfiguration : workspace . getConfiguration ( "rescript.settings" ) ,
138- } ,
139- } ;
140-
141133 // Create the language client and start the client.
142134 client = createLanguageClient ( ) ;
143135
0 commit comments