@@ -5,8 +5,8 @@ import deepEqual from 'deep-equal';
5
5
import WebRequest from 'web-request' ;
6
6
import deepmerge from 'deepmerge' ;
7
7
import { Mutex } from 'async-mutex' ;
8
- import vscode , { ExtensionContext } from 'vscode' ;
9
- import { LanguageClient , CloseAction , ErrorAction , InitializeError , Message , RevealOutputChannelOn } from 'vscode-languageclient' ;
8
+ import vscode , { ExtensionContext , OutputChannel } from 'vscode' ;
9
+ import { LanguageClient , CloseAction , ErrorAction , InitializeError , Message , RevealOutputChannelOn , LanguageClientOptions } from 'vscode-languageclient' ;
10
10
import { DidCompleteBuildNotification , DidCompleteBuildParams } from './protocol' ;
11
11
12
12
interface LanguageServerConfig {
@@ -28,6 +28,7 @@ interface LanguageServerConfig {
28
28
readonly env ?: any ;
29
29
readonly flags ?: string [ ] ;
30
30
readonly realTimeDiagnostics ?: boolean ;
31
+ readonly silentOutput ?: boolean ;
31
32
}
32
33
33
34
interface DebugConfig {
@@ -224,43 +225,48 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
224
225
args . push ( '-logpath' , logPath ) ;
225
226
}
226
227
}
227
- return new LanguageClient (
228
- 'ino' ,
229
- 'Arduino Language Server' ,
230
- {
231
- command,
232
- args,
233
- options : { env } ,
228
+ const clientOptions = {
229
+ initializationOptions : { } ,
230
+ documentSelector : [ 'ino' , 'c' , 'cpp' , 'h' , 'hpp' , 'pde' ] ,
231
+ uriConverters : {
232
+ code2Protocol : ( uri : vscode . Uri ) : string => ( uri . scheme ? uri : uri . with ( { scheme : 'file' } ) ) . toString ( ) ,
233
+ protocol2Code : ( uri : string ) => vscode . Uri . parse ( uri )
234
234
} ,
235
- {
236
- initializationOptions : { } ,
237
- documentSelector : [ 'ino' , 'c' , 'cpp' , 'h' , 'hpp' , 'pde' ] ,
238
- uriConverters : {
239
- code2Protocol : ( uri : vscode . Uri ) : string => ( uri . scheme ? uri : uri . with ( { scheme : 'file' } ) ) . toString ( ) ,
240
- protocol2Code : ( uri : string ) => vscode . Uri . parse ( uri )
241
- } ,
242
- revealOutputChannelOn : RevealOutputChannelOn . Never ,
243
- initializationFailedHandler : ( error : WebRequest . ResponseError < InitializeError > ) : boolean => {
244
- vscode . window . showErrorMessage ( `The language server is not able to serve any features. Initialization failed: ${ error } .` ) ;
245
- return false ;
235
+ revealOutputChannelOn : RevealOutputChannelOn . Never ,
236
+ initializationFailedHandler : ( error : WebRequest . ResponseError < InitializeError > ) : boolean => {
237
+ vscode . window . showErrorMessage ( `The language server is not able to serve any features. Initialization failed: ${ error } .` ) ;
238
+ return false ;
239
+ } ,
240
+ errorHandler : {
241
+ error : ( error : Error , message : Message , count : number ) : ErrorAction => {
242
+ vscode . window . showErrorMessage ( `Error communicating with the language server: ${ error } : ${ message } .` ) ;
243
+ if ( count < 5 ) {
244
+ return ErrorAction . Continue ;
245
+ }
246
+ return ErrorAction . Shutdown ;
246
247
} ,
247
- errorHandler : {
248
- error : ( error : Error , message : Message , count : number ) : ErrorAction => {
249
- vscode . window . showErrorMessage ( `Error communicating with the language server: ${ error } : ${ message } .` ) ;
250
- if ( count < 5 ) {
251
- return ErrorAction . Continue ;
252
- }
253
- return ErrorAction . Shutdown ;
254
- } ,
255
- closed : ( ) : CloseAction => {
256
- crashCount ++ ;
257
- if ( crashCount < 5 ) {
258
- return CloseAction . Restart ;
259
- }
260
- return CloseAction . DoNotRestart ;
248
+ closed : ( ) : CloseAction => {
249
+ crashCount ++ ;
250
+ if ( crashCount < 5 ) {
251
+ return CloseAction . Restart ;
261
252
}
253
+ return CloseAction . DoNotRestart ;
262
254
}
263
255
}
256
+ } as LanguageClientOptions ;
257
+ if ( ! ! config . silentOutput ) {
258
+ clientOptions . outputChannel = noopOutputChannel ( 'Arduino Language Server' ) ;
259
+ }
260
+ const serverOptions = {
261
+ command,
262
+ args,
263
+ options : { env } ,
264
+ } ;
265
+ return new LanguageClient (
266
+ 'ino' ,
267
+ 'Arduino Language Server' ,
268
+ serverOptions ,
269
+ clientOptions
264
270
) ;
265
271
}
266
272
@@ -282,3 +288,15 @@ async function updateLaunchConfig(debugConfig: DebugConfig, launchConfig: object
282
288
await configuration . update ( 'launch' , launchConfig , false ) ;
283
289
}
284
290
}
291
+
292
+ function noopOutputChannel ( name : string ) : OutputChannel {
293
+ return {
294
+ append : ( ) => { } ,
295
+ appendLine : ( ) => { } ,
296
+ clear : ( ) => { } ,
297
+ dispose : ( ) => { } ,
298
+ hide : ( ) => { } ,
299
+ show : ( ) => { } ,
300
+ name
301
+ } ;
302
+ }
0 commit comments