1+ use crate :: adapters:: from_lsp:: text_range;
12use crate :: adapters:: line_index:: LineIndex ;
2- use crate :: adapters:: { PositionEncoding , from_lsp , to_lsp} ;
3+ use crate :: adapters:: { PositionEncoding , to_lsp} ;
34use anyhow:: { Context , Result , ensure} ;
45use pgt_console:: MarkupBuf ;
56use pgt_console:: fmt:: Termcolor ;
@@ -10,8 +11,8 @@ use pgt_text_size::{TextRange, TextSize};
1011use std:: any:: Any ;
1112use std:: borrow:: Cow ;
1213use std:: fmt:: { Debug , Display } ;
13- use std:: io;
1414use std:: ops:: { Add , Range } ;
15+ use std:: { io, mem} ;
1516use tower_lsp:: jsonrpc:: Error as LspError ;
1617use tower_lsp:: lsp_types;
1718use tower_lsp:: lsp_types:: { self as lsp, CodeDescription , Url } ;
@@ -183,7 +184,7 @@ pub(crate) fn panic_to_lsp_error(err: Box<dyn Any + Send>) -> LspError {
183184pub ( crate ) fn apply_document_changes (
184185 position_encoding : PositionEncoding ,
185186 current_content : String ,
186- content_changes : & [ lsp_types:: TextDocumentContentChangeEvent ] ,
187+ mut content_changes : Vec < lsp_types:: TextDocumentContentChangeEvent > ,
187188) -> String {
188189 // Skip to the last full document change, as it invalidates all previous changes anyways.
189190 let mut start = content_changes
@@ -192,12 +193,12 @@ pub(crate) fn apply_document_changes(
192193 . position ( |change| change. range . is_none ( ) )
193194 . map_or ( 0 , |idx| content_changes. len ( ) - idx - 1 ) ;
194195
195- let mut text: String = match content_changes. get ( start) {
196+ let mut text: String = match content_changes. get_mut ( start) {
196197 // peek at the first content change as an optimization
197198 Some ( lsp_types:: TextDocumentContentChangeEvent {
198199 range : None , text, ..
199200 } ) => {
200- let text = text . clone ( ) ;
201+ let text = mem :: take ( text ) ;
201202 start += 1 ;
202203
203204 // The only change is a full document update
@@ -225,12 +226,11 @@ pub(crate) fn apply_document_changes(
225226 line_index = LineIndex :: new ( & text) ;
226227 }
227228 index_valid = range. start . line ;
228- if let Ok ( range) = from_lsp :: text_range ( & line_index, range, position_encoding) {
229+ if let Ok ( range) = text_range ( & line_index, range, position_encoding) {
229230 text. replace_range ( Range :: < usize > :: from ( range) , & change. text ) ;
230231 }
231232 }
232233 }
233-
234234 text
235235}
236236
0 commit comments