22use std:: { mem, ops:: Range , sync:: Arc } ;
33
44use lsp_server:: Notification ;
5+ use lsp_types:: request:: Request ;
56
67use crate :: {
78 from_proto,
89 global_state:: GlobalState ,
910 line_index:: { LineEndings , LineIndex , PositionEncoding } ,
10- LspError ,
11+ lsp_ext , LspError ,
1112} ;
1213
1314pub ( crate ) fn invalid_params_error ( message : String ) -> LspError {
@@ -46,20 +47,47 @@ impl GlobalState {
4647 /// If `additional_info` is [`Some`], appends a note to the notification telling to check the logs.
4748 /// This will always log `message` + `additional_info` to the server's error log.
4849 pub ( crate ) fn show_and_log_error ( & mut self , message : String , additional_info : Option < String > ) {
49- let mut message = message;
5050 match additional_info {
5151 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+ ) ,
5581 }
5682 }
57- None => tracing :: error! ( "{}" , & message ) ,
58- }
83+ None => {
84+ tracing :: error! ( "{}" , & message ) ;
5985
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+ }
6391 }
6492
6593 /// rust-analyzer is resilient -- if it fails, this doesn't usually affect
@@ -77,7 +105,7 @@ impl GlobalState {
77105 let from_source_build = option_env ! ( "POKE_RA_DEVS" ) . is_some ( ) ;
78106 let profiling_enabled = std:: env:: var ( "RA_PROFILE" ) . is_ok ( ) ;
79107 if from_source_build || profiling_enabled {
80- self . show_message ( lsp_types :: MessageType :: ERROR , message )
108+ self . show_and_log_error ( message , None ) ;
81109 }
82110 }
83111
0 commit comments