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

Commit a6af35b

Browse files
committed
Fallback to racer definition
* Runs racer find_definition if analysis goto has failed and `racer_completion` config is enabled. This brings the functionality in line with hover. * Removed `goto_def_racer_fallback`. * Ignore clippy large enum lint in `BuildPlan`
1 parent 9ddbb5a commit a6af35b

File tree

4 files changed

+21
-39
lines changed

4 files changed

+21
-39
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Currently we accept the following options:
117117
features
118118
* `racer_completion` (`bool`, defaults to `true`) enables code completion using
119119
racer (which is, at the moment, our only code completion backend). Also enables
120-
hover tooltips to fall back to racer when save-analysis data is unavailable.
120+
hover tooltips & go-to-definition to fall back to racer when save-analysis data is unavailable.
121121
* `clippy_preference` (`String`, defaults to `"opt-in"`) controls eagerness of clippy
122122
diagnostics when available. Valid values are _(case-insensitive)_:
123123
- `"off"` Disable clippy lints.

src/actions/requests.rs

+15-35
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use url::Url;
2424

2525
use crate::actions::hover;
2626
use crate::actions::run::collect_run_actions;
27-
use crate::actions::work_pool;
28-
use crate::actions::work_pool::WorkDescription;
2927
use crate::build::Edition;
3028
use crate::lsp_data;
3129
use crate::lsp_data::*;
@@ -203,45 +201,27 @@ impl RequestAction for Definition {
203201
let span = ctx.convert_pos_to_span(file_path.clone(), params.position);
204202
let analysis = ctx.analysis.clone();
205203

206-
// If configured start racer concurrently and fallback to racer result
207-
let racer_receiver = {
208-
if ctx.config.lock().unwrap().goto_def_racer_fallback {
209-
Some(work_pool::receive_from_thread(
210-
move || {
211-
let cache = ctx.racer_cache();
212-
let session = ctx.racer_session(&cache);
213-
let location = pos_to_racer_location(params.position);
214-
215-
racer::find_definition(file_path, location, &session)
216-
.and_then(|rm| location_from_racer_match(&rm))
217-
},
218-
WorkDescription("textDocument/definition-racer"),
219-
))
220-
} else {
221-
None
222-
}
223-
};
224-
225204
match analysis.goto_def(&span) {
226205
Ok(out) => {
227206
let result = vec![ls_util::rls_to_location(&out)];
228207
trace!("goto_def (compiler): {:?}", result);
229208
Ok(result)
230209
}
231-
_ => match racer_receiver {
232-
Some(receiver) => match receiver.recv() {
233-
Ok(Some(r)) => {
234-
trace!("goto_def (Racer): {:?}", r);
235-
Ok(vec![r])
236-
}
237-
Ok(None) => {
238-
trace!("goto_def (Racer): None");
239-
Ok(vec![])
240-
}
241-
_ => Self::fallback_response(),
242-
},
243-
_ => Self::fallback_response(),
244-
},
210+
// If analysis failed & `racer_completion` is enabled try racer
211+
_ if ctx.config.lock().unwrap().racer_completion => {
212+
let cache = ctx.racer_cache();
213+
let session = ctx.racer_session(&cache);
214+
let location = pos_to_racer_location(params.position);
215+
216+
let r = racer::find_definition(file_path, location, &session)
217+
.and_then(|rm| location_from_racer_match(&rm))
218+
.map(|l| vec![l])
219+
.unwrap_or_default();
220+
221+
trace!("goto_def (Racer): {:?}", r);
222+
Ok(r)
223+
}
224+
_ => Self::fallback_response(),
245225
}
246226
}
247227
}

src/build/plan.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ crate enum WorkStatus {
5353
Execute(JobQueue),
5454
}
5555

56+
#[allow(clippy::large_enum_variant)]
5657
#[derive(Debug)]
5758
crate enum BuildPlan {
5859
External(ExternalPlan),

src/config.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ pub struct Config {
127127
pub unstable_features: bool,
128128
pub wait_to_build: Option<u64>,
129129
pub show_warnings: bool,
130-
pub goto_def_racer_fallback: bool,
131130
/// Clear the RUST_LOG env variable before calling rustc/cargo? Default: true
132131
pub clear_env_rust_log: bool,
133132
/// Build the project only when a file got saved and not on file change. Default: false
@@ -140,7 +139,10 @@ pub struct Config {
140139
pub no_default_features: bool,
141140
pub jobs: Option<u32>,
142141
pub all_targets: bool,
143-
/// Enable use of racer for `textDocument/completion` requests
142+
/// Enable use of racer for `textDocument/completion` requests.
143+
///
144+
/// Enabled also enables racer fallbacks for hover & go-to-definition functionality
145+
/// if rustc analysis should fail.
144146
pub racer_completion: bool,
145147
#[serde(deserialize_with = "deserialize_clippy_preference")]
146148
pub clippy_preference: ClippyPreference,
@@ -177,7 +179,6 @@ impl Default for Config {
177179
unstable_features: false,
178180
wait_to_build: None,
179181
show_warnings: true,
180-
goto_def_racer_fallback: false,
181182
clear_env_rust_log: true,
182183
build_on_save: false,
183184
use_crate_blacklist: true,

0 commit comments

Comments
 (0)