Skip to content

Commit 1b8288f

Browse files
committed
Fixing naming from graph to list
1 parent e253592 commit 1b8288f

File tree

7 files changed

+52
-48
lines changed

7 files changed

+52
-48
lines changed

crates/ide/src/fetch_crates.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,50 @@ pub(crate) fn fetch_crates(db: &RootDatabase) -> Vec<CrateInfo> {
2222
.iter()
2323
.map(|crate_id| &crate_graph[crate_id])
2424
.filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. }))
25-
.map(|data| {
26-
let crate_name = crate_name(data);
27-
let version = data.version.clone().unwrap_or_else(|| "".to_owned());
28-
let crate_path = crate_path(db, data, &crate_name);
29-
30-
CrateInfo { name: crate_name, version, path: crate_path }
31-
})
25+
.filter_map(|data| crate_info(data, db))
3226
.collect()
3327
}
3428

29+
fn crate_info(data: &ide_db::base_db::CrateData, db: &RootDatabase) -> Option<CrateInfo> {
30+
let crate_name = crate_name(data);
31+
let crate_path = crate_path(db, data, &crate_name);
32+
if let Some(crate_path) = crate_path {
33+
let version = data.version.clone().unwrap_or_else(|| "".to_owned());
34+
Some(CrateInfo { name: crate_name, version, path: crate_path })
35+
} else {
36+
None
37+
}
38+
}
39+
3540
fn crate_name(data: &ide_db::base_db::CrateData) -> String {
3641
data.display_name
3742
.clone()
3843
.map(|it| it.canonical_name().to_owned())
3944
.unwrap_or("unknown".to_string())
4045
}
4146

42-
fn crate_path(db: &RootDatabase, data: &ide_db::base_db::CrateData, crate_name: &str) -> String {
47+
fn crate_path(
48+
db: &RootDatabase,
49+
data: &ide_db::base_db::CrateData,
50+
crate_name: &str,
51+
) -> Option<String> {
4352
let source_root_id = db.file_source_root(data.root_file_id);
4453
let source_root = db.source_root(source_root_id);
4554
let source_root_path = source_root.path_for_file(&data.root_file_id);
46-
match source_root_path.cloned() {
47-
Some(mut root_path) => {
48-
let mut crate_path = "".to_string();
49-
while let Some(vfs_path) = root_path.parent() {
50-
match vfs_path.name_and_extension() {
51-
Some((name, _)) => {
52-
if name.starts_with(crate_name) {
53-
crate_path = vfs_path.to_string();
54-
break;
55-
}
55+
source_root_path.cloned().and_then(|mut root_path| {
56+
let mut crate_path = None;
57+
while let Some(vfs_path) = root_path.parent() {
58+
match vfs_path.name_and_extension() {
59+
Some((name, _)) => {
60+
if name.starts_with(crate_name) {
61+
crate_path = Some(vfs_path.to_string());
62+
break;
5663
}
57-
None => break,
5864
}
59-
root_path = vfs_path;
65+
None => break,
6066
}
61-
crate_path
67+
root_path = vfs_path;
6268
}
63-
None => "".to_owned(),
64-
}
69+
crate_path
70+
})
6571
}

crates/rust-analyzer/src/handlers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use vfs::FileId;
99
use crate::{
1010
global_state::GlobalStateSnapshot, to_proto, Result,
1111
lsp_ext::{
12-
CrateInfoResult, FetchDependencyGraphResult, FetchDependencyGraphParams,
12+
CrateInfoResult, FetchDependencyListResult, FetchDependencyListParams,
1313
},
1414
};
1515

@@ -49,12 +49,12 @@ pub(crate) fn publish_diagnostics(
4949
Ok(diagnostics)
5050
}
5151

52-
pub(crate) fn fetch_dependency_graph(
52+
pub(crate) fn fetch_dependency_list(
5353
state: GlobalStateSnapshot,
54-
_params: FetchDependencyGraphParams,
55-
) -> Result<FetchDependencyGraphResult> {
54+
_params: FetchDependencyListParams,
55+
) -> Result<FetchDependencyListResult> {
5656
let crates = state.analysis.fetch_crates()?;
57-
Ok(FetchDependencyGraphResult {
57+
Ok(FetchDependencyListResult {
5858
crates: crates
5959
.into_iter()
6060
.map(|it| CrateInfoResult { name: it.name, version: it.version, path: it.path })

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ pub struct CrateInfoResult {
3434
pub version: String,
3535
pub path: String,
3636
}
37-
pub enum FetchDependencyGraph {}
37+
pub enum FetchDependencyList {}
3838

39-
impl Request for FetchDependencyGraph {
40-
type Params = FetchDependencyGraphParams;
41-
type Result = FetchDependencyGraphResult;
42-
const METHOD: &'static str = "rust-analyzer/fetchDependencyGraph";
39+
impl Request for FetchDependencyList {
40+
type Params = FetchDependencyListParams;
41+
type Result = FetchDependencyListResult;
42+
const METHOD: &'static str = "rust-analyzer/fetchDependencyList";
4343
}
4444

4545
#[derive(Deserialize, Serialize, Debug)]
4646
#[serde(rename_all = "camelCase")]
47-
pub struct FetchDependencyGraphParams {}
47+
pub struct FetchDependencyListParams {}
4848

4949
#[derive(Deserialize, Serialize, Debug)]
5050
#[serde(rename_all = "camelCase")]
51-
pub struct FetchDependencyGraphResult {
51+
pub struct FetchDependencyListResult {
5252
pub crates: Vec<CrateInfoResult>,
5353
}
5454

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl GlobalState {
660660
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
661661
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
662662
.on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)
663-
.on::<lsp_ext::FetchDependencyGraph>(handlers::fetch_dependency_graph)
663+
.on::<lsp_ext::FetchDependencyList>(handlers::fetch_dependency_list)
664664
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
665665
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
666666
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)

docs/dev/lsp-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ export interface Diagnostic {
855855

856856
## Dependency Tree
857857

858-
**Method:** `rust-analyzer/fetchDependencyGraph`
858+
**Method:** `rust-analyzer/fetchDependencyList`
859859

860860
**Request:**
861861

editors/code/src/dependencies_provider.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import * as fspath from "path";
33
import * as fs from "fs";
44
import { CtxInit } from "./ctx";
55
import * as ra from "./lsp_ext";
6-
import { FetchDependencyGraphResult } from "./lsp_ext";
6+
import { FetchDependencyListResult } from "./lsp_ext";
77
import { Ctx } from "./ctx";
88
import { setFlagsFromString } from "v8";
99
import * as ra from "./lsp_ext";
1010

1111

12-
1312
export class RustDependenciesProvider
1413
implements vscode.TreeDataProvider<Dependency | DependencyFile>
1514
{
@@ -82,8 +81,8 @@ export class RustDependenciesProvider
8281
private async getRootDependencies(): Promise<Dependency[]> {
8382
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
8483

85-
const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(
86-
ra.fetchDependencyGraph,
84+
const dependenciesResult: FetchDependencyListResult = await this.ctx.client.sendRequest(
85+
ra.fetchDependencyList,
8786
{}
8887
);
8988
const crates = dependenciesResult.crates;
@@ -97,7 +96,6 @@ export class RustDependenciesProvider
9796
}
9897

9998
private toDep(moduleName: string, version: string, path: string): Dependency {
100-
// const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
10199
return new Dependency(moduleName, version, path, vscode.TreeItemCollapsibleState.Collapsed);
102100
}
103101
}

editors/code/src/lsp_ext.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>
7070

7171
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
7272

73-
export interface FetchDependencyGraphParams {}
73+
export interface FetchDependencyListParams {}
7474

75-
export interface FetchDependencyGraphResult {
75+
export interface FetchDependencyListResult {
7676
crates: {
7777
name: string;
7878
version: string;
7979
path: string;
8080
}[];
8181
}
8282

83-
export const fetchDependencyGraph = new lc.RequestType<
84-
FetchDependencyGraphParams,
85-
FetchDependencyGraphResult,
83+
export const fetchDependencyList = new lc.RequestType<
84+
FetchDependencyListParams,
85+
FetchDependencyListResult,
8686
void
87-
>("rust-analyzer/fetchDependencyGraph");
87+
>("rust-analyzer/fetchDependencyList");
8888

8989
export interface FetchDependencyGraphParams {}
9090

0 commit comments

Comments
 (0)