@@ -204,6 +204,71 @@ The low-level API is as follows:
204204
205205For examples how to use them, please refer to the README of the above mentioned solc-js releases.
206206
207+ #### Language Server Mode
208+
209+ Since version 0.8.11, the solidity compiler natively supports the
210+ language server protocol. With solc-js, you can now use it as follows:
211+
212+ ``` javascript
213+ var solc = require (' solc' );
214+
215+ // Callback to be invoked when additional files have to be opened during
216+ // source code analysis stage.
217+ //
218+ // This function behaves similar to the compilation file reader callback.
219+ function fileReadCallback (path )
220+ {
221+ if (' path' === ' file:///project/lib.sol' ) {
222+ return {
223+ contents: ' library L { function f() internal returns (uint) { return 7; } }' ;
224+ };
225+ }
226+ else
227+ return { error: ' File not found' };
228+ }
229+
230+ // Put solcjs into LSP mode.
231+ // Needs to be called only once before the actual LSP I/O calls.
232+ solc .lspStart (fileReadCallback);
233+
234+ // Send some LSP JSON-RPC message and optionally receive a reply.
235+ var lspInitializationMessage = {
236+ ' jsonrpc' : ' 2.0' ,
237+ ' method' : ' initialize' ,
238+ ' params' : {
239+ ' rootUri' : ' file:///project/' ,
240+ ' capabilities' : {
241+ ' textDocument' : {
242+ ' publishDiagnostics' : {' relatedInformation' : true }
243+ },
244+ ' workspace' : {
245+ ' applyEdit' : true ,
246+ ' configuration' : true ,
247+ ' didChangeConfiguration' : {' dynamicRegistration' : true },
248+ ' workspaceEdit' : {' documentChanges' : true },
249+ ' workspaceFolders' : true
250+ }
251+ }
252+ }
253+ };
254+ solc .lspSendReceive (JSON .stringify (lspInitializationMessage)));
255+ solc .lspSendReceive (JSON .stringify ({' jsonrpc' : ' 2.0' , ' method' : ' initialized' }));
256+
257+ // Now, with the LSP server, being set up the following
258+ // can be called as often as needed.
259+ function lspRoundtrip (jsonRpcInputObject )
260+ {
261+ return JSON .parse (solc .lspSendReceive (JSON .stringify (jsonRpcInputObject)));
262+ }
263+ ```
264+
265+ This is a low level API endpoint for use by language server clients,
266+ such as Visual Studio Code, or any other editor.
267+ In order to know what you can pass in and what can come out,
268+ it is highly recommended to have a look at:
269+
270+ https://microsoft.github.io/language-server-protocol/specification
271+
207272### Using with Electron
208273
209274** Note:**
0 commit comments