From 0ba7e2eaebf335dbc31b5d6dbc9c354737c7fe54 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 23 Jan 2019 00:15:03 +0300 Subject: [PATCH] ad status command --- crates/ra_ide_api/src/lib.rs | 6 ++++++ crates/ra_ide_api/src/status.rs | 15 +++++++++++++++ crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 4 ++++ crates/ra_lsp_server/src/req.rs | 8 ++++++++ crates/ra_lsp_server/src/server_world.rs | 15 +++++++++++++++ editors/code/package.json | 4 ++++ editors/code/src/commands/analyzer_status.ts | 12 ++++++++++++ editors/code/src/commands/index.ts | 2 ++ editors/code/src/extension.ts | 1 + 10 files changed, 68 insertions(+) create mode 100644 crates/ra_ide_api/src/status.rs create mode 100644 editors/code/src/commands/analyzer_status.ts diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index a09a8f9267..3c53e75ac4 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; mod symbol_index; mod navigation_target; +mod status; mod completion; mod runnables; mod goto_definition; @@ -293,6 +294,11 @@ pub struct Analysis { } impl Analysis { + /// Debug info about the current state of the analysis + pub fn status(&self) -> String { + status::status(&*self.db) + } + /// Gets the text of the source file. pub fn file_text(&self, file_id: FileId) -> Arc { 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 0000000000..d3e04be230 --- /dev/null +++ b/crates/ra_ide_api/src/status.rs @@ -0,0 +1,15 @@ +use ra_db::{ + LocationIntener, SourceFileQuery, + salsa::{Database, debug::DebugQueryTable}, +}; + +use crate::db::RootDatabase; + +pub(crate) fn status(db: &RootDatabase) -> String { + let n_parsed_files = db.query(SourceFileQuery).keys::>().len(); + let n_defs = { + let interner: &LocationIntener = db.as_ref(); + interner.len() + }; + format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs) +} diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index fa07b19428..f51576521e 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( sender, }; let req = pool_dispatcher + .on::(handlers::handle_analyzer_status)? .on::(handlers::handle_syntax_tree)? .on::(handlers::handle_extend_selection)? .on::(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 497f819beb..d84f762f4d 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::{ LspError, Result, }; +pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result { + Ok(world.status()) +} + pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result { let id = params.text_document.try_conv_with(&world)?; 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 156cf96411..ec6b6d905c 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::{ TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, }; +pub enum AnalyzerStatus {} + +impl Request for AnalyzerStatus { + type Params = (); + type Result = String; + const METHOD: &'static str = "ra/analyzerStatus"; +} + pub enum SyntaxTree {} impl Request for SyntaxTree { diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index c24ded9f97..5cb97b29b7 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 { .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; Ok(url) } + + pub fn status(&self) -> String { + let mut res = String::new(); + if self.workspaces.is_empty() { + res.push_str("no workspaces\n") + } else { + res.push_str("workspaces:\n"); + for w in self.workspaces.iter() { + res += &format!("{} packages loaded\n", w.cargo.packages().count()); + } + } + res.push_str("\nanalysis:\n"); + res.push_str(&self.analysis.status()); + res + } } diff --git a/editors/code/package.json b/editors/code/package.json index 9433bd3d2c..3e07032c7f 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -94,6 +94,10 @@ { "command": "ra-lsp.run", "title": "Rust Run" + }, + { + "command": "ra-lsp.analyzerStatus", + "title": "Status of rust-analyzer (debug)" } ], "keybindings": [ diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts new file mode 100644 index 0000000000..5c56b9c4cd --- /dev/null +++ b/editors/code/src/commands/analyzer_status.ts @@ -0,0 +1,12 @@ +import * as vscode from 'vscode'; +import { Server } from '../server'; + +// Shows status of rust-analyzer (for debugging) +export async function handle() { + const status = await Server.client.sendRequest( + 'ra/analyzerStatus', + null + ); + const doc = await vscode.workspace.openTextDocument({ content: status }); + await vscode.window.showTextDocument(doc, vscode.ViewColumn.Two); +} diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 33e2b34a28..f36c4b040f 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -1,3 +1,4 @@ +import * as analyzerStatus from './analyzer_status'; import * as applySourceChange from './apply_source_change'; import * as extendSelection from './extend_selection'; import * as joinLines from './join_lines'; @@ -8,6 +9,7 @@ import * as runnables from './runnables'; import * as syntaxTree from './syntaxTree'; export { + analyzerStatus, applySourceChange, extendSelection, joinLines, diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 0098c94547..288a852aa3 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -45,6 +45,7 @@ export function activate(context: vscode.ExtensionContext) { } // Commands are requests from vscode to the language server + registerCommand('ra-lsp.analyzerStatus', commands.analyzerStatus.handle); registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);