aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-25 13:10:34 +0000
committerAleksey Kladov <[email protected]>2019-01-25 13:16:42 +0000
commit8d68b76ba01dcd190e037e4d61a94d4c9d568bdd (patch)
tree07aa4db38ba212ab1e2af1b791c409e5407ac53b
parent021e691997efc35c983808ee3470a060a3ec3e96 (diff)
better stats
-rw-r--r--crates/ra_ide_api/src/status.rs50
-rw-r--r--editors/code/src/commands/analyzer_status.ts61
-rw-r--r--editors/code/src/extension.ts5
3 files changed, 107 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs
index d499dd878..c184ca892 100644
--- a/crates/ra_ide_api/src/status.rs
+++ b/crates/ra_ide_api/src/status.rs
@@ -1,3 +1,6 @@
1use std::fmt;
2
3use ra_syntax::AstNode;
1use ra_db::{ 4use ra_db::{
2 SourceFileQuery, 5 SourceFileQuery,
3 salsa::{Database, debug::DebugQueryTable}, 6 salsa::{Database, debug::DebugQueryTable},
@@ -6,10 +9,53 @@ use ra_db::{
6use crate::db::RootDatabase; 9use crate::db::RootDatabase;
7 10
8pub(crate) fn status(db: &RootDatabase) -> String { 11pub(crate) fn status(db: &RootDatabase) -> String {
9 let n_parsed_files = db.query(SourceFileQuery).entries::<Vec<_>>().len(); 12 let file_stats = {
13 let mut stats = FilesStats::default();
14 for entry in db.query(SourceFileQuery).entries::<Vec<_>>() {
15 stats.total += 1;
16 if let Some(value) = entry.value {
17 stats.retained += 1;
18 stats.retained_size = stats
19 .retained_size
20 .checked_add(value.syntax().memory_size_of_subtree())
21 .unwrap();
22 }
23 }
24 stats
25 };
10 let n_defs = { 26 let n_defs = {
11 let interner: &hir::HirInterner = db.as_ref(); 27 let interner: &hir::HirInterner = db.as_ref();
12 interner.len() 28 interner.len()
13 }; 29 };
14 format!("#n_parsed_files {}\n#n_defs {}\n", n_parsed_files, n_defs) 30 format!("{}\nn_defs {}\n", file_stats, n_defs)
31}
32
33#[derive(Default)]
34struct FilesStats {
35 total: usize,
36 retained: usize,
37 retained_size: usize,
38}
39
40impl fmt::Display for FilesStats {
41 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
42 let (size, suff) = human_bytes(self.retained_size);
43 write!(
44 fmt,
45 "{} parsed_files, {} ({}{}) retained",
46 self.total, self.retained, size, suff
47 )
48 }
49}
50
51fn human_bytes(bytes: usize) -> (usize, &'static str) {
52 if bytes < 4096 {
53 return (bytes, " bytes");
54 }
55 let kb = bytes / 1024;
56 if kb < 4096 {
57 return (kb, "kb");
58 }
59 let mb = kb / 1024;
60 (mb, "mb")
15} 61}
diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts
index 5c56b9c4c..bb46a1990 100644
--- a/editors/code/src/commands/analyzer_status.ts
+++ b/editors/code/src/commands/analyzer_status.ts
@@ -1,12 +1,61 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import { Server } from '../server'; 2import { Server } from '../server';
3 3
4const statusUri = vscode.Uri.parse('ra-lsp-status://status');
5
6export class TextDocumentContentProvider
7 implements vscode.TextDocumentContentProvider {
8 public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
9 public syntaxTree: string = 'Not available';
10
11 public provideTextDocumentContent(
12 uri: vscode.Uri
13 ): vscode.ProviderResult<string> {
14 const editor = vscode.window.activeTextEditor;
15 if (editor == null) {
16 return '';
17 }
18 return Server.client.sendRequest<string>('ra/analyzerStatus', null);
19 }
20
21 get onDidChange(): vscode.Event<vscode.Uri> {
22 return this.eventEmitter.event;
23 }
24}
25
26let poller: NodeJS.Timer | null = null;
27
4// Shows status of rust-analyzer (for debugging) 28// Shows status of rust-analyzer (for debugging)
5export async function handle() { 29
6 const status = await Server.client.sendRequest<string>( 30export function makeCommand(context: vscode.ExtensionContext) {
7 'ra/analyzerStatus', 31 const textDocumentContentProvider = new TextDocumentContentProvider();
8 null 32 context.subscriptions.push(
33 vscode.workspace.registerTextDocumentContentProvider(
34 'ra-lsp-status',
35 textDocumentContentProvider
36 )
9 ); 37 );
10 const doc = await vscode.workspace.openTextDocument({ content: status }); 38
11 await vscode.window.showTextDocument(doc, vscode.ViewColumn.Two); 39 context.subscriptions.push({
40 dispose() {
41 if (poller != null) {
42 clearInterval(poller);
43 }
44 }
45 });
46
47 return async function handle() {
48 if (poller == null) {
49 poller = setInterval(
50 () => textDocumentContentProvider.eventEmitter.fire(statusUri),
51 1000
52 );
53 }
54 const document = await vscode.workspace.openTextDocument(statusUri);
55 return vscode.window.showTextDocument(
56 document,
57 vscode.ViewColumn.Two,
58 true
59 );
60 };
12} 61}
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 288a852aa..3af95c599 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -45,7 +45,10 @@ 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(
49 'ra-lsp.analyzerStatus',
50 commands.analyzerStatus.makeCommand(context)
51 );
49 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); 52 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
50 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); 53 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
51 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); 54 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);