@@ -3,7 +3,6 @@ use std::fs::File;
33use std:: io:: Read ;
44use std:: sync:: mpsc:: Sender ;
55
6- use erg_common:: vfs:: VFS ;
76use lsp_types:: {
87 DidChangeTextDocumentParams , FileOperationFilter , FileOperationPattern ,
98 FileOperationPatternKind , FileOperationRegistrationOptions , OneOf , Position , Range ,
@@ -14,13 +13,14 @@ use lsp_types::{
1413use serde_json:: Value ;
1514
1615use erg_common:: dict:: Dict ;
16+ use erg_common:: lsp_log;
1717use erg_common:: set:: Set ;
1818use erg_common:: shared:: Shared ;
1919use erg_common:: traits:: DequeStream ;
20+ use erg_common:: vfs:: VFS ;
2021use erg_compiler:: erg_parser:: lex:: Lexer ;
2122use erg_compiler:: erg_parser:: token:: { Token , TokenCategory , TokenKind , TokenStream } ;
2223
23- use crate :: _log;
2424use crate :: server:: { ELSResult , RedirectableStdout } ;
2525use crate :: util:: { self , NormalizedUrl } ;
2626
@@ -279,7 +279,13 @@ impl FileCache {
279279 return ;
280280 }
281281 }
282- let token_stream = Lexer :: from_str ( code. clone ( ) ) . lex ( ) . ok ( ) ;
282+ let token_stream = match Lexer :: from_str ( code. clone ( ) ) . lex ( ) {
283+ Ok ( ts) => Some ( ts) ,
284+ Err ( ( ts, es) ) => {
285+ lsp_log ! ( "failed to lex: {es}" ) ;
286+ Some ( ts)
287+ }
288+ } ;
283289 let ver = ver. unwrap_or ( {
284290 if let Some ( entry) = entry {
285291 entry. ver
@@ -308,7 +314,13 @@ impl FileCache {
308314 let start = util:: pos_to_byte_index ( & code, old. start ) ;
309315 let end = util:: pos_to_byte_index ( & code, old. end ) ;
310316 code. replace_range ( start..end, new_code) ;
311- let token_stream = Lexer :: from_str ( code. clone ( ) ) . lex ( ) . ok ( ) ;
317+ let token_stream = match Lexer :: from_str ( code. clone ( ) ) . lex ( ) {
318+ Ok ( ts) => Some ( ts) ,
319+ Err ( ( ts, es) ) => {
320+ lsp_log ! ( "failed to lex: {es}" ) ;
321+ Some ( ts)
322+ }
323+ } ;
312324 VFS . update ( uri. to_file_path ( ) . unwrap ( ) , code. clone ( ) ) ;
313325 entry. code = code;
314326 // entry.ver += 1;
@@ -341,7 +353,13 @@ impl FileCache {
341353 code. replace_range ( start..end, & change. text ) ;
342354 }
343355 VFS . update ( uri. to_file_path ( ) . unwrap ( ) , code. clone ( ) ) ;
344- let token_stream = Lexer :: from_str ( code. clone ( ) ) . lex ( ) . ok ( ) ;
356+ let token_stream = match Lexer :: from_str ( code. clone ( ) ) . lex ( ) {
357+ Ok ( ts) => Some ( ts) ,
358+ Err ( ( ts, es) ) => {
359+ lsp_log ! ( "failed to lex: {es}" ) ;
360+ Some ( ts)
361+ }
362+ } ;
345363 entry. code = code;
346364 entry. ver = params. text_document . version ;
347365 entry. token_stream = token_stream;
@@ -356,15 +374,15 @@ impl FileCache {
356374 pub fn rename_files ( & mut self , params : & RenameFilesParams ) -> ELSResult < ( ) > {
357375 for file in & params. files {
358376 let Ok ( old_uri) = NormalizedUrl :: parse ( & file. old_uri ) else {
359- _log ! ( self , "failed to parse old uri: {}" , file. old_uri) ;
377+ lsp_log ! ( "failed to parse old uri: {}" , file. old_uri) ;
360378 continue ;
361379 } ;
362380 let Ok ( new_uri) = NormalizedUrl :: parse ( & file. new_uri ) else {
363- _log ! ( self , "failed to parse new uri: {}" , file. new_uri) ;
381+ lsp_log ! ( "failed to parse new uri: {}" , file. new_uri) ;
364382 continue ;
365383 } ;
366384 let Some ( entry) = self . files . borrow_mut ( ) . remove ( & old_uri) else {
367- _log ! ( self , "failed to find old uri: {}" , file. old_uri) ;
385+ lsp_log ! ( "failed to find old uri: {}" , file. old_uri) ;
368386 continue ;
369387 } ;
370388 VFS . rename (
0 commit comments