mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 11:55:04 +00:00
ad status command
This commit is contained in:
parent
e08df3219d
commit
0ba7e2eaeb
10 changed files with 68 additions and 0 deletions
|
@ -15,6 +15,7 @@ pub mod mock_analysis;
|
||||||
mod symbol_index;
|
mod symbol_index;
|
||||||
mod navigation_target;
|
mod navigation_target;
|
||||||
|
|
||||||
|
mod status;
|
||||||
mod completion;
|
mod completion;
|
||||||
mod runnables;
|
mod runnables;
|
||||||
mod goto_definition;
|
mod goto_definition;
|
||||||
|
@ -293,6 +294,11 @@ pub struct Analysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
/// Gets the text of the source file.
|
||||||
pub fn file_text(&self, file_id: FileId) -> Arc<String> {
|
pub fn file_text(&self, file_id: FileId) -> Arc<String> {
|
||||||
self.db.file_text(file_id)
|
self.db.file_text(file_id)
|
||||||
|
|
15
crates/ra_ide_api/src/status.rs
Normal file
15
crates/ra_ide_api/src/status.rs
Normal file
|
@ -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::<Vec<_>>().len();
|
||||||
|
let n_defs = {
|
||||||
|
let interner: &LocationIntener<hir::DefLoc, hir::DefId> = db.as_ref();
|
||||||
|
interner.len()
|
||||||
|
};
|
||||||
|
format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs)
|
||||||
|
}
|
|
@ -285,6 +285,7 @@ fn on_request(
|
||||||
sender,
|
sender,
|
||||||
};
|
};
|
||||||
let req = pool_dispatcher
|
let req = pool_dispatcher
|
||||||
|
.on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)?
|
||||||
.on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
|
.on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
|
||||||
.on::<req::ExtendSelection>(handlers::handle_extend_selection)?
|
.on::<req::ExtendSelection>(handlers::handle_extend_selection)?
|
||||||
.on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)?
|
.on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)?
|
||||||
|
|
|
@ -23,6 +23,10 @@ use crate::{
|
||||||
LspError, Result,
|
LspError, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> {
|
||||||
|
Ok(world.status())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> {
|
pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> {
|
||||||
let id = params.text_document.try_conv_with(&world)?;
|
let id = params.text_document.try_conv_with(&world)?;
|
||||||
let res = world.analysis().syntax_tree(id);
|
let res = world.analysis().syntax_tree(id);
|
||||||
|
|
|
@ -11,6 +11,14 @@ pub use lsp_types::{
|
||||||
TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams,
|
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 {}
|
pub enum SyntaxTree {}
|
||||||
|
|
||||||
impl Request for SyntaxTree {
|
impl Request for SyntaxTree {
|
||||||
|
|
|
@ -264,4 +264,19 @@ impl ServerWorld {
|
||||||
.map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
|
.map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
|
||||||
Ok(url)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,10 @@
|
||||||
{
|
{
|
||||||
"command": "ra-lsp.run",
|
"command": "ra-lsp.run",
|
||||||
"title": "Rust Run"
|
"title": "Rust Run"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "ra-lsp.analyzerStatus",
|
||||||
|
"title": "Status of rust-analyzer (debug)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keybindings": [
|
"keybindings": [
|
||||||
|
|
12
editors/code/src/commands/analyzer_status.ts
Normal file
12
editors/code/src/commands/analyzer_status.ts
Normal file
|
@ -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<string>(
|
||||||
|
'ra/analyzerStatus',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const doc = await vscode.workspace.openTextDocument({ content: status });
|
||||||
|
await vscode.window.showTextDocument(doc, vscode.ViewColumn.Two);
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as analyzerStatus from './analyzer_status';
|
||||||
import * as applySourceChange from './apply_source_change';
|
import * as applySourceChange from './apply_source_change';
|
||||||
import * as extendSelection from './extend_selection';
|
import * as extendSelection from './extend_selection';
|
||||||
import * as joinLines from './join_lines';
|
import * as joinLines from './join_lines';
|
||||||
|
@ -8,6 +9,7 @@ import * as runnables from './runnables';
|
||||||
import * as syntaxTree from './syntaxTree';
|
import * as syntaxTree from './syntaxTree';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
analyzerStatus,
|
||||||
applySourceChange,
|
applySourceChange,
|
||||||
extendSelection,
|
extendSelection,
|
||||||
joinLines,
|
joinLines,
|
||||||
|
|
|
@ -45,6 +45,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commands are requests from vscode to the language server
|
// 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.syntaxTree', commands.syntaxTree.handle);
|
||||||
registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
|
registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
|
||||||
registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);
|
registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);
|
||||||
|
|
Loading…
Reference in a new issue