aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/lib.rs6
-rw-r--r--crates/ra_ide_api/src/status.rs15
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs1
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs4
-rw-r--r--crates/ra_lsp_server/src/req.rs8
-rw-r--r--crates/ra_lsp_server/src/server_world.rs15
-rw-r--r--editors/code/package.json4
-rw-r--r--editors/code/src/commands/analyzer_status.ts12
-rw-r--r--editors/code/src/commands/index.ts2
-rw-r--r--editors/code/src/extension.ts1
10 files changed, 68 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index a09a8f926..3c53e75ac 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -15,6 +15,7 @@ pub mod mock_analysis;
15mod symbol_index; 15mod symbol_index;
16mod navigation_target; 16mod navigation_target;
17 17
18mod status;
18mod completion; 19mod completion;
19mod runnables; 20mod runnables;
20mod goto_definition; 21mod goto_definition;
@@ -293,6 +294,11 @@ pub struct Analysis {
293} 294}
294 295
295impl Analysis { 296impl Analysis {
297 /// Debug info about the current state of the analysis
298 pub fn status(&self) -> String {
299 status::status(&*self.db)
300 }
301
296 /// Gets the text of the source file. 302 /// Gets the text of the source file.
297 pub fn file_text(&self, file_id: FileId) -> Arc<String> { 303 pub fn file_text(&self, file_id: FileId) -> Arc<String> {
298 self.db.file_text(file_id) 304 self.db.file_text(file_id)
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
new file mode 100644
index 000000000..d3e04be23
--- /dev/null
+++ b/crates/ra_ide_api/src/status.rs
@@ -0,0 +1,15 @@
1use ra_db::{
2 LocationIntener, SourceFileQuery,
3 salsa::{Database, debug::DebugQueryTable},
4};
5
6use crate::db::RootDatabase;
7
8pub(crate) fn status(db: &RootDatabase) -> String {
9 let n_parsed_files = db.query(SourceFileQuery).keys::<Vec<_>>().len();
10 let n_defs = {
11 let interner: &LocationIntener<hir::DefLoc, hir::DefId> = db.as_ref();
12 interner.len()
13 };
14 format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs)
15}
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index fa07b1942..f51576521 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -285,6 +285,7 @@ fn on_request(
285 sender, 285 sender,
286 }; 286 };
287 let req = pool_dispatcher 287 let req = pool_dispatcher
288 .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)?
288 .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? 289 .on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
289 .on::<req::ExtendSelection>(handlers::handle_extend_selection)? 290 .on::<req::ExtendSelection>(handlers::handle_extend_selection)?
290 .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? 291 .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)?
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 497f819be..d84f762f4 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -23,6 +23,10 @@ use crate::{
23 LspError, Result, 23 LspError, Result,
24}; 24};
25 25
26pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> {
27 Ok(world.status())
28}
29
26pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> { 30pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> {
27 let id = params.text_document.try_conv_with(&world)?; 31 let id = params.text_document.try_conv_with(&world)?;
28 let res = world.analysis().syntax_tree(id); 32 let res = world.analysis().syntax_tree(id);
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index 156cf9641..ec6b6d905 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -11,6 +11,14 @@ pub use lsp_types::{
11 TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, 11 TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams,
12}; 12};
13 13
14pub enum AnalyzerStatus {}
15
16impl Request for AnalyzerStatus {
17 type Params = ();
18 type Result = String;
19 const METHOD: &'static str = "ra/analyzerStatus";
20}
21
14pub enum SyntaxTree {} 22pub enum SyntaxTree {}
15 23
16impl Request for SyntaxTree { 24impl Request for SyntaxTree {
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index c24ded9f9..5cb97b29b 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -264,4 +264,19 @@ impl ServerWorld {
264 .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; 264 .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
265 Ok(url) 265 Ok(url)
266 } 266 }
267
268 pub fn status(&self) -> String {
269 let mut res = String::new();
270 if self.workspaces.is_empty() {
271 res.push_str("no workspaces\n")
272 } else {
273 res.push_str("workspaces:\n");
274 for w in self.workspaces.iter() {
275 res += &format!("{} packages loaded\n", w.cargo.packages().count());
276 }
277 }
278 res.push_str("\nanalysis:\n");
279 res.push_str(&self.analysis.status());
280 res
281 }
267} 282}
diff --git a/editors/code/package.json b/editors/code/package.json
index 9433bd3d2..3e07032c7 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -94,6 +94,10 @@
94 { 94 {
95 "command": "ra-lsp.run", 95 "command": "ra-lsp.run",
96 "title": "Rust Run" 96 "title": "Rust Run"
97 },
98 {
99 "command": "ra-lsp.analyzerStatus",
100 "title": "Status of rust-analyzer (debug)"
97 } 101 }
98 ], 102 ],
99 "keybindings": [ 103 "keybindings": [
diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts
new file mode 100644
index 000000000..5c56b9c4c
--- /dev/null
+++ b/editors/code/src/commands/analyzer_status.ts
@@ -0,0 +1,12 @@
1import * as vscode from 'vscode';
2import { Server } from '../server';
3
4// Shows status of rust-analyzer (for debugging)
5export async function handle() {
6 const status = await Server.client.sendRequest<string>(
7 'ra/analyzerStatus',
8 null
9 );
10 const doc = await vscode.workspace.openTextDocument({ content: status });
11 await vscode.window.showTextDocument(doc, vscode.ViewColumn.Two);
12}
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index 33e2b34a2..f36c4b040 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -1,3 +1,4 @@
1import * as analyzerStatus from './analyzer_status';
1import * as applySourceChange from './apply_source_change'; 2import * as applySourceChange from './apply_source_change';
2import * as extendSelection from './extend_selection'; 3import * as extendSelection from './extend_selection';
3import * as joinLines from './join_lines'; 4import * as joinLines from './join_lines';
@@ -8,6 +9,7 @@ import * as runnables from './runnables';
8import * as syntaxTree from './syntaxTree'; 9import * as syntaxTree from './syntaxTree';
9 10
10export { 11export {
12 analyzerStatus,
11 applySourceChange, 13 applySourceChange,
12 extendSelection, 14 extendSelection,
13 joinLines, 15 joinLines,
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 0098c9454..288a852aa 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -45,6 +45,7 @@ export function activate(context: vscode.ExtensionContext) {
45 } 45 }
46 46
47 // Commands are requests from vscode to the language server 47 // Commands are requests from vscode to the language server
48 registerCommand('ra-lsp.analyzerStatus', commands.analyzerStatus.handle);
48 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); 49 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
49 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); 50 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
50 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); 51 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);