@@ -104,7 +104,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
104
104
105
105
if project_roots. is_empty ( ) && config. notifications . cargo_toml_not_found {
106
106
show_message (
107
- req :: MessageType :: Error ,
107
+ lsp_types :: MessageType :: Error ,
108
108
format ! (
109
109
"rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}" ,
110
110
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)
124
124
. map_err ( |err| {
125
125
log:: error!( "failed to load workspace: {:#}" , err) ;
126
126
show_message (
127
- req :: MessageType :: Error ,
127
+ lsp_types :: MessageType :: Error ,
128
128
format ! ( "rust-analyzer failed to load workspace: {:#}" , err) ,
129
129
& connection. sender ,
130
130
) ;
@@ -142,23 +142,25 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
142
142
. collect :: < std:: result:: Result < Vec < _ > , _ > > ( ) ?;
143
143
144
144
if let FilesWatcher :: Client = config. files . watcher {
145
- let registration_options = req :: DidChangeWatchedFilesRegistrationOptions {
145
+ let registration_options = lsp_types :: DidChangeWatchedFilesRegistrationOptions {
146
146
watchers : workspaces
147
147
. iter ( )
148
148
. flat_map ( ProjectWorkspace :: to_roots)
149
149
. filter ( PackageRoot :: is_member)
150
150
. 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 } )
152
152
. collect ( ) ,
153
153
} ;
154
- let registration = req :: Registration {
154
+ let registration = lsp_types :: Registration {
155
155
id : "file-watcher" . to_string ( ) ,
156
156
method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
157
157
register_options : Some ( serde_json:: to_value ( registration_options) . unwrap ( ) ) ,
158
158
} ;
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
+ ) ;
162
164
connection. sender . send ( request. into ( ) ) . unwrap ( ) ;
163
165
}
164
166
@@ -258,14 +260,14 @@ impl fmt::Debug for Event {
258
260
259
261
match self {
260
262
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)
263
265
{
264
266
return debug_verbose_not ( not, f) ;
265
267
}
266
268
}
267
269
Event :: Task ( Task :: Notify ( not) ) => {
268
- if notification_is :: < req :: PublishDiagnostics > ( not) {
270
+ if notification_is :: < lsp_types :: notification :: PublishDiagnostics > ( not) {
269
271
return debug_verbose_not ( not, f) ;
270
272
}
271
273
}
@@ -450,7 +452,7 @@ fn loop_turn(
450
452
log:: error!( "overly long loop turn: {:?}" , loop_duration) ;
451
453
if env:: var ( "RA_PROFILE" ) . is_ok ( ) {
452
454
show_message (
453
- req :: MessageType :: Error ,
455
+ lsp_types :: MessageType :: Error ,
454
456
format ! ( "overly long loop turn: {:?}" , loop_duration) ,
455
457
& connection. sender ,
456
458
) ;
@@ -503,7 +505,7 @@ fn on_request(
503
505
. on_sync :: < req:: CollectGarbage > ( |s, ( ) | Ok ( s. collect_garbage ( ) ) ) ?
504
506
. on_sync :: < req:: JoinLines > ( |s, p| handlers:: handle_join_lines ( s. snapshot ( ) , p) ) ?
505
507
. 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| {
507
509
handlers:: handle_selection_range ( s. snapshot ( ) , p)
508
510
} ) ?
509
511
. on_sync :: < req:: FindMatchingBrace > ( |s, p| {
@@ -512,32 +514,38 @@ fn on_request(
512
514
. on :: < req:: AnalyzerStatus > ( handlers:: handle_analyzer_status) ?
513
515
. on :: < req:: SyntaxTree > ( handlers:: handle_syntax_tree) ?
514
516
. 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) ?
521
523
. on :: < req:: ParentModule > ( handlers:: handle_parent_module) ?
522
524
. 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) ?
535
537
. 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
+ ) ?
541
549
. on :: < req:: Ssr > ( handlers:: handle_ssr) ?
542
550
. finish ( ) ;
543
551
Ok ( ( ) )
@@ -549,7 +557,7 @@ fn on_notification(
549
557
loop_state : & mut LoopState ,
550
558
not : Notification ,
551
559
) -> Result < ( ) > {
552
- let not = match notification_cast :: < req :: Cancel > ( not) {
560
+ let not = match notification_cast :: < lsp_types :: notification :: Cancel > ( not) {
553
561
Ok ( params) => {
554
562
let id: RequestId = match params. id {
555
563
NumberOrString :: Number ( id) => id. into ( ) ,
@@ -567,7 +575,7 @@ fn on_notification(
567
575
}
568
576
Err ( not) => not,
569
577
} ;
570
- let not = match notification_cast :: < req :: DidOpenTextDocument > ( not) {
578
+ let not = match notification_cast :: < lsp_types :: notification :: DidOpenTextDocument > ( not) {
571
579
Ok ( params) => {
572
580
let uri = params. text_document . uri ;
573
581
let path = uri. to_file_path ( ) . map_err ( |( ) | format ! ( "invalid uri: {}" , uri) ) ?;
@@ -580,7 +588,7 @@ fn on_notification(
580
588
}
581
589
Err ( not) => not,
582
590
} ;
583
- let not = match notification_cast :: < req :: DidChangeTextDocument > ( not) {
591
+ let not = match notification_cast :: < lsp_types :: notification :: DidChangeTextDocument > ( not) {
584
592
Ok ( params) => {
585
593
let DidChangeTextDocumentParams { text_document, content_changes } = params;
586
594
let world = state. snapshot ( ) ;
@@ -595,7 +603,7 @@ fn on_notification(
595
603
}
596
604
Err ( not) => not,
597
605
} ;
598
- let not = match notification_cast :: < req :: DidSaveTextDocument > ( not) {
606
+ let not = match notification_cast :: < lsp_types :: notification :: DidSaveTextDocument > ( not) {
599
607
Ok ( _params) => {
600
608
if let Some ( flycheck) = & state. flycheck {
601
609
flycheck. update ( ) ;
@@ -604,30 +612,30 @@ fn on_notification(
604
612
}
605
613
Err ( not) => not,
606
614
} ;
607
- let not = match notification_cast :: < req :: DidCloseTextDocument > ( not) {
615
+ let not = match notification_cast :: < lsp_types :: notification :: DidCloseTextDocument > ( not) {
608
616
Ok ( params) => {
609
617
let uri = params. text_document . uri ;
610
618
let path = uri. to_file_path ( ) . map_err ( |( ) | format ! ( "invalid uri: {}" , uri) ) ?;
611
619
if let Some ( file_id) = state. vfs . write ( ) . remove_file_overlay ( path. as_path ( ) ) {
612
620
loop_state. subscriptions . remove_sub ( FileId ( file_id. 0 ) ) ;
613
621
}
614
622
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) ;
617
625
msg_sender. send ( not. into ( ) ) . unwrap ( ) ;
618
626
return Ok ( ( ) ) ;
619
627
}
620
628
Err ( not) => not,
621
629
} ;
622
- let not = match notification_cast :: < req :: DidChangeConfiguration > ( not) {
630
+ let not = match notification_cast :: < lsp_types :: notification :: DidChangeConfiguration > ( not) {
623
631
Ok ( _) => {
624
632
// As stated in https://github.com/microsoft/language-server-protocol/issues/676,
625
633
// this notification's parameters should be ignored and the actual config queried separately.
626
634
let request_id = loop_state. next_request_id ( ) ;
627
- let request = request_new :: < req :: WorkspaceConfiguration > (
635
+ let request = request_new :: < lsp_types :: request :: WorkspaceConfiguration > (
628
636
request_id. clone ( ) ,
629
- req :: ConfigurationParams {
630
- items : vec ! [ req :: ConfigurationItem {
637
+ lsp_types :: ConfigurationParams {
638
+ items : vec ! [ lsp_types :: ConfigurationItem {
631
639
scope_uri: None ,
632
640
section: Some ( "rust-analyzer" . to_string( ) ) ,
633
641
} ] ,
@@ -640,7 +648,7 @@ fn on_notification(
640
648
}
641
649
Err ( not) => not,
642
650
} ;
643
- let not = match notification_cast :: < req :: DidChangeWatchedFiles > ( not) {
651
+ let not = match notification_cast :: < lsp_types :: notification :: DidChangeWatchedFiles > ( not) {
644
652
Ok ( params) => {
645
653
let mut vfs = state. vfs . write ( ) ;
646
654
for change in params. changes {
@@ -742,11 +750,11 @@ fn on_check_task(
742
750
}
743
751
744
752
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) ,
748
756
} ;
749
- let not = notification_new :: < req :: Progress > ( params) ;
757
+ let not = notification_new :: < lsp_types :: notification :: Progress > ( params) ;
750
758
task_sender. send ( Task :: Notify ( not) ) . unwrap ( ) ;
751
759
}
752
760
} ;
@@ -768,8 +776,8 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender<Message>, state:
768
776
} ;
769
777
770
778
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) ;
773
781
msg_sender. send ( not. into ( ) ) . unwrap ( ) ;
774
782
}
775
783
}
@@ -782,10 +790,10 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
782
790
783
791
match ( prev, loop_state. workspace_loaded ) {
784
792
( None , false ) => {
785
- let work_done_progress_create = request_new :: < req :: WorkDoneProgressCreate > (
793
+ let work_done_progress_create = request_new :: < lsp_types :: request :: WorkDoneProgressCreate > (
786
794
loop_state. next_request_id ( ) ,
787
795
WorkDoneProgressCreateParams {
788
- token : req :: ProgressToken :: String ( "rustAnalyzer/startup" . into ( ) ) ,
796
+ token : lsp_types :: ProgressToken :: String ( "rustAnalyzer/startup" . into ( ) ) ,
789
797
} ,
790
798
) ;
791
799
sender. send ( work_done_progress_create. into ( ) ) . unwrap ( ) ;
@@ -817,10 +825,11 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
817
825
}
818
826
819
827
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
+ } ) ;
824
833
sender. send ( notif. into ( ) ) . unwrap ( ) ;
825
834
}
826
835
}
@@ -842,7 +851,7 @@ impl<'a> PoolDispatcher<'a> {
842
851
f : fn ( & mut WorldState , R :: Params ) -> Result < R :: Result > ,
843
852
) -> Result < & mut Self >
844
853
where
845
- R : req :: Request + ' static ,
854
+ R : lsp_types :: request :: Request + ' static ,
846
855
R :: Params : DeserializeOwned + panic:: UnwindSafe + ' static ,
847
856
R :: Result : Serialize + ' static ,
848
857
{
@@ -865,7 +874,7 @@ impl<'a> PoolDispatcher<'a> {
865
874
/// Dispatches the request onto thread pool
866
875
fn on < R > ( & mut self , f : fn ( WorldSnapshot , R :: Params ) -> Result < R :: Result > ) -> Result < & mut Self >
867
876
where
868
- R : req :: Request + ' static ,
877
+ R : lsp_types :: request :: Request + ' static ,
869
878
R :: Params : DeserializeOwned + Send + ' static ,
870
879
R :: Result : Serialize + ' static ,
871
880
{
@@ -891,7 +900,7 @@ impl<'a> PoolDispatcher<'a> {
891
900
892
901
fn parse < R > ( & mut self ) -> Option < ( RequestId , R :: Params ) >
893
902
where
894
- R : req :: Request + ' static ,
903
+ R : lsp_types :: request :: Request + ' static ,
895
904
R :: Params : DeserializeOwned + ' static ,
896
905
{
897
906
let req = self . req . take ( ) ?;
@@ -928,7 +937,7 @@ impl<'a> PoolDispatcher<'a> {
928
937
929
938
fn result_to_task < R > ( id : RequestId , result : Result < R :: Result > ) -> Task
930
939
where
931
- R : req :: Request + ' static ,
940
+ R : lsp_types :: request :: Request + ' static ,
932
941
R :: Params : DeserializeOwned + ' static ,
933
942
R :: Result : Serialize + ' static ,
934
943
{
@@ -984,10 +993,14 @@ fn update_file_notifications_on_threadpool(
984
993
}
985
994
}
986
995
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
+ ) {
988
1001
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) ;
991
1004
sender. send ( not. into ( ) ) . unwrap ( ) ;
992
1005
}
993
1006
0 commit comments