@@ -15,10 +15,11 @@ use lsp_types::{
1515 DocumentSymbol , FoldingRange , FoldingRangeParams , Hover , HoverContents , Location ,
1616 MarkupContent , MarkupKind , Position , PrepareRenameResponse , Range , RenameParams ,
1717 SemanticTokensParams , SemanticTokensRangeParams , SemanticTokensRangeResult ,
18- SemanticTokensResult , SymbolInformation , TextDocumentIdentifier , TextEdit , Url , WorkspaceEdit ,
18+ SemanticTokensResult , SymbolInformation , TextDocumentIdentifier , Url , WorkspaceEdit ,
1919} ;
2020use ra_ide:: {
2121 Assist , FileId , FilePosition , FileRange , Query , RangeInfo , Runnable , RunnableKind , SearchScope ,
22+ TextEdit ,
2223} ;
2324use ra_prof:: profile;
2425use ra_project_model:: TargetKind ;
@@ -149,11 +150,24 @@ pub fn handle_find_matching_brace(
149150pub fn handle_join_lines (
150151 world : WorldSnapshot ,
151152 params : lsp_ext:: JoinLinesParams ,
152- ) -> Result < lsp_ext :: SourceChange > {
153+ ) -> Result < Vec < lsp_types :: TextEdit > > {
153154 let _p = profile ( "handle_join_lines" ) ;
154- let frange = from_proto:: file_range ( & world, params. text_document , params. range ) ?;
155- let source_change = world. analysis ( ) . join_lines ( frange) ?;
156- to_proto:: source_change ( & world, source_change)
155+ let file_id = from_proto:: file_id ( & world, & params. text_document . uri ) ?;
156+ let line_index = world. analysis ( ) . file_line_index ( file_id) ?;
157+ let line_endings = world. file_line_endings ( file_id) ;
158+ let mut res = TextEdit :: default ( ) ;
159+ for range in params. ranges {
160+ let range = from_proto:: text_range ( & line_index, range) ;
161+ let edit = world. analysis ( ) . join_lines ( FileRange { file_id, range } ) ?;
162+ match res. union ( edit) {
163+ Ok ( ( ) ) => ( ) ,
164+ Err ( _edit) => {
165+ // just ignore overlapping edits
166+ }
167+ }
168+ }
169+ let res = to_proto:: text_edit_vec ( & line_index, line_endings, res) ;
170+ Ok ( res)
157171}
158172
159173pub fn handle_on_enter (
@@ -172,7 +186,7 @@ pub fn handle_on_enter(
172186pub fn handle_on_type_formatting (
173187 world : WorldSnapshot ,
174188 params : lsp_types:: DocumentOnTypeFormattingParams ,
175- ) -> Result < Option < Vec < TextEdit > > > {
189+ ) -> Result < Option < Vec < lsp_types :: TextEdit > > > {
176190 let _p = profile ( "handle_on_type_formatting" ) ;
177191 let mut position = from_proto:: file_position ( & world, params. text_document_position ) ?;
178192 let line_index = world. analysis ( ) . file_line_index ( position. file_id ) ?;
@@ -618,7 +632,7 @@ pub fn handle_references(
618632pub fn handle_formatting (
619633 world : WorldSnapshot ,
620634 params : DocumentFormattingParams ,
621- ) -> Result < Option < Vec < TextEdit > > > {
635+ ) -> Result < Option < Vec < lsp_types :: TextEdit > > > {
622636 let _p = profile ( "handle_formatting" ) ;
623637 let file_id = from_proto:: file_id ( & world, & params. text_document . uri ) ?;
624638 let file = world. analysis ( ) . file_text ( file_id) ?;
@@ -685,7 +699,7 @@ pub fn handle_formatting(
685699 }
686700 }
687701
688- Ok ( Some ( vec ! [ TextEdit {
702+ Ok ( Some ( vec ! [ lsp_types :: TextEdit {
689703 range: Range :: new( Position :: new( 0 , 0 ) , end_position) ,
690704 new_text: captured_stdout,
691705 } ] ) )
0 commit comments