-
-
Notifications
You must be signed in to change notification settings - Fork 9
Language Server Protocol for Dart
Shirish Kadam edited this page May 23, 2023
·
4 revisions
The Language Server Protocol (LSP), which is designed to integrate multiple languages into code editors and IDEs. In this case, we are using the Dart language server.
To run this server and interact with it, we'll be starting the process, listening for JSON-RPC messages on its stdout, and writing JSON-RPC messages to its stdin. Here the client 'Tonic IDE' will be interacting with the server by sending request, notifications and the server will be responding back to the client with appropriate resolution.
In order to start and initialize the LSP server, you need to follow these steps:
- Start a new process, which will be your LSP server.
dart language-server --client-id my-editor.my-plugin --client-version 1.2
- After starting the server, client needs need to send an
initialize
request to it. This is done by writing a properly formed request to thestdin
of the process. - Client can now monitor the server by listening to its
stdout
andstderr
streams. This allows it to process any output or errors that the server produces.
As for the sequence of stop operations, the typical sequence would be:
- Send the
shutdown
request to the server. This request asks the server to shut down, but it does not actually cause the server to exit. - Wait for the server to respond to the
shutdown
request. The server should respond with an empty response ({}
). - Send the
exit
notification to the server. This notification asks the server to exit. - Close the input stream of the server process. This is necessary because the server might still be waiting for input.
- Wait for the server process to exit. You can do this by waiting on
Process.exitCode
. If the server does not exit within a reasonable time, send theSIGTERM
signal to the server process withProcess.kill()
. If the server still does not exit, send theSIGKILL
signal withProcess.kill(ProcessSignal.sigkill)
.