2
2
use std:: { mem, ops:: Range , sync:: Arc } ;
3
3
4
4
use lsp_server:: Notification ;
5
+ use lsp_types:: request:: Request ;
5
6
6
7
use crate :: {
7
8
from_proto,
8
9
global_state:: GlobalState ,
9
10
line_index:: { LineEndings , LineIndex , PositionEncoding } ,
10
- LspError ,
11
+ lsp_ext , LspError ,
11
12
} ;
12
13
13
14
pub ( crate ) fn invalid_params_error ( message : String ) -> LspError {
@@ -46,20 +47,47 @@ impl GlobalState {
46
47
/// If `additional_info` is [`Some`], appends a note to the notification telling to check the logs.
47
48
/// This will always log `message` + `additional_info` to the server's error log.
48
49
pub ( crate ) fn show_and_log_error ( & mut self , message : String , additional_info : Option < String > ) {
49
- let mut message = message;
50
50
match additional_info {
51
51
Some ( additional_info) => {
52
- tracing:: error!( "{}\n \n {}" , & message, & additional_info) ;
53
- if tracing:: enabled!( tracing:: Level :: ERROR ) {
54
- message. push_str ( "\n \n Check the server logs for additional info." ) ;
52
+ tracing:: error!( "{}:\n {}" , & message, & additional_info) ;
53
+ match self . config . open_server_logs ( ) && tracing:: enabled!( tracing:: Level :: ERROR ) {
54
+ true => self . send_request :: < lsp_types:: request:: ShowMessageRequest > (
55
+ lsp_types:: ShowMessageRequestParams {
56
+ typ : lsp_types:: MessageType :: ERROR ,
57
+ message,
58
+ actions : Some ( vec ! [ lsp_types:: MessageActionItem {
59
+ title: "Open server logs" . to_owned( ) ,
60
+ properties: Default :: default ( ) ,
61
+ } ] ) ,
62
+ } ,
63
+ |this, resp| {
64
+ let lsp_server:: Response { error : None , result : Some ( result) , .. } = resp
65
+ else { return } ;
66
+ if let Ok ( Some ( _item) ) = crate :: from_json :: <
67
+ <lsp_types:: request:: ShowMessageRequest as lsp_types:: request:: Request >:: Result ,
68
+ > (
69
+ lsp_types:: request:: ShowMessageRequest :: METHOD , & result
70
+ ) {
71
+ this. send_notification :: < lsp_ext:: OpenServerLogs > ( ( ) ) ;
72
+ }
73
+ } ,
74
+ ) ,
75
+ false => self . send_notification :: < lsp_types:: notification:: ShowMessage > (
76
+ lsp_types:: ShowMessageParams {
77
+ typ : lsp_types:: MessageType :: ERROR ,
78
+ message,
79
+ } ,
80
+ ) ,
55
81
}
56
82
}
57
- None => tracing :: error! ( "{}" , & message ) ,
58
- }
83
+ None => {
84
+ tracing :: error! ( "{}" , & message ) ;
59
85
60
- self . send_notification :: < lsp_types:: notification:: ShowMessage > (
61
- lsp_types:: ShowMessageParams { typ : lsp_types:: MessageType :: ERROR , message } ,
62
- )
86
+ self . send_notification :: < lsp_types:: notification:: ShowMessage > (
87
+ lsp_types:: ShowMessageParams { typ : lsp_types:: MessageType :: ERROR , message } ,
88
+ ) ;
89
+ }
90
+ }
63
91
}
64
92
65
93
/// rust-analyzer is resilient -- if it fails, this doesn't usually affect
@@ -77,7 +105,7 @@ impl GlobalState {
77
105
let from_source_build = option_env ! ( "POKE_RA_DEVS" ) . is_some ( ) ;
78
106
let profiling_enabled = std:: env:: var ( "RA_PROFILE" ) . is_ok ( ) ;
79
107
if from_source_build || profiling_enabled {
80
- self . show_message ( lsp_types :: MessageType :: ERROR , message )
108
+ self . show_and_log_error ( message , None ) ;
81
109
}
82
110
}
83
111
0 commit comments