]> git.lizzy.rs Git - rust.git/commitdiff
ad status command
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 22 Jan 2019 21:15:03 +0000 (00:15 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 22 Jan 2019 22:24:53 +0000 (01:24 +0300)
crates/ra_ide_api/src/lib.rs
crates/ra_ide_api/src/status.rs [new file with mode: 0644]
crates/ra_lsp_server/src/main_loop.rs
crates/ra_lsp_server/src/main_loop/handlers.rs
crates/ra_lsp_server/src/req.rs
crates/ra_lsp_server/src/server_world.rs
editors/code/package.json
editors/code/src/commands/analyzer_status.ts [new file with mode: 0644]
editors/code/src/commands/index.ts
editors/code/src/extension.ts

index a09a8f92678a740f483a667f37bbe8ce650bd10a..3c53e75ac43240797608cfbe42079bc7ebe8ea92 100644 (file)
@@ -15,6 +15,7 @@
 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<String> {
         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 (file)
index 0000000..d3e04be
--- /dev/null
@@ -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)
+}
index fa07b194283ed43bcbef093b8d9b3588c3acd84d..f51576521e93c6afd2548148de65a01f1314f94c 100644 (file)
@@ -285,6 +285,7 @@ fn on_request(
         sender,
     };
     let req = pool_dispatcher
+        .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)?
         .on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
         .on::<req::ExtendSelection>(handlers::handle_extend_selection)?
         .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)?
index 497f819bebc397b159db184818ec0bc1385f0236..d84f762f4dd9565f397dd111e8c1865a5959da73 100644 (file)
     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> {
     let id = params.text_document.try_conv_with(&world)?;
     let res = world.analysis().syntax_tree(id);
index 156cf9641138b1cd3b71205e4067437510f62715..ec6b6d905cd859bcbd541e88b255c309308a66e3 100644 (file)
     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 {
index c24ded9f97160c7892e9235ac50414eaa9743e27..5cb97b29b70c27883c2c8cf82e2701defcccfca4 100644 (file)
@@ -264,4 +264,19 @@ pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<
             .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
+    }
 }
index 9433bd3d2c8a5df4484bd72ec2bfa99b2b08cf15..3e07032c7ff0c6b72c16e2d3e06da6cc39856875 100644 (file)
             {
                 "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 (file)
index 0000000..5c56b9c
--- /dev/null
@@ -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);
+}
index 33e2b34a28c1765f11f5860a359918a08871c995..f36c4b040f556a0bf13a87e2d45f995c0c6bff0f 100644 (file)
@@ -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,
index 0098c94547ab05dc17eb6202a9524ac1fdac4184..288a852aa3f8a9bf1874dfe70f993ae4b3e921ce 100644 (file)
@@ -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);