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 PrintDebugInformationParams {
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,15 @@ 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 params: PrintDebugInformationParams =
44
+ params. arguments . into_iter ( ) . next ( ) . map_or_else (
45
+ || Ok ( PrintDebugInformationParams :: default ( ) ) ,
46
+ |value| {
47
+ serde_json:: from_value ( value) . with_failure_code ( ErrorCode :: InvalidParams )
48
+ } ,
49
+ ) ?;
50
+ let output = debug_information ( session, params. uri )
51
+ . with_failure_code ( ErrorCode :: InternalError ) ?;
38
52
notifier
39
53
. notify :: < types:: notification:: LogMessage > ( types:: LogMessageParams {
40
54
message : output. clone ( ) ,
@@ -134,23 +148,66 @@ fn apply_edit(
134
148
)
135
149
}
136
150
137
- fn debug_information ( session : & Session ) -> String {
151
+ fn debug_information ( session : & Session , uri : Option < types :: Url > ) -> crate :: Result < String > {
138
152
let executable = std:: env:: current_exe ( )
139
153
. map ( |path| format ! ( "{}" , path. display( ) ) )
140
154
. unwrap_or_else ( |_| "<unavailable>" . to_string ( ) ) ;
141
- format ! (
142
- "executable = {executable}
155
+
156
+ let mut buffer = String :: new ( ) ;
157
+
158
+ writeln ! (
159
+ buffer,
160
+ "Global:
161
+ executable = {executable}
143
162
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}" ,
163
+ position_encoding = {encoding:?}
164
+ workspace_root_folders = {workspace_folders:#?}
165
+ indexed_configuration_files = {config_files:#?}
166
+ open_documents = {open_documents}
167
+ client_capabilities = {client_capabilities:#?}
168
+ " ,
149
169
version = crate :: version( ) ,
150
170
encoding = session. encoding( ) ,
171
+ workspace_folders = session. workspace_root_folders( ) . collect:: <Vec <_>>( ) ,
172
+ config_files = session. config_file_paths( ) . collect:: <Vec <_>>( ) ,
173
+ open_documents = session. open_documents( ) ,
151
174
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
- )
175
+ ) ?;
176
+
177
+ if let Some ( uri) = uri {
178
+ let Some ( snapshot) = session. take_snapshot ( uri. clone ( ) ) else {
179
+ writeln ! ( buffer, "Unable to take a snapshot of the document at {uri}" ) ?;
180
+ return Ok ( buffer) ;
181
+ } ;
182
+
183
+ writeln ! (
184
+ buffer,
185
+ "Document:
186
+ uri = {uri}
187
+ kind = {kind}
188
+ version = {version}
189
+ client_settings = {client_settings:#?}
190
+ config_path = {config_path:?}
191
+ {settings}
192
+ " ,
193
+ uri = uri. clone( ) ,
194
+ kind = match session. key_from_url( uri) {
195
+ DocumentKey :: Notebook ( _) => "Notebook" ,
196
+ DocumentKey :: NotebookCell ( _) => "NotebookCell" ,
197
+ DocumentKey :: Text ( _) => "Text" ,
198
+ } ,
199
+ version = snapshot. query( ) . version( ) ,
200
+ client_settings = snapshot. client_settings( ) ,
201
+ config_path = snapshot. query( ) . settings( ) . path( ) ,
202
+ settings = snapshot. query( ) . settings( ) ,
203
+ ) ?;
204
+ } else {
205
+ writeln ! (
206
+ buffer,
207
+ "global_client_settings = {:#?}" ,
208
+ session. global_client_settings( )
209
+ ) ?;
210
+ }
211
+
212
+ Ok ( buffer)
156
213
}
0 commit comments