mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Fixing naming from graph to list
This commit is contained in:
parent
e2535926e9
commit
1b8288ff96
7 changed files with 52 additions and 48 deletions
|
@ -22,16 +22,21 @@ pub(crate) fn fetch_crates(db: &RootDatabase) -> Vec<CrateInfo> {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|crate_id| &crate_graph[crate_id])
|
.map(|crate_id| &crate_graph[crate_id])
|
||||||
.filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. }))
|
.filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. }))
|
||||||
.map(|data| {
|
.filter_map(|data| crate_info(data, db))
|
||||||
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 }
|
|
||||||
})
|
|
||||||
.collect()
|
.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 {
|
fn crate_name(data: &ide_db::base_db::CrateData) -> String {
|
||||||
data.display_name
|
data.display_name
|
||||||
.clone()
|
.clone()
|
||||||
|
@ -39,27 +44,28 @@ fn crate_name(data: &ide_db::base_db::CrateData) -> String {
|
||||||
.unwrap_or("unknown".to_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_id = db.file_source_root(data.root_file_id);
|
||||||
let source_root = db.source_root(source_root_id);
|
let source_root = db.source_root(source_root_id);
|
||||||
let source_root_path = source_root.path_for_file(&data.root_file_id);
|
let source_root_path = source_root.path_for_file(&data.root_file_id);
|
||||||
match source_root_path.cloned() {
|
source_root_path.cloned().and_then(|mut root_path| {
|
||||||
Some(mut root_path) => {
|
let mut crate_path = None;
|
||||||
let mut crate_path = "".to_string();
|
while let Some(vfs_path) = root_path.parent() {
|
||||||
while let Some(vfs_path) = root_path.parent() {
|
match vfs_path.name_and_extension() {
|
||||||
match vfs_path.name_and_extension() {
|
Some((name, _)) => {
|
||||||
Some((name, _)) => {
|
if name.starts_with(crate_name) {
|
||||||
if name.starts_with(crate_name) {
|
crate_path = Some(vfs_path.to_string());
|
||||||
crate_path = vfs_path.to_string();
|
break;
|
||||||
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 vfs::FileId;
|
||||||
use crate::{
|
use crate::{
|
||||||
global_state::GlobalStateSnapshot, to_proto, Result,
|
global_state::GlobalStateSnapshot, to_proto, Result,
|
||||||
lsp_ext::{
|
lsp_ext::{
|
||||||
CrateInfoResult, FetchDependencyGraphResult, FetchDependencyGraphParams,
|
CrateInfoResult, FetchDependencyListResult, FetchDependencyListParams,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,12 +49,12 @@ pub(crate) fn publish_diagnostics(
|
||||||
Ok(diagnostics)
|
Ok(diagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fetch_dependency_graph(
|
pub(crate) fn fetch_dependency_list(
|
||||||
state: GlobalStateSnapshot,
|
state: GlobalStateSnapshot,
|
||||||
_params: FetchDependencyGraphParams,
|
_params: FetchDependencyListParams,
|
||||||
) -> Result<FetchDependencyGraphResult> {
|
) -> Result<FetchDependencyListResult> {
|
||||||
let crates = state.analysis.fetch_crates()?;
|
let crates = state.analysis.fetch_crates()?;
|
||||||
Ok(FetchDependencyGraphResult {
|
Ok(FetchDependencyListResult {
|
||||||
crates: crates
|
crates: crates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|it| CrateInfoResult { name: it.name, version: it.version, path: it.path })
|
.map(|it| CrateInfoResult { name: it.name, version: it.version, path: it.path })
|
||||||
|
|
|
@ -34,21 +34,21 @@ pub struct CrateInfoResult {
|
||||||
pub version: String,
|
pub version: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
pub enum FetchDependencyGraph {}
|
pub enum FetchDependencyList {}
|
||||||
|
|
||||||
impl Request for FetchDependencyGraph {
|
impl Request for FetchDependencyList {
|
||||||
type Params = FetchDependencyGraphParams;
|
type Params = FetchDependencyListParams;
|
||||||
type Result = FetchDependencyGraphResult;
|
type Result = FetchDependencyListResult;
|
||||||
const METHOD: &'static str = "rust-analyzer/fetchDependencyGraph";
|
const METHOD: &'static str = "rust-analyzer/fetchDependencyList";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct FetchDependencyGraphParams {}
|
pub struct FetchDependencyListParams {}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct FetchDependencyGraphResult {
|
pub struct FetchDependencyListResult {
|
||||||
pub crates: Vec<CrateInfoResult>,
|
pub crates: Vec<CrateInfoResult>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -660,7 +660,7 @@ impl GlobalState {
|
||||||
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
|
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
|
||||||
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
|
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
|
||||||
.on_sync::<lsp_ext::MatchingBrace>(handlers::handle_matching_brace)
|
.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::AnalyzerStatus>(handlers::handle_analyzer_status)
|
||||||
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
|
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
|
||||||
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
|
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
|
||||||
|
|
|
@ -855,7 +855,7 @@ export interface Diagnostic {
|
||||||
|
|
||||||
## Dependency Tree
|
## Dependency Tree
|
||||||
|
|
||||||
**Method:** `rust-analyzer/fetchDependencyGraph`
|
**Method:** `rust-analyzer/fetchDependencyList`
|
||||||
|
|
||||||
**Request:**
|
**Request:**
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,12 @@ import * as fspath from "path";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { CtxInit } from "./ctx";
|
import { CtxInit } from "./ctx";
|
||||||
import * as ra from "./lsp_ext";
|
import * as ra from "./lsp_ext";
|
||||||
import { FetchDependencyGraphResult } from "./lsp_ext";
|
import { FetchDependencyListResult } from "./lsp_ext";
|
||||||
import { Ctx } from "./ctx";
|
import { Ctx } from "./ctx";
|
||||||
import { setFlagsFromString } from "v8";
|
import { setFlagsFromString } from "v8";
|
||||||
import * as ra from "./lsp_ext";
|
import * as ra from "./lsp_ext";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export class RustDependenciesProvider
|
export class RustDependenciesProvider
|
||||||
implements vscode.TreeDataProvider<Dependency | DependencyFile>
|
implements vscode.TreeDataProvider<Dependency | DependencyFile>
|
||||||
{
|
{
|
||||||
|
@ -82,8 +81,8 @@ export class RustDependenciesProvider
|
||||||
private async getRootDependencies(): Promise<Dependency[]> {
|
private async getRootDependencies(): Promise<Dependency[]> {
|
||||||
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
|
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
|
||||||
|
|
||||||
const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(
|
const dependenciesResult: FetchDependencyListResult = await this.ctx.client.sendRequest(
|
||||||
ra.fetchDependencyGraph,
|
ra.fetchDependencyList,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
const crates = dependenciesResult.crates;
|
const crates = dependenciesResult.crates;
|
||||||
|
@ -97,7 +96,6 @@ export class RustDependenciesProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
private toDep(moduleName: string, version: string, path: string): Dependency {
|
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);
|
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 type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
|
||||||
|
|
||||||
export interface FetchDependencyGraphParams {}
|
export interface FetchDependencyListParams {}
|
||||||
|
|
||||||
export interface FetchDependencyGraphResult {
|
export interface FetchDependencyListResult {
|
||||||
crates: {
|
crates: {
|
||||||
name: string;
|
name: string;
|
||||||
version: string;
|
version: string;
|
||||||
|
@ -80,11 +80,11 @@ export interface FetchDependencyGraphResult {
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchDependencyGraph = new lc.RequestType<
|
export const fetchDependencyList = new lc.RequestType<
|
||||||
FetchDependencyGraphParams,
|
FetchDependencyListParams,
|
||||||
FetchDependencyGraphResult,
|
FetchDependencyListResult,
|
||||||
void
|
void
|
||||||
>("rust-analyzer/fetchDependencyGraph");
|
>("rust-analyzer/fetchDependencyList");
|
||||||
|
|
||||||
export interface FetchDependencyGraphParams {}
|
export interface FetchDependencyGraphParams {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue