Initial commit of highlight related configuration w/ implementation.

This commit is contained in:
Kevin DeLorey 2021-07-21 19:44:16 -06:00
parent 1dd1814100
commit b75e0e7bb1
6 changed files with 78 additions and 10 deletions

View file

@ -18,6 +18,14 @@ pub struct HighlightedRange {
pub access: Option<ReferenceAccess>,
}
#[derive(Default, Clone)]
pub struct HighlightRelatedConfig {
pub references: bool,
pub exit_points: bool,
pub break_points: bool,
pub yield_points: bool,
}
// Feature: Highlight Related
//
// Highlights constructs related to the thing under the cursor:
@ -27,6 +35,7 @@ pub struct HighlightedRange {
// - if on a `break`, `loop`, `while` or `for` token, highlights all break points for that loop or block context
pub(crate) fn highlight_related(
sema: &Semantics<RootDatabase>,
config: HighlightRelatedConfig,
position: FilePosition,
) -> Option<Vec<HighlightedRange>> {
let _p = profile::span("highlight_related");
@ -46,10 +55,13 @@ pub(crate) fn highlight_related(
})?;
match token.kind() {
T![return] | T![?] | T![->] => highlight_exit_points(sema, token),
T![await] | T![async] => highlight_yield_points(token),
T![break] | T![loop] | T![for] | T![while] => highlight_break_points(token),
_ => highlight_references(sema, &syntax, position),
T![return] | T![?] | T![->] if config.exit_points => highlight_exit_points(sema, token),
T![await] | T![async] if config.yield_points => highlight_yield_points(token),
T![break] | T![loop] | T![for] | T![while] if config.break_points => {
highlight_break_points(token)
}
_ if config.references => highlight_references(sema, &syntax, position),
_ => None,
}
}
@ -261,7 +273,14 @@ mod tests {
fn check(ra_fixture: &str) {
let (analysis, pos, annotations) = fixture::annotations(ra_fixture);
let hls = analysis.highlight_related(pos).unwrap().unwrap();
let config = HighlightRelatedConfig {
break_points: true,
exit_points: true,
references: true,
yield_points: true,
};
let hls = analysis.highlight_related(config, pos).unwrap().unwrap();
let mut expected = annotations
.into_iter()