mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
More symbol usage
This commit is contained in:
parent
c30bdfcc84
commit
df5f1777b8
50 changed files with 388 additions and 303 deletions
|
@ -9,10 +9,10 @@
|
|||
use std::{fmt, mem, ops};
|
||||
|
||||
use cfg::CfgOptions;
|
||||
use intern::Symbol;
|
||||
use la_arena::{Arena, Idx, RawIdx};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use span::Edition;
|
||||
use syntax::SmolStr;
|
||||
use triomphe::Arc;
|
||||
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
|
||||
|
||||
|
@ -99,8 +99,8 @@ impl fmt::Debug for CrateGraph {
|
|||
|
||||
pub type CrateId = Idx<CrateData>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct CrateName(SmolStr);
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct CrateName(Symbol);
|
||||
|
||||
impl CrateName {
|
||||
/// Creates a crate name, checking for dashes in the string provided.
|
||||
|
@ -110,16 +110,16 @@ impl CrateName {
|
|||
if name.contains('-') {
|
||||
Err(name)
|
||||
} else {
|
||||
Ok(Self(SmolStr::new(name)))
|
||||
Ok(Self(Symbol::intern(name)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a crate name, unconditionally replacing the dashes with underscores.
|
||||
pub fn normalize_dashes(name: &str) -> CrateName {
|
||||
Self(SmolStr::new(name.replace('-', "_")))
|
||||
Self(Symbol::intern(&name.replace('-', "_")))
|
||||
}
|
||||
|
||||
pub fn as_smol_str(&self) -> &SmolStr {
|
||||
pub fn symbol(&self) -> &Symbol {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ impl fmt::Display for CrateName {
|
|||
impl ops::Deref for CrateName {
|
||||
type Target = str;
|
||||
fn deref(&self) -> &str {
|
||||
&self.0
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,11 +141,11 @@ impl ops::Deref for CrateName {
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum CrateOrigin {
|
||||
/// Crates that are from the rustc workspace.
|
||||
Rustc { name: String },
|
||||
Rustc { name: Symbol },
|
||||
/// Crates that are workspace members.
|
||||
Local { repo: Option<String>, name: Option<String> },
|
||||
Local { repo: Option<String>, name: Option<Symbol> },
|
||||
/// Crates that are non member libraries.
|
||||
Library { repo: Option<String>, name: String },
|
||||
Library { repo: Option<String>, name: Symbol },
|
||||
/// Crates that are provided by the language, like std, core, proc-macro, ...
|
||||
Lang(LangCrateOrigin),
|
||||
}
|
||||
|
@ -201,16 +201,16 @@ impl fmt::Display for LangCrateOrigin {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct CrateDisplayName {
|
||||
// The name we use to display various paths (with `_`).
|
||||
crate_name: CrateName,
|
||||
// The name as specified in Cargo.toml (with `-`).
|
||||
canonical_name: String,
|
||||
canonical_name: Symbol,
|
||||
}
|
||||
|
||||
impl CrateDisplayName {
|
||||
pub fn canonical_name(&self) -> &str {
|
||||
pub fn canonical_name(&self) -> &Symbol {
|
||||
&self.canonical_name
|
||||
}
|
||||
pub fn crate_name(&self) -> &CrateName {
|
||||
|
@ -220,7 +220,7 @@ impl CrateDisplayName {
|
|||
|
||||
impl From<CrateName> for CrateDisplayName {
|
||||
fn from(crate_name: CrateName) -> CrateDisplayName {
|
||||
let canonical_name = crate_name.to_string();
|
||||
let canonical_name = crate_name.0.clone();
|
||||
CrateDisplayName { crate_name, canonical_name }
|
||||
}
|
||||
}
|
||||
|
@ -239,9 +239,9 @@ impl ops::Deref for CrateDisplayName {
|
|||
}
|
||||
|
||||
impl CrateDisplayName {
|
||||
pub fn from_canonical_name(canonical_name: String) -> CrateDisplayName {
|
||||
let crate_name = CrateName::normalize_dashes(&canonical_name);
|
||||
CrateDisplayName { crate_name, canonical_name }
|
||||
pub fn from_canonical_name(canonical_name: &str) -> CrateDisplayName {
|
||||
let crate_name = CrateName::normalize_dashes(canonical_name);
|
||||
CrateDisplayName { crate_name, canonical_name: Symbol::intern(canonical_name) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue