How to write a log with vscode extension?

I am trying to develop a language server extension for VSCode. I am trying to understand how to write text for registration from the language server side of the extension. console.log produces nothing

+7
source share
4 answers

You must set the outputChannelName property for client parameters inside the client extension code:

 let clientOptions: LanguageClientOptions = { outputChannelName: 'XYZ Language Server', }; 

After that, you can use console.log() and it will be displayed in the output pane of the VSCode extension.

+5
source

On the server side, try using connection.console.log.

 // Create a connection for the server. The connection uses // stdin / stdout for message passing let connection: IConnection = createConnection(process.stdin, process.stdout); connection.console.log(`Console test.`); 

A message showing in the debug console on the client side.

For the client side, a simple console.log works well for me.

+4
source

Language Server Protocol supports logging, use the window / logMessage notification to send log messages from the server, VS Code will display the server log in the output panel in the channel corresponding to the language client that started the server.

+1
source

As an update, you can use vscode.window.createOutputChannel to create an output container and then write the appendLine method to appendLine .

  //Create output channel let orange = vscode.window.createOutputChannel("Orange"); //Write to output. orange.appendLine("I am a banana."); 

Results of creating output channel.

+1
source

All Articles