@@ -104,7 +104,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
104104
105105 if project_roots. is_empty ( ) && config. notifications . cargo_toml_not_found {
106106 show_message (
107- req :: MessageType :: Error ,
107+ lsp_types :: MessageType :: Error ,
108108 format ! (
109109 "rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}" ,
110110 ws_roots. iter( ) . format_with( ", " , |it, f| f( & it. display( ) ) )
@@ -124,7 +124,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
124124 . map_err ( |err| {
125125 log:: error!( "failed to load workspace: {:#}" , err) ;
126126 show_message (
127- req :: MessageType :: Error ,
127+ lsp_types :: MessageType :: Error ,
128128 format ! ( "rust-analyzer failed to load workspace: {:#}" , err) ,
129129 & connection. sender ,
130130 ) ;
@@ -142,23 +142,25 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
142142 . collect :: < std:: result:: Result < Vec < _ > , _ > > ( ) ?;
143143
144144 if let FilesWatcher :: Client = config. files . watcher {
145- let registration_options = req :: DidChangeWatchedFilesRegistrationOptions {
145+ let registration_options = lsp_types :: DidChangeWatchedFilesRegistrationOptions {
146146 watchers : workspaces
147147 . iter ( )
148148 . flat_map ( ProjectWorkspace :: to_roots)
149149 . filter ( PackageRoot :: is_member)
150150 . map ( |root| format ! ( "{}/**/*.rs" , root. path( ) . display( ) ) )
151- . map ( |glob_pattern| req :: FileSystemWatcher { glob_pattern, kind : None } )
151+ . map ( |glob_pattern| lsp_types :: FileSystemWatcher { glob_pattern, kind : None } )
152152 . collect ( ) ,
153153 } ;
154- let registration = req :: Registration {
154+ let registration = lsp_types :: Registration {
155155 id : "file-watcher" . to_string ( ) ,
156156 method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
157157 register_options : Some ( serde_json:: to_value ( registration_options) . unwrap ( ) ) ,
158158 } ;
159- let params = req:: RegistrationParams { registrations : vec ! [ registration] } ;
160- let request =
161- request_new :: < req:: RegisterCapability > ( loop_state. next_request_id ( ) , params) ;
159+ let params = lsp_types:: RegistrationParams { registrations : vec ! [ registration] } ;
160+ let request = request_new :: < lsp_types:: request:: RegisterCapability > (
161+ loop_state. next_request_id ( ) ,
162+ params,
163+ ) ;
162164 connection. sender . send ( request. into ( ) ) . unwrap ( ) ;
163165 }
164166
@@ -258,14 +260,14 @@ impl fmt::Debug for Event {
258260
259261 match self {
260262 Event :: Msg ( Message :: Notification ( not) ) => {
261- if notification_is :: < req :: DidOpenTextDocument > ( not)
262- || notification_is :: < req :: DidChangeTextDocument > ( not)
263+ if notification_is :: < lsp_types :: notification :: DidOpenTextDocument > ( not)
264+ || notification_is :: < lsp_types :: notification :: DidChangeTextDocument > ( not)
263265 {
264266 return debug_verbose_not ( not, f) ;
265267 }
266268 }
267269 Event :: Task ( Task :: Notify ( not) ) => {
268- if notification_is :: < req :: PublishDiagnostics > ( not) {
270+ if notification_is :: < lsp_types :: notification :: PublishDiagnostics > ( not) {
269271 return debug_verbose_not ( not, f) ;
270272 }
271273 }
@@ -450,7 +452,7 @@ fn loop_turn(
450452 log:: error!( "overly long loop turn: {:?}" , loop_duration) ;
451453 if env:: var ( "RA_PROFILE" ) . is_ok ( ) {
452454 show_message (
453- req :: MessageType :: Error ,
455+ lsp_types :: MessageType :: Error ,
454456 format ! ( "overly long loop turn: {:?}" , loop_duration) ,
455457 & connection. sender ,
456458 ) ;
@@ -503,7 +505,7 @@ fn on_request(
503505 . on_sync :: < req:: CollectGarbage > ( |s, ( ) | Ok ( s. collect_garbage ( ) ) ) ?
504506 . on_sync :: < req:: JoinLines > ( |s, p| handlers:: handle_join_lines ( s. snapshot ( ) , p) ) ?
505507 . on_sync :: < req:: OnEnter > ( |s, p| handlers:: handle_on_enter ( s. snapshot ( ) , p) ) ?
506- . on_sync :: < req :: SelectionRangeRequest > ( |s, p| {
508+ . on_sync :: < lsp_types :: request :: SelectionRangeRequest > ( |s, p| {
507509 handlers:: handle_selection_range ( s. snapshot ( ) , p)
508510 } ) ?
509511 . on_sync :: < req:: FindMatchingBrace > ( |s, p| {
@@ -512,32 +514,38 @@ fn on_request(
512514 . on :: < req:: AnalyzerStatus > ( handlers:: handle_analyzer_status) ?
513515 . on :: < req:: SyntaxTree > ( handlers:: handle_syntax_tree) ?
514516 . on :: < req:: ExpandMacro > ( handlers:: handle_expand_macro) ?
515- . on :: < req :: OnTypeFormatting > ( handlers:: handle_on_type_formatting) ?
516- . on :: < req :: DocumentSymbolRequest > ( handlers:: handle_document_symbol) ?
517- . on :: < req :: WorkspaceSymbol > ( handlers:: handle_workspace_symbol) ?
518- . on :: < req :: GotoDefinition > ( handlers:: handle_goto_definition) ?
519- . on :: < req :: GotoImplementation > ( handlers:: handle_goto_implementation) ?
520- . on :: < req :: GotoTypeDefinition > ( handlers:: handle_goto_type_definition) ?
517+ . on :: < lsp_types :: request :: OnTypeFormatting > ( handlers:: handle_on_type_formatting) ?
518+ . on :: < lsp_types :: request :: DocumentSymbolRequest > ( handlers:: handle_document_symbol) ?
519+ . on :: < lsp_types :: request :: WorkspaceSymbol > ( handlers:: handle_workspace_symbol) ?
520+ . on :: < lsp_types :: request :: GotoDefinition > ( handlers:: handle_goto_definition) ?
521+ . on :: < lsp_types :: request :: GotoImplementation > ( handlers:: handle_goto_implementation) ?
522+ . on :: < lsp_types :: request :: GotoTypeDefinition > ( handlers:: handle_goto_type_definition) ?
521523 . on :: < req:: ParentModule > ( handlers:: handle_parent_module) ?
522524 . on :: < req:: Runnables > ( handlers:: handle_runnables) ?
523- . on :: < req :: Completion > ( handlers:: handle_completion) ?
524- . on :: < req :: CodeActionRequest > ( handlers:: handle_code_action) ?
525- . on :: < req :: CodeLensRequest > ( handlers:: handle_code_lens) ?
526- . on :: < req :: CodeLensResolve > ( handlers:: handle_code_lens_resolve) ?
527- . on :: < req :: FoldingRangeRequest > ( handlers:: handle_folding_range) ?
528- . on :: < req :: SignatureHelpRequest > ( handlers:: handle_signature_help) ?
529- . on :: < req :: HoverRequest > ( handlers:: handle_hover) ?
530- . on :: < req :: PrepareRenameRequest > ( handlers:: handle_prepare_rename) ?
531- . on :: < req :: Rename > ( handlers:: handle_rename) ?
532- . on :: < req :: References > ( handlers:: handle_references) ?
533- . on :: < req :: Formatting > ( handlers:: handle_formatting) ?
534- . on :: < req :: DocumentHighlightRequest > ( handlers:: handle_document_highlight) ?
525+ . on :: < lsp_types :: request :: Completion > ( handlers:: handle_completion) ?
526+ . on :: < lsp_types :: request :: CodeActionRequest > ( handlers:: handle_code_action) ?
527+ . on :: < lsp_types :: request :: CodeLensRequest > ( handlers:: handle_code_lens) ?
528+ . on :: < lsp_types :: request :: CodeLensResolve > ( handlers:: handle_code_lens_resolve) ?
529+ . on :: < lsp_types :: request :: FoldingRangeRequest > ( handlers:: handle_folding_range) ?
530+ . on :: < lsp_types :: request :: SignatureHelpRequest > ( handlers:: handle_signature_help) ?
531+ . on :: < lsp_types :: request :: HoverRequest > ( handlers:: handle_hover) ?
532+ . on :: < lsp_types :: request :: PrepareRenameRequest > ( handlers:: handle_prepare_rename) ?
533+ . on :: < lsp_types :: request :: Rename > ( handlers:: handle_rename) ?
534+ . on :: < lsp_types :: request :: References > ( handlers:: handle_references) ?
535+ . on :: < lsp_types :: request :: Formatting > ( handlers:: handle_formatting) ?
536+ . on :: < lsp_types :: request :: DocumentHighlightRequest > ( handlers:: handle_document_highlight) ?
535537 . on :: < req:: InlayHints > ( handlers:: handle_inlay_hints) ?
536- . on :: < req:: CallHierarchyPrepare > ( handlers:: handle_call_hierarchy_prepare) ?
537- . on :: < req:: CallHierarchyIncomingCalls > ( handlers:: handle_call_hierarchy_incoming) ?
538- . on :: < req:: CallHierarchyOutgoingCalls > ( handlers:: handle_call_hierarchy_outgoing) ?
539- . on :: < req:: SemanticTokensRequest > ( handlers:: handle_semantic_tokens) ?
540- . on :: < req:: SemanticTokensRangeRequest > ( handlers:: handle_semantic_tokens_range) ?
538+ . on :: < lsp_types:: request:: CallHierarchyPrepare > ( handlers:: handle_call_hierarchy_prepare) ?
539+ . on :: < lsp_types:: request:: CallHierarchyIncomingCalls > (
540+ handlers:: handle_call_hierarchy_incoming,
541+ ) ?
542+ . on :: < lsp_types:: request:: CallHierarchyOutgoingCalls > (
543+ handlers:: handle_call_hierarchy_outgoing,
544+ ) ?
545+ . on :: < lsp_types:: request:: SemanticTokensRequest > ( handlers:: handle_semantic_tokens) ?
546+ . on :: < lsp_types:: request:: SemanticTokensRangeRequest > (
547+ handlers:: handle_semantic_tokens_range,
548+ ) ?
541549 . on :: < req:: Ssr > ( handlers:: handle_ssr) ?
542550 . finish ( ) ;
543551 Ok ( ( ) )
@@ -549,7 +557,7 @@ fn on_notification(
549557 loop_state : & mut LoopState ,
550558 not : Notification ,
551559) -> Result < ( ) > {
552- let not = match notification_cast :: < req :: Cancel > ( not) {
560+ let not = match notification_cast :: < lsp_types :: notification :: Cancel > ( not) {
553561 Ok ( params) => {
554562 let id: RequestId = match params. id {
555563 NumberOrString :: Number ( id) => id. into ( ) ,
@@ -567,7 +575,7 @@ fn on_notification(
567575 }
568576 Err ( not) => not,
569577 } ;
570- let not = match notification_cast :: < req :: DidOpenTextDocument > ( not) {
578+ let not = match notification_cast :: < lsp_types :: notification :: DidOpenTextDocument > ( not) {
571579 Ok ( params) => {
572580 let uri = params. text_document . uri ;
573581 let path = uri. to_file_path ( ) . map_err ( |( ) | format ! ( "invalid uri: {}" , uri) ) ?;
@@ -580,7 +588,7 @@ fn on_notification(
580588 }
581589 Err ( not) => not,
582590 } ;
583- let not = match notification_cast :: < req :: DidChangeTextDocument > ( not) {
591+ let not = match notification_cast :: < lsp_types :: notification :: DidChangeTextDocument > ( not) {
584592 Ok ( params) => {
585593 let DidChangeTextDocumentParams { text_document, content_changes } = params;
586594 let world = state. snapshot ( ) ;
@@ -595,7 +603,7 @@ fn on_notification(
595603 }
596604 Err ( not) => not,
597605 } ;
598- let not = match notification_cast :: < req :: DidSaveTextDocument > ( not) {
606+ let not = match notification_cast :: < lsp_types :: notification :: DidSaveTextDocument > ( not) {
599607 Ok ( _params) => {
600608 if let Some ( flycheck) = & state. flycheck {
601609 flycheck. update ( ) ;
@@ -604,30 +612,30 @@ fn on_notification(
604612 }
605613 Err ( not) => not,
606614 } ;
607- let not = match notification_cast :: < req :: DidCloseTextDocument > ( not) {
615+ let not = match notification_cast :: < lsp_types :: notification :: DidCloseTextDocument > ( not) {
608616 Ok ( params) => {
609617 let uri = params. text_document . uri ;
610618 let path = uri. to_file_path ( ) . map_err ( |( ) | format ! ( "invalid uri: {}" , uri) ) ?;
611619 if let Some ( file_id) = state. vfs . write ( ) . remove_file_overlay ( path. as_path ( ) ) {
612620 loop_state. subscriptions . remove_sub ( FileId ( file_id. 0 ) ) ;
613621 }
614622 let params =
615- req :: PublishDiagnosticsParams { uri, diagnostics : Vec :: new ( ) , version : None } ;
616- let not = notification_new :: < req :: PublishDiagnostics > ( params) ;
623+ lsp_types :: PublishDiagnosticsParams { uri, diagnostics : Vec :: new ( ) , version : None } ;
624+ let not = notification_new :: < lsp_types :: notification :: PublishDiagnostics > ( params) ;
617625 msg_sender. send ( not. into ( ) ) . unwrap ( ) ;
618626 return Ok ( ( ) ) ;
619627 }
620628 Err ( not) => not,
621629 } ;
622- let not = match notification_cast :: < req :: DidChangeConfiguration > ( not) {
630+ let not = match notification_cast :: < lsp_types :: notification :: DidChangeConfiguration > ( not) {
623631 Ok ( _) => {
624632 // As stated in https://github.com/microsoft/language-server-protocol/issues/676,
625633 // this notification's parameters should be ignored and the actual config queried separately.
626634 let request_id = loop_state. next_request_id ( ) ;
627- let request = request_new :: < req :: WorkspaceConfiguration > (
635+ let request = request_new :: < lsp_types :: request :: WorkspaceConfiguration > (
628636 request_id. clone ( ) ,
629- req :: ConfigurationParams {
630- items : vec ! [ req :: ConfigurationItem {
637+ lsp_types :: ConfigurationParams {
638+ items : vec ! [ lsp_types :: ConfigurationItem {
631639 scope_uri: None ,
632640 section: Some ( "rust-analyzer" . to_string( ) ) ,
633641 } ] ,
@@ -640,7 +648,7 @@ fn on_notification(
640648 }
641649 Err ( not) => not,
642650 } ;
643- let not = match notification_cast :: < req :: DidChangeWatchedFiles > ( not) {
651+ let not = match notification_cast :: < lsp_types :: notification :: DidChangeWatchedFiles > ( not) {
644652 Ok ( params) => {
645653 let mut vfs = state. vfs . write ( ) ;
646654 for change in params. changes {
@@ -742,11 +750,11 @@ fn on_check_task(
742750 }
743751
744752 CheckTask :: Status ( progress) => {
745- let params = req :: ProgressParams {
746- token : req :: ProgressToken :: String ( "rustAnalyzer/cargoWatcher" . to_string ( ) ) ,
747- value : req :: ProgressParamsValue :: WorkDone ( progress) ,
753+ let params = lsp_types :: ProgressParams {
754+ token : lsp_types :: ProgressToken :: String ( "rustAnalyzer/cargoWatcher" . to_string ( ) ) ,
755+ value : lsp_types :: ProgressParamsValue :: WorkDone ( progress) ,
748756 } ;
749- let not = notification_new :: < req :: Progress > ( params) ;
757+ let not = notification_new :: < lsp_types :: notification :: Progress > ( params) ;
750758 task_sender. send ( Task :: Notify ( not) ) . unwrap ( ) ;
751759 }
752760 } ;
@@ -768,8 +776,8 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender<Message>, state:
768776 } ;
769777
770778 let diagnostics = state. diagnostics . diagnostics_for ( file_id) . cloned ( ) . collect ( ) ;
771- let params = req :: PublishDiagnosticsParams { uri, diagnostics, version : None } ;
772- let not = notification_new :: < req :: PublishDiagnostics > ( params) ;
779+ let params = lsp_types :: PublishDiagnosticsParams { uri, diagnostics, version : None } ;
780+ let not = notification_new :: < lsp_types :: notification :: PublishDiagnostics > ( params) ;
773781 msg_sender. send ( not. into ( ) ) . unwrap ( ) ;
774782 }
775783}
@@ -782,10 +790,10 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
782790
783791 match ( prev, loop_state. workspace_loaded ) {
784792 ( None , false ) => {
785- let work_done_progress_create = request_new :: < req :: WorkDoneProgressCreate > (
793+ let work_done_progress_create = request_new :: < lsp_types :: request :: WorkDoneProgressCreate > (
786794 loop_state. next_request_id ( ) ,
787795 WorkDoneProgressCreateParams {
788- token : req :: ProgressToken :: String ( "rustAnalyzer/startup" . into ( ) ) ,
796+ token : lsp_types :: ProgressToken :: String ( "rustAnalyzer/startup" . into ( ) ) ,
789797 } ,
790798 ) ;
791799 sender. send ( work_done_progress_create. into ( ) ) . unwrap ( ) ;
@@ -817,10 +825,11 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
817825 }
818826
819827 fn send_startup_progress_notif ( sender : & Sender < Message > , work_done_progress : WorkDoneProgress ) {
820- let notif = notification_new :: < req:: Progress > ( req:: ProgressParams {
821- token : req:: ProgressToken :: String ( "rustAnalyzer/startup" . into ( ) ) ,
822- value : req:: ProgressParamsValue :: WorkDone ( work_done_progress) ,
823- } ) ;
828+ let notif =
829+ notification_new :: < lsp_types:: notification:: Progress > ( lsp_types:: ProgressParams {
830+ token : lsp_types:: ProgressToken :: String ( "rustAnalyzer/startup" . into ( ) ) ,
831+ value : lsp_types:: ProgressParamsValue :: WorkDone ( work_done_progress) ,
832+ } ) ;
824833 sender. send ( notif. into ( ) ) . unwrap ( ) ;
825834 }
826835}
@@ -842,7 +851,7 @@ impl<'a> PoolDispatcher<'a> {
842851 f : fn ( & mut WorldState , R :: Params ) -> Result < R :: Result > ,
843852 ) -> Result < & mut Self >
844853 where
845- R : req :: Request + ' static ,
854+ R : lsp_types :: request :: Request + ' static ,
846855 R :: Params : DeserializeOwned + panic:: UnwindSafe + ' static ,
847856 R :: Result : Serialize + ' static ,
848857 {
@@ -865,7 +874,7 @@ impl<'a> PoolDispatcher<'a> {
865874 /// Dispatches the request onto thread pool
866875 fn on < R > ( & mut self , f : fn ( WorldSnapshot , R :: Params ) -> Result < R :: Result > ) -> Result < & mut Self >
867876 where
868- R : req :: Request + ' static ,
877+ R : lsp_types :: request :: Request + ' static ,
869878 R :: Params : DeserializeOwned + Send + ' static ,
870879 R :: Result : Serialize + ' static ,
871880 {
@@ -891,7 +900,7 @@ impl<'a> PoolDispatcher<'a> {
891900
892901 fn parse < R > ( & mut self ) -> Option < ( RequestId , R :: Params ) >
893902 where
894- R : req :: Request + ' static ,
903+ R : lsp_types :: request :: Request + ' static ,
895904 R :: Params : DeserializeOwned + ' static ,
896905 {
897906 let req = self . req . take ( ) ?;
@@ -928,7 +937,7 @@ impl<'a> PoolDispatcher<'a> {
928937
929938fn result_to_task < R > ( id : RequestId , result : Result < R :: Result > ) -> Task
930939where
931- R : req :: Request + ' static ,
940+ R : lsp_types :: request :: Request + ' static ,
932941 R :: Params : DeserializeOwned + ' static ,
933942 R :: Result : Serialize + ' static ,
934943{
@@ -984,10 +993,14 @@ fn update_file_notifications_on_threadpool(
984993 }
985994}
986995
987- pub fn show_message ( typ : req:: MessageType , message : impl Into < String > , sender : & Sender < Message > ) {
996+ pub fn show_message (
997+ typ : lsp_types:: MessageType ,
998+ message : impl Into < String > ,
999+ sender : & Sender < Message > ,
1000+ ) {
9881001 let message = message. into ( ) ;
989- let params = req :: ShowMessageParams { typ, message } ;
990- let not = notification_new :: < req :: ShowMessage > ( params) ;
1002+ let params = lsp_types :: ShowMessageParams { typ, message } ;
1003+ let not = notification_new :: < lsp_types :: notification :: ShowMessage > ( params) ;
9911004 sender. send ( not. into ( ) ) . unwrap ( ) ;
9921005}
9931006
0 commit comments