1
+ use std:: fmt:: Write ;
1
2
use std:: str:: FromStr ;
2
3
3
4
use crate :: edit:: WorkspaceEditTracker ;
4
5
use crate :: server:: api:: LSPResult ;
5
6
use crate :: server:: schedule:: Task ;
6
7
use crate :: server:: { client, SupportedCommand } ;
7
8
use crate :: session:: Session ;
8
- use crate :: DIAGNOSTIC_NAME ;
9
9
use crate :: { edit:: DocumentVersion , server} ;
10
+ use crate :: { DocumentKey , DIAGNOSTIC_NAME } ;
10
11
use lsp_server:: ErrorCode ;
11
12
use lsp_types:: { self as types, request as req} ;
12
13
use serde:: Deserialize ;
@@ -19,6 +20,11 @@ struct Argument {
19
20
version : DocumentVersion ,
20
21
}
21
22
23
+ #[ derive( Default , Deserialize ) ]
24
+ struct DebugCommandArgument {
25
+ uri : Option < types:: Url > ,
26
+ }
27
+
22
28
impl super :: RequestHandler for ExecuteCommand {
23
29
type RequestType = req:: ExecuteCommand ;
24
30
}
@@ -34,7 +40,12 @@ impl super::SyncRequestHandler for ExecuteCommand {
34
40
. with_failure_code ( ErrorCode :: InvalidParams ) ?;
35
41
36
42
if command == SupportedCommand :: Debug {
37
- let output = debug_information ( session) ;
43
+ let argument: DebugCommandArgument = params. arguments . into_iter ( ) . next ( ) . map_or_else (
44
+ || Ok ( DebugCommandArgument :: default ( ) ) ,
45
+ |value| serde_json:: from_value ( value) . with_failure_code ( ErrorCode :: InvalidParams ) ,
46
+ ) ?;
47
+ let output = debug_information ( session, argument. uri )
48
+ . with_failure_code ( ErrorCode :: InternalError ) ?;
38
49
notifier
39
50
. notify :: < types:: notification:: LogMessage > ( types:: LogMessageParams {
40
51
message : output. clone ( ) ,
@@ -134,23 +145,66 @@ fn apply_edit(
134
145
)
135
146
}
136
147
137
- fn debug_information ( session : & Session ) -> String {
148
+ fn debug_information ( session : & Session , uri : Option < types :: Url > ) -> crate :: Result < String > {
138
149
let executable = std:: env:: current_exe ( )
139
150
. map ( |path| format ! ( "{}" , path. display( ) ) )
140
151
. unwrap_or_else ( |_| "<unavailable>" . to_string ( ) ) ;
141
- format ! (
142
- "executable = {executable}
152
+
153
+ let mut buffer = String :: new ( ) ;
154
+
155
+ writeln ! (
156
+ buffer,
157
+ "Global:
158
+ executable = {executable}
143
159
version = {version}
144
- encoding = {encoding:?}
145
- open_document_count = {doc_count}
146
- active_workspace_count = {workspace_count}
147
- configuration_files = {config_files:?}
148
- {client_capabilities}" ,
160
+ position_encoding = {encoding:?}
161
+ workspace_root_folders = {workspace_folders:#?}
162
+ indexed_configuration_files = {config_files:#?}
163
+ open_documents = {open_documents}
164
+ client_capabilities = {client_capabilities:#?}
165
+ " ,
149
166
version = crate :: version( ) ,
150
167
encoding = session. encoding( ) ,
168
+ workspace_folders = session. workspace_root_folders( ) . collect:: <Vec <_>>( ) ,
169
+ config_files = session. config_file_paths( ) . collect:: <Vec <_>>( ) ,
170
+ open_documents = session. open_documents( ) ,
151
171
client_capabilities = session. resolved_client_capabilities( ) ,
152
- doc_count = session. num_documents( ) ,
153
- workspace_count = session. num_workspaces( ) ,
154
- config_files = session. list_config_files( )
155
- )
172
+ ) ?;
173
+
174
+ if let Some ( uri) = uri {
175
+ let Some ( snapshot) = session. take_snapshot ( uri. clone ( ) ) else {
176
+ writeln ! ( buffer, "Unable to take a snapshot of the document at {uri}" ) ?;
177
+ return Ok ( buffer) ;
178
+ } ;
179
+
180
+ writeln ! (
181
+ buffer,
182
+ "Document:
183
+ uri = {uri}
184
+ kind = {kind}
185
+ version = {version}
186
+ client_settings = {client_settings:#?}
187
+ config_path = {config_path:?}
188
+ {settings}
189
+ " ,
190
+ uri = uri. clone( ) ,
191
+ kind = match session. key_from_url( uri) {
192
+ DocumentKey :: Notebook ( _) => "Notebook" ,
193
+ DocumentKey :: NotebookCell ( _) => "NotebookCell" ,
194
+ DocumentKey :: Text ( _) => "Text" ,
195
+ } ,
196
+ version = snapshot. query( ) . version( ) ,
197
+ client_settings = snapshot. client_settings( ) ,
198
+ config_path = snapshot. query( ) . settings( ) . path( ) ,
199
+ settings = snapshot. query( ) . settings( ) ,
200
+ ) ?;
201
+ } else {
202
+ writeln ! (
203
+ buffer,
204
+ "global_client_settings = {:#?}" ,
205
+ session. global_client_settings( )
206
+ ) ?;
207
+ }
208
+
209
+ Ok ( buffer)
156
210
}
0 commit comments