@@ -4,8 +4,8 @@ use lsp_server::{Connection, ErrorCode, Message, Response};
44use lsp_textdocument:: { FullTextDocument , TextDocuments } ;
55use lsp_types:: {
66 request:: { Formatting , RangeFormatting , Request } ,
7- DocumentFormattingParams , DocumentRangeFormattingParams , FormattingOptions , OneOf ,
8- Position , Range , ServerCapabilities , ServerInfo , TextDocumentSyncCapability ,
7+ DocumentFormattingParams , DocumentRangeFormattingParams , FormattingOptions , InitializeResult ,
8+ OneOf , Position , Range , ServerCapabilities , ServerInfo , TextDocumentSyncCapability ,
99 TextDocumentSyncKind , TextEdit , Uri ,
1010} ;
1111use stylua_lib:: { format_code, IndentType , OutputVerification } ;
@@ -139,14 +139,22 @@ fn handle_request(
139139}
140140
141141fn main_loop ( connection : Connection , config_resolver : & mut ConfigResolver ) -> anyhow:: Result < ( ) > {
142- let capabilities = ServerCapabilities {
143- document_formatting_provider : Some ( OneOf :: Left ( true ) ) ,
144- text_document_sync : Some ( TextDocumentSyncCapability :: Kind (
145- TextDocumentSyncKind :: INCREMENTAL ,
146- ) ) ,
147- ..Default :: default ( )
142+ let initialize_result = InitializeResult {
143+ capabilities : ServerCapabilities {
144+ document_formatting_provider : Some ( OneOf :: Left ( true ) ) ,
145+ text_document_sync : Some ( TextDocumentSyncCapability :: Kind (
146+ TextDocumentSyncKind :: INCREMENTAL ,
147+ ) ) ,
148+ ..Default :: default ( )
149+ } ,
150+ server_info : Some ( ServerInfo {
151+ name : "stylua" . to_string ( ) ,
152+ version : Some ( env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ) ,
153+ } ) ,
148154 } ;
149- connection. initialize ( serde_json:: to_value ( capabilities) ?) ?;
155+
156+ let ( id, _) = connection. initialize_start ( ) ?;
157+ connection. initialize_finish ( id, serde_json:: to_value ( initialize_result) ?) ?;
150158
151159 let mut documents = TextDocuments :: new ( ) ;
152160 for msg in & connection. receiver {
@@ -198,7 +206,9 @@ mod tests {
198206 FormattingOptions , InitializeParams , Position , Range , TextDocumentIdentifier ,
199207 TextDocumentItem , TextEdit , Uri , WorkDoneProgressParams ,
200208 } ;
201- use lsp_types:: { OneOf , ServerCapabilities , TextDocumentSyncCapability , TextDocumentSyncKind } ;
209+ use lsp_types:: {
210+ OneOf , ServerCapabilities , ServerInfo , TextDocumentSyncCapability , TextDocumentSyncKind ,
211+ } ;
202212 use serde:: de:: DeserializeOwned ;
203213 use serde_json:: to_value;
204214
@@ -249,7 +259,12 @@ mod tests {
249259 TextDocumentSyncKind :: INCREMENTAL ,
250260 ) ) ,
251261 ..Default :: default ( )
252- } } ) => { }
262+ } ,
263+ "serverInfo" : Some ( ServerInfo {
264+ name: "stylua" . to_string( ) ,
265+ version: Some ( env!( "CARGO_PKG_VERSION" ) . to_string( ) ) ,
266+ } ) ,
267+ } ) => { }
253268 _ => panic ! ( "assertion failed" ) ,
254269 }
255270 }
0 commit comments