10841: Emit moniker in lsif r=Veykril a=HKalbasi

fix #10559 

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
Co-authored-by: HKalbasi <45197576+HKalbasi@users.noreply.github.com>
This commit is contained in:
bors[bot] 2021-11-29 11:13:39 +00:00 committed by GitHub
commit 393cbd0982
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 511 additions and 19 deletions

View file

@ -130,6 +130,8 @@ pub struct PackageData {
pub version: semver::Version,
/// Name as given in the `Cargo.toml`
pub name: String,
/// Repository as given in the `Cargo.toml`
pub repository: Option<String>,
/// Path containing the `Cargo.toml`
pub manifest: ManifestPath,
/// Targets provided by the crate (lib, bin, example, test, ...)
@ -146,9 +148,9 @@ pub struct PackageData {
pub features: FxHashMap<String, Vec<String>>,
/// List of features enabled on this package
pub active_features: Vec<String>,
// String representation of package id
/// String representation of package id
pub id: String,
// The contents of [package.metadata.rust-analyzer]
/// The contents of [package.metadata.rust-analyzer]
pub metadata: RustAnalyzerPackageMetaData,
}
@ -302,7 +304,14 @@ impl CargoWorkspace {
meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
for meta_pkg in &meta.packages {
let cargo_metadata::Package {
id, edition, name, manifest_path, version, metadata, ..
id,
edition,
name,
manifest_path,
version,
metadata,
repository,
..
} = meta_pkg;
let meta = from_value::<PackageMetadata>(metadata.clone()).unwrap_or_default();
let edition = edition.parse::<Edition>().unwrap_or_else(|err| {
@ -323,6 +332,7 @@ impl CargoWorkspace {
is_local,
is_member,
edition,
repository: repository.clone(),
dependencies: Vec::new(),
features: meta_pkg.features.clone().into_iter().collect(),
active_features: Vec::new(),

View file

@ -39,6 +39,7 @@ pub struct Crate {
pub(crate) include: Vec<AbsPathBuf>,
pub(crate) exclude: Vec<AbsPathBuf>,
pub(crate) is_proc_macro: bool,
pub(crate) repository: Option<String>,
}
impl ProjectJson {
@ -99,6 +100,7 @@ impl ProjectJson {
include,
exclude,
is_proc_macro: crate_data.is_proc_macro,
repository: crate_data.repository,
}
})
.collect::<Vec<_>>(),
@ -142,6 +144,8 @@ struct CrateData {
source: Option<CrateSource>,
#[serde(default)]
is_proc_macro: bool,
#[serde(default)]
repository: Option<String>,
}
#[derive(Deserialize, Debug, Clone)]

View file

@ -173,6 +173,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
5,
@ -242,6 +245,11 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
2,
@ -311,6 +319,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
4,
@ -370,6 +381,11 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
dependencies: [],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
1,
@ -439,6 +455,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
6,
@ -498,6 +517,11 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
dependencies: [],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
3,
@ -567,6 +591,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
},
}"#]],
@ -651,6 +678,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
5,
@ -720,6 +750,11 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
2,
@ -791,6 +826,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
4,
@ -850,6 +888,11 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
dependencies: [],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
1,
@ -921,6 +964,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
6,
@ -980,6 +1026,11 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
dependencies: [],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
3,
@ -1051,6 +1102,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
},
}"#]],
@ -1126,6 +1180,9 @@ fn cargo_hello_world_project_model() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
5,
@ -1197,6 +1254,11 @@ fn cargo_hello_world_project_model() {
},
],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
2,
@ -1268,6 +1330,9 @@ fn cargo_hello_world_project_model() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
4,
@ -1329,6 +1394,11 @@ fn cargo_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
1,
@ -1400,6 +1470,9 @@ fn cargo_hello_world_project_model() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
6,
@ -1461,6 +1534,11 @@ fn cargo_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: CratesIo {
repo: Some(
"https://github.com/rust-lang/libc",
),
},
},
CrateId(
3,
@ -1532,6 +1610,9 @@ fn cargo_hello_world_project_model() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
},
}"#]],
@ -1583,6 +1664,7 @@ fn rust_project_hello_world_project_model() {
},
],
proc_macro: [],
origin: Lang,
},
CrateId(
10,
@ -1611,6 +1693,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
7,
@ -1639,6 +1722,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
4,
@ -1677,6 +1761,7 @@ fn rust_project_hello_world_project_model() {
},
],
proc_macro: [],
origin: Lang,
},
CrateId(
1,
@ -1705,6 +1790,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
11,
@ -1770,6 +1856,9 @@ fn rust_project_hello_world_project_model() {
},
],
proc_macro: [],
origin: CratesIo {
repo: None,
},
},
CrateId(
8,
@ -1798,6 +1887,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
5,
@ -1826,6 +1916,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
2,
@ -1854,6 +1945,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
9,
@ -1882,6 +1974,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
CrateId(
6,
@ -1992,6 +2085,7 @@ fn rust_project_hello_world_project_model() {
},
],
proc_macro: [],
origin: Lang,
},
CrateId(
3,
@ -2020,6 +2114,7 @@ fn rust_project_hello_world_project_model() {
},
dependencies: [],
proc_macro: [],
origin: Lang,
},
},
}"#]],

View file

@ -6,7 +6,8 @@ use std::{collections::VecDeque, fmt, fs, process::Command};
use anyhow::{format_err, Context, Result};
use base_db::{
CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, FileId, ProcMacro,
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
FileId, ProcMacro,
};
use cfg::{CfgDiff, CfgOptions};
use paths::{AbsPath, AbsPathBuf};
@ -473,6 +474,11 @@ fn project_json_to_crate_graph(
cfg_options,
env,
proc_macro.unwrap_or_default(),
if krate.display_name.is_some() {
CrateOrigin::CratesIo { repo: krate.repository.clone() }
} else {
CrateOrigin::Unknown
},
),
)
})
@ -681,6 +687,7 @@ fn detached_files_to_crate_graph(
cfg_options.clone(),
Env::default(),
Vec::new(),
CrateOrigin::Unknown,
);
public_deps.add(detached_file_crate, &mut crate_graph);
@ -821,7 +828,6 @@ fn add_target_crate_root(
.iter()
.map(|feat| CfgFlag::KeyValue { key: "feature".into(), value: feat.0.into() }),
);
crate_graph.add_crate_root(
file_id,
edition,
@ -831,6 +837,7 @@ fn add_target_crate_root(
potential_cfg_options,
env,
proc_macro,
CrateOrigin::CratesIo { repo: pkg.repository.clone() },
)
}
@ -874,6 +881,7 @@ fn sysroot_to_crate_graph(
cfg_options.clone(),
env,
proc_macro,
CrateOrigin::Lang,
);
Some((krate, crate_id))
})