Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Update Racer and Rustfmt #1123

Merged
merged 4 commits into from
Nov 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 60 additions & 80 deletions Cargo.lock
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ languageserver-types = "0.45"
lazy_static = "1"
log = "0.4"
num_cpus = "1"
racer = { version = "=2.1.9", default-features = false }
racer = { version = "=2.1.13", default-features = false }
rand = "0.5.5"
rayon = "1"
rls-analysis = "0.16.6"
@@ -32,7 +32,7 @@ rls-rustc = "0.5.0"
rls-span = { version = "0.4", features = ["serialize-serde"] }
rls-vfs = "0.7"
rustc_tools_util = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "d8b426901a75b1eb975f52b4537f2736f2b94436" }
rustfmt-nightly = "0.99.6"
rustfmt-nightly = "0.99.9"
rustc-serialize = "0.3"
serde = "1.0"
serde_json = "1.0"
49 changes: 28 additions & 21 deletions src/actions/hover.rs
Original file line number Diff line number Diff line change
@@ -613,27 +613,34 @@ fn collapse_parents(path: PathBuf) -> PathBuf {
/// `None` if the coordinates are not available on the match.
fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def> {
use racer::MatchType;
let kind = match m.mtype {
MatchType::Struct(_) => DefKind::Struct,
MatchType::Module => DefKind::Mod,
MatchType::MatchArm => DefKind::Local,
MatchType::Function | MatchType::Method(_) => DefKind::Function,
MatchType::Crate => DefKind::Mod,
MatchType::Let
| MatchType::IfLet(_)
| MatchType::WhileLet(_)
| MatchType::For(_) => DefKind::Local,
MatchType::StructField => DefKind::Field,
MatchType::Enum(_) => DefKind::Enum,
MatchType::EnumVariant(_) => DefKind::StructVariant,
MatchType::Type | MatchType::TypeParameter(_) => DefKind::Type,
MatchType::FnArg => DefKind::Local,
MatchType::Trait => DefKind::Trait,
MatchType::Const => DefKind::Const,
MatchType::Static => DefKind::Static,
MatchType::Macro => DefKind::Macro,
MatchType::Builtin(_) => DefKind::Macro,
};
fn to_def_kind(kind: &MatchType) -> DefKind {
match kind {
MatchType::Struct(_) => DefKind::Struct,
MatchType::Module => DefKind::Mod,
MatchType::MatchArm => DefKind::Local,
MatchType::Function | MatchType::Method(_) => DefKind::Function,
MatchType::Crate => DefKind::Mod,
MatchType::Let(_)
| MatchType::IfLet(_)
| MatchType::WhileLet(_)
| MatchType::For(_) => DefKind::Local,
MatchType::StructField => DefKind::Field,
MatchType::Enum(_) => DefKind::Enum,
MatchType::EnumVariant(_) => DefKind::StructVariant,
MatchType::Type | MatchType::TypeParameter(_) | MatchType::AssocType => DefKind::Type,
MatchType::FnArg(_) => DefKind::Local,
MatchType::Trait => DefKind::Trait,
MatchType::Const => DefKind::Const,
MatchType::Static => DefKind::Static,
MatchType::Macro => DefKind::Macro,
MatchType::Builtin(_) => DefKind::Macro,
MatchType::UseAlias(m) => match m.mtype {
MatchType::UseAlias(_) => unreachable!("Nested use aliases"),
_ => to_def_kind(&m.mtype),
},
}
}
let kind = to_def_kind(&m.mtype);

let contextstr = if kind == DefKind::Mod {
use std::env;
9 changes: 7 additions & 2 deletions src/lsp_data.rs
Original file line number Diff line number Diff line change
@@ -206,11 +206,11 @@ pub fn completion_kind_from_match_type(m: racer::MatchType) -> CompletionItemKin
racer::MatchType::Macro
| racer::MatchType::Function
| racer::MatchType::Method(_)
| racer::MatchType::FnArg => CompletionItemKind::Function,
| racer::MatchType::FnArg(_) => CompletionItemKind::Function,
racer::MatchType::Type | racer::MatchType::Trait => {
CompletionItemKind::Interface
}
racer::MatchType::Let
racer::MatchType::Let(_)
| racer::MatchType::IfLet(_)
| racer::MatchType::WhileLet(_)
| racer::MatchType::For(_)
@@ -219,6 +219,11 @@ pub fn completion_kind_from_match_type(m: racer::MatchType) -> CompletionItemKin
| racer::MatchType::Static => CompletionItemKind::Variable,
racer::MatchType::TypeParameter(_) => CompletionItemKind::TypeParameter,
racer::MatchType::Builtin(_) => CompletionItemKind::Keyword,
racer::MatchType::UseAlias(m) => match m.mtype {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kngwyu do I understand that in this case, we have use X as Y and we match on Y but m here refers to X and we can derive the completion kind from that instead? (also nested/recursive case seems to be impossible?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's impossible too but haven't tested it yet.

racer::MatchType::UseAlias(_) => unreachable!("Nested use aliases"),
typ @ _ => completion_kind_from_match_type(typ),
}
racer::MatchType::AssocType => CompletionItemKind::TypeParameter,
}
}

42 changes: 42 additions & 0 deletions src/project_model.rs
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ pub struct Package(usize);
struct PackageData {
lib: Option<(PathBuf, String)>,
deps: Vec<Dep>,
edition: racer::Edition,
}

#[derive(Debug)]
@@ -83,6 +84,10 @@ impl ProjectModel {
// racer expect name 'underscored'(crate) name
.map(|t| (t.src_path().path().to_owned(), t.name().replace('-', "_"))),
deps: Vec::new(),
edition: match cargo_pkg.manifest().edition() {
cargo::core::Edition::Edition2015 => racer::Edition::Ed2015,
cargo::core::Edition::Edition2018 => racer::Edition::Ed2018,
},
});
manifest_to_id.insert(manifest, pkg);
}
@@ -133,6 +138,31 @@ impl Package {
pub struct RacerProjectModel(pub Arc<ProjectModel>);

impl racer::ProjectModelProvider for RacerProjectModel {
fn edition(&self, manifest: &Path) -> Option<racer::Edition> {
self.0
.package_for_manifest(manifest)
.map(|pkg| self.0.get(pkg).edition)
}

fn search_dependencies(
&self,
manifest: &Path,
search_fn: Box<dyn Fn(&str) -> bool>,
) -> Vec<(String, PathBuf)> {
let pkg = match self.0.package_for_manifest(manifest) {
Some(pkg) => pkg,
None => return vec![],
};

pkg.deps(&self.0)
.iter()
.filter(|d| search_fn(&d.crate_name))
.filter_map(|d| self.0.get(d.pkg).lib.as_ref())
.cloned()
.map(|(src_path, crate_name)| (crate_name, src_path))
.collect()
}

fn discover_project_manifest(&self, path: &Path) -> Option<PathBuf> {
match find_root_manifest_for_wd(path) {
Ok(val) => Some(val),
@@ -164,6 +194,18 @@ impl racer::ProjectModelProvider for RacerProjectModel {
pub struct RacerFallbackModel;

impl racer::ProjectModelProvider for RacerFallbackModel {
fn edition(&self, _manifest: &Path) -> Option<racer::Edition> {
None
}

fn search_dependencies(
&self,
_manifest: &Path,
_search_fn: Box<dyn Fn(&str) -> bool>,
) -> Vec<(String, PathBuf)> {
Vec::new()
}

fn discover_project_manifest(&self, _path: &Path) -> Option<PathBuf> {
None
}