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

Commit e1aafa7

Browse files
authored
Merge pull request #1152 from alexheretic/fail-back-to-racer-def
Fallback to racer definition
2 parents 1a6361b + 2d16f79 commit e1aafa7

File tree

4 files changed

+28
-43
lines changed

4 files changed

+28
-43
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

+22-39
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::*;
@@ -204,45 +202,30 @@ impl RequestAction for Definition {
204202
let span = ctx.convert_pos_to_span(file_path.clone(), params.position);
205203
let analysis = ctx.analysis.clone();
206204

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

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)