@@ -7,6 +7,7 @@ use codebook::parser::TextRange;
7
7
use codebook:: parser:: WordLocation ;
8
8
use codebook:: parser:: get_word_from_string;
9
9
use codebook:: queries:: LanguageType ;
10
+ use log:: LevelFilter ;
10
11
use log:: error;
11
12
use serde_json:: Value ;
12
13
use tokio:: task;
@@ -19,6 +20,7 @@ use codebook_config::CodebookConfig;
19
20
use log:: { debug, info} ;
20
21
21
22
use crate :: file_cache:: TextDocumentCache ;
23
+ use crate :: lsp_logger;
22
24
23
25
const SOURCE_NAME : & str = "Codebook" ;
24
26
@@ -58,8 +60,24 @@ impl From<CodebookCommand> for String {
58
60
59
61
#[ tower_lsp:: async_trait]
60
62
impl LanguageServer for Backend {
61
- async fn initialize ( & self , _: InitializeParams ) -> RpcResult < InitializeResult > {
62
- info ! ( "Server initialized" ) ;
63
+ async fn initialize ( & self , params : InitializeParams ) -> RpcResult < InitializeResult > {
64
+ // Get log level from initialization options
65
+ let log_level = params
66
+ . initialization_options
67
+ . as_ref ( )
68
+ . and_then ( |options| options. get ( "logLevel" ) )
69
+ . and_then ( |level| level. as_str ( ) )
70
+ . map ( |level| {
71
+ if level == "debug" {
72
+ LevelFilter :: Debug
73
+ } else {
74
+ LevelFilter :: Info
75
+ }
76
+ } )
77
+ . unwrap_or ( LevelFilter :: Info ) ;
78
+ lsp_logger:: LspLogger :: init ( self . client . clone ( ) , log_level)
79
+ . expect ( "Failed to initialize LSP logger" ) ;
80
+ info ! ( "LSP logger initialized with log level: {}" , log_level) ;
63
81
Ok ( InitializeResult {
64
82
capabilities : ServerCapabilities {
65
83
text_document_sync : Some ( TextDocumentSyncCapability :: Kind (
@@ -313,10 +331,10 @@ impl Backend {
313
331
should_save = true ;
314
332
}
315
333
Ok ( false ) => {
316
- log :: info!( "Word '{}' already exists in dictionary." , word) ;
334
+ info ! ( "Word '{}' already exists in dictionary." , word) ;
317
335
}
318
336
Err ( e) => {
319
- log :: error!( "Failed to add word: {}" , e) ;
337
+ error ! ( "Failed to add word: {}" , e) ;
320
338
}
321
339
}
322
340
}
@@ -330,10 +348,10 @@ impl Backend {
330
348
should_save = true ;
331
349
}
332
350
Ok ( false ) => {
333
- log :: info!( "Word '{}' already exists in global dictionary." , word) ;
351
+ info ! ( "Word '{}' already exists in global dictionary." , word) ;
334
352
}
335
353
Err ( e) => {
336
- log :: error!( "Failed to add word: {}" , e) ;
354
+ error ! ( "Failed to add word: {}" , e) ;
337
355
}
338
356
}
339
357
}
@@ -379,7 +397,7 @@ impl Backend {
379
397
let did_reload = match self . config . reload ( ) {
380
398
Ok ( did_reload) => did_reload,
381
399
Err ( e) => {
382
- log :: error!( "Failed to reload config: {}" , e) ;
400
+ error ! ( "Failed to reload config: {}" , e) ;
383
401
false
384
402
}
385
403
} ;
@@ -399,7 +417,7 @@ impl Backend {
399
417
} ;
400
418
// Convert the file URI to a local file path.
401
419
let file_path = doc. uri . to_file_path ( ) . unwrap_or_default ( ) ;
402
- info ! ( "Spell-checking file: {:?}" , file_path) ;
420
+ debug ! ( "Spell-checking file: {:?}" , file_path) ;
403
421
// 1) Perform spell-check.
404
422
let lang_type = doc
405
423
. language_id
@@ -438,11 +456,11 @@ impl Backend {
438
456
} )
439
457
. collect ( ) ;
440
458
441
- debug ! ( "Diagnostics: {:?}" , diagnostics) ;
459
+ // debug!("Diagnostics: {:?}", diagnostics);
442
460
// 3) Send the diagnostics to the client.
443
461
self . client
444
462
. publish_diagnostics ( doc. uri , diagnostics, None )
445
463
. await ;
446
- debug ! ( "Published diagnostics for: {:?}" , file_path) ;
464
+ // debug!("Published diagnostics for: {:?}", file_path);
447
465
}
448
466
}
0 commit comments