Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide/src/fetch_crates.rs52
-rw-r--r--crates/rust-analyzer/src/handlers.rs10
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs14
-rw-r--r--crates/rust-analyzer/src/main_loop.rs2
-rw-r--r--docs/dev/lsp-extensions.md2
-rw-r--r--editors/code/src/dependencies_provider.ts8
-rw-r--r--editors/code/src/lsp_ext.ts12
7 files changed, 52 insertions, 48 deletions
diff --git a/crates/ide/src/fetch_crates.rs b/crates/ide/src/fetch_crates.rs
index ec6d66d5c4..416082ae73 100644
--- a/crates/ide/src/fetch_crates.rs
+++ b/crates/ide/src/fetch_crates.rs
@@ -22,16 +22,21 @@ pub(crate) fn fetch_crates(db: &RootDatabase) -> Vec<CrateInfo> {
.iter()
.map(|crate_id| &crate_graph[crate_id])
.filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. }))
- .map(|data| {
- let crate_name = crate_name(data);
- let version = data.version.clone().unwrap_or_else(|| "".to_owned());
- let crate_path = crate_path(db, data, &crate_name);
-
- CrateInfo { name: crate_name, version, path: crate_path }
- })
+ .filter_map(|data| crate_info(data, db))
.collect()
}
+fn crate_info(data: &ide_db::base_db::CrateData, db: &RootDatabase) -> Option<CrateInfo> {
+ let crate_name = crate_name(data);
+ let crate_path = crate_path(db, data, &crate_name);
+ if let Some(crate_path) = crate_path {
+ let version = data.version.clone().unwrap_or_else(|| "".to_owned());
+ Some(CrateInfo { name: crate_name, version, path: crate_path })
+ } else {
+ None
+ }
+}
+
fn crate_name(data: &ide_db::base_db::CrateData) -> String {
data.display_name
.clone()
@@ -39,27 +44,28 @@ fn crate_name(data: &ide_db::base_db::CrateData) -> String {
.unwrap_or("unknown".to_string())
}
-fn crate_path(db: &RootDatabase, data: &ide_db::base_db::CrateData, crate_name: &str) -> String {
+fn crate_path(
+ db: &RootDatabase,
+ data: &ide_db::base_db::CrateData,
+ crate_name: &str,
+) -> Option<String> {
let source_root_id = db.file_source_root(data.root_file_id);
let source_root = db.source_root(source_root_id);
let source_root_path = source_root.path_for_file(&data.root_file_id);
- match source_root_path.cloned() {
- Some(mut root_path) => {
- let mut crate_path = "".to_string();
- while let Some(vfs_path) = root_path.parent() {
- match vfs_path.name_and_extension() {
- Some((name, _)) => {
- if name.starts_with(crate_name) {
- crate_path = vfs_path.to_string();
- break;
- }
+ source_root_path.cloned().and_then(|mut root_path| {
+ let mut crate_path = None;
+ while let Some(vfs_path) = root_path.parent() {
+ match vfs_path.name_and_extension() {
+ Some((name, _)) => {
+ if name.starts_with(crate_name) {
+ crate_path = Some(vfs_path.to_string());
+ break;
}
- None => break,
}
- root_path = vfs_path;
+ None => break,
}
- crate_path
+ root_path = vfs_path;
}
- None => "".to_owned(),
- }
+ crate_path
+ })
}
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 2324490e53..5c966f0f68 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -9,7 +9,7 @@ use vfs::FileId;
use crate::{
global_state::GlobalStateSnapshot, to_proto, Result,
lsp_ext::{
- CrateInfoResult, FetchDependencyGraphResult, FetchDependencyGraphParams,
+ CrateInfoResult, FetchDependencyListResult, FetchDependencyListParams,
},
};
@@ -49,12 +49,12 @@ pub(crate) fn publish_diagnostics(
Ok(diagnostics)
}
-pub(crate) fn fetch_dependency_graph(
+pub(crate) fn fetch_dependency_list(
state: GlobalStateSnapshot,
- _params: FetchDependencyGraphParams,
-) -> Result<FetchDependencyGraphResult> {
+ _params: FetchDependencyListParams,
+) -> Result<FetchDependencyListResult> {
let crates = state.analysis.fetch_crates()?;
- Ok(FetchDependencyGraphResult {
+ Ok(FetchDependencyListResult {
crates: crates
.into_iter()
.map(|it| CrateInfoResult { name: it.name, version: it.version, path: it.path })
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index 18511da468..6285578a6c 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -34,21 +34,21 @@ pub struct CrateInfoResult {
pub version: String,
pub path: String,
}
-pub enum FetchDependencyGraph {}
+pub enum FetchDependencyList {}
-impl Request for FetchDependencyGraph {
- type Params = FetchDependencyGraphParams;
- type Result = FetchDependencyGraphResult;
- const METHOD: &'static str = "rust-analyzer/fetchDependencyGraph";
+impl Request for FetchDependencyList {
+ type Params = FetchDependencyListParams;
+ type Result = FetchDependencyListResult;
+ const METHOD: &'static str = "rust-analyzer/fetchDependencyList";
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
-pub struct FetchDependencyGraphParams {}
+pub struct FetchDependencyListParams {}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
-pub struct FetchDependencyGraphResult {
+pub struct FetchDependencyListResult {
pub crates: Vec<CrateInfoResult>,
}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 7a81a18f4a..d3cfc5e40d 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -660,7 +660,7 @@ impl GlobalState {
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
.on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)
- .on::<lsp_ext::FetchDependencyGraph>(handlers::fetch_dependency_graph)
+ .on::<lsp_ext::FetchDependencyList>(handlers::fetch_dependency_list)
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 41bda554be..d73ae3d519 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -855,7 +855,7 @@ export interface Diagnostic {
## Dependency Tree
-**Method:** `rust-analyzer/fetchDependencyGraph`
+**Method:** `rust-analyzer/fetchDependencyList`
**Request:**
diff --git a/editors/code/src/dependencies_provider.ts b/editors/code/src/dependencies_provider.ts
index 3713250b8f..2e5ea04922 100644
--- a/editors/code/src/dependencies_provider.ts
+++ b/editors/code/src/dependencies_provider.ts
@@ -3,13 +3,12 @@ import * as fspath from "path";
import * as fs from "fs";
import { CtxInit } from "./ctx";
import * as ra from "./lsp_ext";
-import { FetchDependencyGraphResult } from "./lsp_ext";
+import { FetchDependencyListResult } from "./lsp_ext";
import { Ctx } from "./ctx";
import { setFlagsFromString } from "v8";
import * as ra from "./lsp_ext";
-
export class RustDependenciesProvider
implements vscode.TreeDataProvider<Dependency | DependencyFile>
{
@@ -82,8 +81,8 @@ export class RustDependenciesProvider
private async getRootDependencies(): Promise<Dependency[]> {
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
- const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(
- ra.fetchDependencyGraph,
+ const dependenciesResult: FetchDependencyListResult = await this.ctx.client.sendRequest(
+ ra.fetchDependencyList,
{}
);
const crates = dependenciesResult.crates;
@@ -97,7 +96,6 @@ export class RustDependenciesProvider
}
private toDep(moduleName: string, version: string, path: string): Dependency {
- // const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
return new Dependency(moduleName, version, path, vscode.TreeItemCollapsibleState.Collapsed);
}
}
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index f066a1c654..30de5035d6 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -70,9 +70,9 @@ export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
-export interface FetchDependencyGraphParams {}
+export interface FetchDependencyListParams {}
-export interface FetchDependencyGraphResult {
+export interface FetchDependencyListResult {
crates: {
name: string;
version: string;
@@ -80,11 +80,11 @@ export interface FetchDependencyGraphResult {
}[];
}
-export const fetchDependencyGraph = new lc.RequestType<
- FetchDependencyGraphParams,
- FetchDependencyGraphResult,
+export const fetchDependencyList = new lc.RequestType<
+ FetchDependencyListParams,
+ FetchDependencyListResult,
void
->("rust-analyzer/fetchDependencyGraph");
+>("rust-analyzer/fetchDependencyList");
export interface FetchDependencyGraphParams {}