@@ -764,21 +764,26 @@ impl Action for Formatting {
764
764
const METHOD : & ' static str = "textDocument/formatting" ;
765
765
}
766
766
767
- impl < ' a > BlockingRequestAction < ' a > for Formatting {
767
+ impl RequestAction for Formatting {
768
768
type Response = [ TextEdit ; 1 ] ;
769
769
770
- fn new ( _ : & ' a mut LsState ) -> Self {
770
+ fn new ( ) -> Self {
771
771
Formatting
772
772
}
773
773
774
- fn handle < O : Output > (
774
+ fn fallback_response ( & self ) -> Result < Self :: Response , ResponseError > {
775
+ Err ( ResponseError :: Message (
776
+ ErrorCode :: InternalError ,
777
+ "Reformat failed to complete successfully" . into ( ) ,
778
+ ) )
779
+ }
780
+
781
+ fn handle (
775
782
& mut self ,
776
- id : usize ,
783
+ ctx : InitActionContext ,
777
784
params : Self :: Params ,
778
- ctx : & mut ActionContext ,
779
- out : O ,
780
- ) -> Result < Self :: Response , ( ) > {
781
- reformat ( id, params. text_document , None , & params. options , ctx, out)
785
+ ) -> Result < Self :: Response , ResponseError > {
786
+ reformat ( params. text_document , None , & params. options , ctx)
782
787
}
783
788
}
784
789
@@ -790,69 +795,64 @@ impl Action for RangeFormatting {
790
795
const METHOD : & ' static str = "textDocument/rangeFormatting" ;
791
796
}
792
797
793
- impl < ' a > BlockingRequestAction < ' a > for RangeFormatting {
798
+ impl RequestAction for RangeFormatting {
794
799
type Response = [ TextEdit ; 1 ] ;
795
800
796
- fn new ( _ : & ' a mut LsState ) -> Self {
801
+ fn new ( ) -> Self {
797
802
RangeFormatting
798
803
}
799
804
800
- fn handle < O : Output > (
805
+ fn fallback_response ( & self ) -> Result < Self :: Response , ResponseError > {
806
+ Err ( ResponseError :: Message (
807
+ ErrorCode :: InternalError ,
808
+ "Reformat failed to complete successfully" . into ( ) ,
809
+ ) )
810
+ }
811
+
812
+ fn handle (
801
813
& mut self ,
802
- id : usize ,
814
+ ctx : InitActionContext ,
803
815
params : Self :: Params ,
804
- ctx : & mut ActionContext ,
805
- out : O ,
806
- ) -> Result < Self :: Response , ( ) > {
816
+ ) -> Result < Self :: Response , ResponseError > {
807
817
reformat (
808
- id,
809
818
params. text_document ,
810
819
Some ( params. range ) ,
811
820
& params. options ,
812
821
ctx,
813
- out,
814
822
)
815
823
}
816
824
}
817
825
818
- fn reformat < O : Output > (
819
- id : usize ,
826
+ fn reformat (
820
827
doc : TextDocumentIdentifier ,
821
828
selection : Option < Range > ,
822
829
opts : & FormattingOptions ,
823
- ctx : & mut ActionContext ,
824
- out : O ,
825
- ) -> Result < [ TextEdit ; 1 ] , ( ) > {
830
+ ctx : InitActionContext ,
831
+ ) -> Result < [ TextEdit ; 1 ] , ResponseError > {
826
832
trace ! (
827
- "Reformat: {} {:?} {:?} {} {}" ,
828
- id,
833
+ "Reformat: {:?} {:?} {} {}" ,
829
834
doc,
830
835
selection,
831
836
opts. tab_size,
832
837
opts. insert_spaces
833
838
) ;
834
- let ctx = ctx. inited ( ) ;
835
839
let path = parse_file_path ! ( & doc. uri, "reformat" ) ?;
836
840
837
841
let input = match ctx. vfs . load_file ( & path) {
838
842
Ok ( FileContents :: Text ( s) ) => FmtInput :: Text ( s) ,
839
843
Ok ( _) => {
840
844
debug ! ( "Reformat failed, found binary file" ) ;
841
- out. failure_message (
842
- id,
845
+ return Err ( ResponseError :: Message (
843
846
ErrorCode :: InternalError ,
844
- "Reformat failed to complete successfully" ,
845
- ) ;
846
- return Err ( ( ) ) ;
847
+ "Reformat failed to complete successfully" . into ( ) ,
848
+ ) ) ;
847
849
}
848
850
Err ( e) => {
849
851
debug ! ( "Reformat failed: {:?}" , e) ;
850
- out. failure_message (
851
- id,
852
+ return Err ( ResponseError :: Message (
852
853
ErrorCode :: InternalError ,
853
- "Reformat failed to complete successfully" ,
854
- ) ;
855
- return Err ( ( ) ) ;
854
+ "Reformat failed to complete successfully" . into ( ) ,
855
+ ) ) ;
856
856
}
857
857
} ;
858
858
@@ -900,22 +900,19 @@ fn reformat<O: Output>(
900
900
summary
901
901
) ;
902
902
903
- out. failure_message (
904
- id,
903
+ return Err ( ResponseError :: Message (
905
904
ErrorCode :: InternalError ,
906
- "Reformat failed to complete successfully" ,
907
- ) ;
908
- Err ( ( ) )
905
+ "Reformat failed to complete successfully" . into ( ) ,
906
+ ) ) ;
909
907
}
910
908
}
911
909
Err ( e) => {
912
910
debug ! ( "Reformat failed: {:?}" , e) ;
913
- out . failure_message (
914
- id ,
911
+
912
+ return Err ( ResponseError :: Message (
915
913
ErrorCode :: InternalError ,
916
- "Reformat failed to complete successfully" ,
917
- ) ;
918
- Err ( ( ) )
914
+ "Reformat failed to complete successfully" . into ( ) ,
915
+ ) ) ;
919
916
}
920
917
}
921
918
}
@@ -931,24 +928,26 @@ impl Action for ResolveCompletion {
931
928
const METHOD : & ' static str = "completionItem/resolve" ;
932
929
}
933
930
934
- impl < ' a > BlockingRequestAction < ' a > for ResolveCompletion {
931
+ impl RequestAction for ResolveCompletion {
935
932
type Response = CompletionItem ;
936
933
937
- fn new ( _ : & ' a mut LsState ) -> Self {
934
+ fn new ( ) -> Self {
938
935
ResolveCompletion
939
936
}
940
937
941
- fn handle < O : Output > (
938
+ fn fallback_response ( & self ) -> Result < Self :: Response , ResponseError > {
939
+ Err ( ResponseError :: Empty )
940
+ }
941
+
942
+ fn handle (
942
943
& mut self ,
943
- _id : usize ,
944
+ _ : InitActionContext ,
944
945
params : Self :: Params ,
945
- _ctx : & mut ActionContext ,
946
- _out : O ,
947
- ) -> Result < Self :: Response , ( ) > {
946
+ ) -> Result < Self :: Response , ResponseError > {
948
947
// currently, we safely ignore this as a pass-through since we fully handle
949
948
// textDocument/completion. In the future, we may want to use this method as a
950
949
// way to more lazily fill out completion information
951
- Ok ( params)
950
+ Ok ( params. into ( ) )
952
951
}
953
952
}
954
953
0 commit comments