@@ -23,23 +23,21 @@ impl Store {
2323 pub fn handle_did_open (
2424 & mut self ,
2525 db : & dyn Database ,
26- params : DidOpenTextDocumentParams ,
27- ) -> Result < ( ) > {
26+ params : & DidOpenTextDocumentParams ,
27+ ) {
2828 let uri = params. text_document . uri . to_string ( ) ;
2929 let version = params. text_document . version ;
3030
31- let document = TextDocument :: from_did_open_params ( db, & params) ;
31+ let document = TextDocument :: from_did_open_params ( db, params) ;
3232
3333 self . add_document ( document, uri. clone ( ) ) ;
3434 self . versions . insert ( uri, version) ;
35-
36- Ok ( ( ) )
3735 }
3836
3937 pub fn handle_did_change (
4038 & mut self ,
4139 db : & dyn Database ,
42- params : DidChangeTextDocumentParams ,
40+ params : & DidChangeTextDocumentParams ,
4341 ) -> Result < ( ) > {
4442 let uri = params. text_document . uri . as_str ( ) . to_string ( ) ;
4543 let version = params. text_document . version ;
@@ -56,10 +54,8 @@ impl Store {
5654 Ok ( ( ) )
5755 }
5856
59- pub fn handle_did_close ( & mut self , params : DidCloseTextDocumentParams ) -> Result < ( ) > {
57+ pub fn handle_did_close ( & mut self , params : & DidCloseTextDocumentParams ) {
6058 self . remove_document ( params. text_document . uri . as_str ( ) ) ;
61-
62- Ok ( ( ) )
6359 }
6460
6561 fn add_document ( & mut self , document : TextDocument , uri : String ) {
@@ -173,7 +169,7 @@ pub struct TextDocument {
173169impl TextDocument {
174170 pub fn from_did_open_params ( db : & dyn Database , params : & DidOpenTextDocumentParams ) -> Self {
175171 let uri = params. text_document . uri . to_string ( ) ;
176- let contents = params. text_document . text . clone ( ) ;
172+ let contents = params. text_document . text . clone ( ) ; // Need to clone here since we don't own params
177173 let version = params. text_document . version ;
178174 let language_id = LanguageId :: from ( params. text_document . language_id . as_str ( ) ) ;
179175
@@ -182,7 +178,7 @@ impl TextDocument {
182178 }
183179
184180 pub fn with_changes (
185- & self ,
181+ self ,
186182 db : & dyn Database ,
187183 changes : & [ TextDocumentContentChangeEvent ] ,
188184 new_version : i32 ,
@@ -209,7 +205,7 @@ impl TextDocument {
209205 }
210206 } else {
211207 // Full document update
212- new_contents = change. text . clone ( ) ;
208+ new_contents. clone_from ( & change. text ) ;
213209 }
214210 }
215211
@@ -225,20 +221,20 @@ impl TextDocument {
225221 }
226222
227223 #[ allow( dead_code) ]
228- pub fn get_text ( & self , db : & dyn Database ) -> String {
224+ pub fn get_text ( self , db : & dyn Database ) -> String {
229225 self . contents ( db) . to_string ( )
230226 }
231227
232228 #[ allow( dead_code) ]
233- pub fn get_text_range ( & self , db : & dyn Database , range : Range ) -> Option < String > {
229+ pub fn get_text_range ( self , db : & dyn Database , range : Range ) -> Option < String > {
234230 let index = self . index ( db) ;
235231 let start = index. offset ( range. start ) ? as usize ;
236232 let end = index. offset ( range. end ) ? as usize ;
237233 let contents = self . contents ( db) ;
238234 Some ( contents[ start..end] . to_string ( ) )
239235 }
240236
241- pub fn get_line ( & self , db : & dyn Database , line : u32 ) -> Option < String > {
237+ pub fn get_line ( self , db : & dyn Database , line : u32 ) -> Option < String > {
242238 let index = self . index ( db) ;
243239 let start = index. line_starts . get ( line as usize ) ?;
244240 let end = index
@@ -252,12 +248,12 @@ impl TextDocument {
252248 }
253249
254250 #[ allow( dead_code) ]
255- pub fn line_count ( & self , db : & dyn Database ) -> usize {
251+ pub fn line_count ( self , db : & dyn Database ) -> usize {
256252 self . index ( db) . line_starts . len ( )
257253 }
258254
259255 pub fn get_template_tag_context (
260- & self ,
256+ self ,
261257 db : & dyn Database ,
262258 position : Position ,
263259 ) -> Option < TemplateTagContext > {
@@ -300,7 +296,7 @@ impl LineIndex {
300296 let mut pos = 0 ;
301297
302298 for c in text. chars ( ) {
303- pos += c. len_utf8 ( ) as u32 ;
299+ pos += u32 :: try_from ( c. len_utf8 ( ) ) . unwrap_or ( 0 ) ;
304300 if c == '\n' {
305301 line_starts. push ( pos) ;
306302 }
@@ -328,7 +324,7 @@ impl LineIndex {
328324 let line_start = self . line_starts [ line] ;
329325 let character = offset - line_start;
330326
331- Position :: new ( line as u32 , character)
327+ Position :: new ( u32:: try_from ( line ) . unwrap_or ( 0 ) , character)
332328 }
333329}
334330
0 commit comments