Fixing naming from graph to list
This commit is contained in:
parent
e2535926e9
commit
1b8288ff96
@ -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
|
||||
})
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
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 })
|
||||
|
@ -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>,
|
||||
}
|
||||
|
||||
|
@ -660,7 +660,7 @@ fn on_request(&mut self, req: Request) {
|
||||
.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)
|
||||
|
@ -855,7 +855,7 @@ export interface Diagnostic {
|
||||
|
||||
## Dependency Tree
|
||||
|
||||
**Method:** `rust-analyzer/fetchDependencyGraph`
|
||||
**Method:** `rust-analyzer/fetchDependencyList`
|
||||
|
||||
**Request:**
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user