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

Fallback to racer definition #1152

Merged
merged 2 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Currently we accept the following options:
features
* `racer_completion` (`bool`, defaults to `true`) enables code completion using
racer (which is, at the moment, our only code completion backend). Also enables
hover tooltips to fall back to racer when save-analysis data is unavailable.
hover tooltips & go-to-definition to fall back to racer when save-analysis data is unavailable.
* `clippy_preference` (`String`, defaults to `"opt-in"`) controls eagerness of clippy
diagnostics when available. Valid values are _(case-insensitive)_:
- `"off"` Disable clippy lints.
Expand Down
61 changes: 22 additions & 39 deletions src/actions/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use url::Url;

use crate::actions::hover;
use crate::actions::run::collect_run_actions;
use crate::actions::work_pool;
use crate::actions::work_pool::WorkDescription;
use crate::build::Edition;
use crate::lsp_data;
use crate::lsp_data::*;
Expand Down Expand Up @@ -203,45 +201,30 @@ impl RequestAction for Definition {
let span = ctx.convert_pos_to_span(file_path.clone(), params.position);
let analysis = ctx.analysis.clone();

// If configured start racer concurrently and fallback to racer result
let racer_receiver = {
if ctx.config.lock().unwrap().goto_def_racer_fallback {
Some(work_pool::receive_from_thread(
move || {
let cache = ctx.racer_cache();
let session = ctx.racer_session(&cache);
let location = pos_to_racer_location(params.position);

racer::find_definition(file_path, location, &session)
.and_then(|rm| location_from_racer_match(&rm))
},
WorkDescription("textDocument/definition-racer"),
))
if let Ok(out) = analysis.goto_def(&span) {
let result = vec![ls_util::rls_to_location(&out)];
trace!("goto_def (compiler): {:?}", result);
Ok(result)
} else {
let racer_enabled = {
let config = ctx.config.lock().unwrap();
config.racer_completion
};
if racer_enabled {
let cache = ctx.racer_cache();
let session = ctx.racer_session(&cache);
let location = pos_to_racer_location(params.position);

let r = racer::find_definition(file_path, location, &session)
.and_then(|rm| location_from_racer_match(&rm))
.map(|l| vec![l])
.unwrap_or_default();

trace!("goto_def (Racer): {:?}", r);
Ok(r)
} else {
None
Self::fallback_response()
}
};

match analysis.goto_def(&span) {
Ok(out) => {
let result = vec![ls_util::rls_to_location(&out)];
trace!("goto_def (compiler): {:?}", result);
Ok(result)
}
_ => match racer_receiver {
Some(receiver) => match receiver.recv() {
Ok(Some(r)) => {
trace!("goto_def (Racer): {:?}", r);
Ok(vec![r])
}
Ok(None) => {
trace!("goto_def (Racer): None");
Ok(vec![])
}
_ => Self::fallback_response(),
},
_ => Self::fallback_response(),
},
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/build/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ crate enum WorkStatus {
Execute(JobQueue),
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
crate enum BuildPlan {
External(ExternalPlan),
Expand Down
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub struct Config {
pub unstable_features: bool,
pub wait_to_build: Option<u64>,
pub show_warnings: bool,
pub goto_def_racer_fallback: bool,
/// Clear the RUST_LOG env variable before calling rustc/cargo? Default: true
pub clear_env_rust_log: bool,
/// Build the project only when a file got saved and not on file change. Default: false
Expand All @@ -140,7 +139,10 @@ pub struct Config {
pub no_default_features: bool,
pub jobs: Option<u32>,
pub all_targets: bool,
/// Enable use of racer for `textDocument/completion` requests
/// Enable use of racer for `textDocument/completion` requests.
///
/// Enabled also enables racer fallbacks for hover & go-to-definition functionality
/// if rustc analysis should fail.
pub racer_completion: bool,
#[serde(deserialize_with = "deserialize_clippy_preference")]
pub clippy_preference: ClippyPreference,
Expand Down Expand Up @@ -177,7 +179,6 @@ impl Default for Config {
unstable_features: false,
wait_to_build: None,
show_warnings: true,
goto_def_racer_fallback: false,
clear_env_rust_log: true,
build_on_save: false,
use_crate_blacklist: true,
Expand Down