Skip to content

Commit 3e17039

Browse files
committed
Declare highlightRelated_* as local
1 parent 259e233 commit 3e17039

File tree

2 files changed

+82
-79
lines changed

2 files changed

+82
-79
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,6 @@ config_data! {
297297
/// Controls file watching implementation.
298298
files_watcher: FilesWatcherDef = "\"client\"",
299299

300-
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
301-
highlightRelated_breakPoints_enable: bool = "true",
302-
/// Enables highlighting of all captures of a closure while the cursor is on the `|` or move keyword of a closure.
303-
highlightRelated_closureCaptures_enable: bool = "true",
304-
/// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
305-
highlightRelated_exitPoints_enable: bool = "true",
306-
/// Enables highlighting of related references while the cursor is on any identifier.
307-
highlightRelated_references_enable: bool = "true",
308-
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
309-
highlightRelated_yieldPoints_enable: bool = "true",
310300

311301
/// Whether to show `Debug` action. Only applies when
312302
/// `#rust-analyzer.hover.actions.enable#` is set.
@@ -506,6 +496,16 @@ config_data! {
506496

507497
config_data! {
508498
struct LocalConfigData {
499+
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
500+
highlightRelated_breakPoints_enable: bool = "true",
501+
/// Enables highlighting of all captures of a closure while the cursor is on the `|` or move keyword of a closure.
502+
highlightRelated_closureCaptures_enable: bool = "true",
503+
/// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
504+
highlightRelated_exitPoints_enable: bool = "true",
505+
/// Enables highlighting of related references while the cursor is on any identifier.
506+
highlightRelated_references_enable: bool = "true",
507+
/// Enables highlighting of all break points for a loop or block context while the cursor is on any `async` or `await` keywords.
508+
highlightRelated_yieldPoints_enable: bool = "true",
509509

510510
/// Whether to show inlay type hints for binding modes.
511511
inlayHints_bindingModeHints_enable: bool = "false",
@@ -670,6 +670,46 @@ pub struct LocalConfigView<'a> {
670670
}
671671

672672
impl<'a> LocalConfigView<'a> {
673+
pub fn assist(&self) -> AssistConfig {
674+
AssistConfig {
675+
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
676+
allowed: None,
677+
insert_use: self.insert_use_config(),
678+
prefer_no_std: self.local.imports_prefer_no_std,
679+
assist_emit_must_use: self.global.0.assist_emitMustUse,
680+
}
681+
}
682+
683+
pub fn completion(&self) -> CompletionConfig {
684+
CompletionConfig {
685+
enable_postfix_completions: self.global.0.completion_postfix_enable,
686+
enable_imports_on_the_fly: self.global.0.completion_autoimport_enable
687+
&& completion_item_edit_resolve(&self.caps),
688+
enable_self_on_the_fly: self.global.0.completion_autoself_enable,
689+
enable_private_editable: self.global.0.completion_privateEditable_enable,
690+
full_function_signatures: self.global.0.completion_fullFunctionSignatures_enable,
691+
callable: match self.global.0.completion_callable_snippets {
692+
CallableCompletionDef::FillArguments => Some(CallableSnippets::FillArguments),
693+
CallableCompletionDef::AddParentheses => Some(CallableSnippets::AddParentheses),
694+
CallableCompletionDef::None => None,
695+
},
696+
insert_use: self.insert_use_config(),
697+
prefer_no_std: self.local.imports_prefer_no_std,
698+
snippet_cap: SnippetCap::new(try_or_def!(
699+
self.caps
700+
.text_document
701+
.as_ref()?
702+
.completion
703+
.as_ref()?
704+
.completion_item
705+
.as_ref()?
706+
.snippet_support?
707+
)),
708+
snippets: self.snippets.clone().to_vec(),
709+
limit: self.global.0.completion_limit,
710+
}
711+
}
712+
673713
pub fn diagnostics(&self) -> DiagnosticsConfig {
674714
DiagnosticsConfig {
675715
enabled: self.global.0.diagnostics_enable,
@@ -685,35 +725,24 @@ impl<'a> LocalConfigView<'a> {
685725
prefer_no_std: self.local.imports_prefer_no_std,
686726
}
687727
}
728+
pub fn expand_proc_attr_macros(&self) -> bool {
729+
self.global.0.procMacro_enable && self.global.0.procMacro_attributes_enable
730+
}
688731

689-
pub fn assist(&self) -> AssistConfig {
690-
AssistConfig {
691-
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
692-
allowed: None,
693-
insert_use: self.insert_use_config(),
694-
prefer_no_std: self.local.imports_prefer_no_std,
695-
assist_emit_must_use: self.global.0.assist_emitMustUse,
696-
}
732+
fn experimental(&self, index: &'static str) -> bool {
733+
try_or_def!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?)
697734
}
698735

699-
fn insert_use_config(&self) -> InsertUseConfig {
700-
InsertUseConfig {
701-
granularity: match self.local.imports_granularity_group {
702-
ImportGranularityDef::Preserve => ImportGranularity::Preserve,
703-
ImportGranularityDef::Item => ImportGranularity::Item,
704-
ImportGranularityDef::Crate => ImportGranularity::Crate,
705-
ImportGranularityDef::Module => ImportGranularity::Module,
706-
},
707-
enforce_granularity: self.local.imports_granularity_enforce,
708-
prefix_kind: match self.local.imports_prefix {
709-
ImportPrefixDef::Plain => PrefixKind::Plain,
710-
ImportPrefixDef::ByCrate => PrefixKind::ByCrate,
711-
ImportPrefixDef::BySelf => PrefixKind::BySelf,
712-
},
713-
group: self.local.imports_group_enable,
714-
skip_glob_imports: !self.local.imports_merge_glob,
736+
pub fn highlight_related(&self) -> HighlightRelatedConfig {
737+
HighlightRelatedConfig {
738+
references: self.local.highlightRelated_references_enable,
739+
break_points: self.local.highlightRelated_breakPoints_enable,
740+
exit_points: self.local.highlightRelated_exitPoints_enable,
741+
yield_points: self.local.highlightRelated_yieldPoints_enable,
742+
closure_captures: self.local.highlightRelated_closureCaptures_enable,
715743
}
716744
}
745+
717746
pub fn inlay_hints(&self) -> InlayHintsConfig {
718747
let client_capability_fields = self
719748
.caps
@@ -797,44 +826,25 @@ impl<'a> LocalConfigView<'a> {
797826
}
798827
}
799828

800-
pub fn expand_proc_attr_macros(&self) -> bool {
801-
self.global.0.procMacro_enable && self.global.0.procMacro_attributes_enable
802-
}
803-
804-
pub fn completion(&self) -> CompletionConfig {
805-
CompletionConfig {
806-
enable_postfix_completions: self.global.0.completion_postfix_enable,
807-
enable_imports_on_the_fly: self.global.0.completion_autoimport_enable
808-
&& completion_item_edit_resolve(&self.caps),
809-
enable_self_on_the_fly: self.global.0.completion_autoself_enable,
810-
enable_private_editable: self.global.0.completion_privateEditable_enable,
811-
full_function_signatures: self.global.0.completion_fullFunctionSignatures_enable,
812-
callable: match self.global.0.completion_callable_snippets {
813-
CallableCompletionDef::FillArguments => Some(CallableSnippets::FillArguments),
814-
CallableCompletionDef::AddParentheses => Some(CallableSnippets::AddParentheses),
815-
CallableCompletionDef::None => None,
829+
fn insert_use_config(&self) -> InsertUseConfig {
830+
InsertUseConfig {
831+
granularity: match self.local.imports_granularity_group {
832+
ImportGranularityDef::Preserve => ImportGranularity::Preserve,
833+
ImportGranularityDef::Item => ImportGranularity::Item,
834+
ImportGranularityDef::Crate => ImportGranularity::Crate,
835+
ImportGranularityDef::Module => ImportGranularity::Module,
816836
},
817-
insert_use: self.insert_use_config(),
818-
prefer_no_std: self.local.imports_prefer_no_std,
819-
snippet_cap: SnippetCap::new(try_or_def!(
820-
self.caps
821-
.text_document
822-
.as_ref()?
823-
.completion
824-
.as_ref()?
825-
.completion_item
826-
.as_ref()?
827-
.snippet_support?
828-
)),
829-
snippets: self.snippets.clone().to_vec(),
830-
limit: self.global.0.completion_limit,
837+
enforce_granularity: self.local.imports_granularity_enforce,
838+
prefix_kind: match self.local.imports_prefix {
839+
ImportPrefixDef::Plain => PrefixKind::Plain,
840+
ImportPrefixDef::ByCrate => PrefixKind::ByCrate,
841+
ImportPrefixDef::BySelf => PrefixKind::BySelf,
842+
},
843+
group: self.local.imports_group_enable,
844+
skip_glob_imports: !self.local.imports_merge_glob,
831845
}
832846
}
833847

834-
fn experimental(&self, index: &'static str) -> bool {
835-
try_or_def!(self.caps.experimental.as_ref()?.get(index)?.as_bool()?)
836-
}
837-
838848
pub fn join_lines(&self) -> JoinLinesConfig {
839849
JoinLinesConfig {
840850
join_else_if: self.local.joinLines_joinElseIf,
@@ -1876,16 +1886,6 @@ impl Config {
18761886
}
18771887
}
18781888

1879-
pub fn highlight_related(&self) -> HighlightRelatedConfig {
1880-
HighlightRelatedConfig {
1881-
references: self.root_config.global.0.highlightRelated_references_enable,
1882-
break_points: self.root_config.global.0.highlightRelated_breakPoints_enable,
1883-
exit_points: self.root_config.global.0.highlightRelated_exitPoints_enable,
1884-
yield_points: self.root_config.global.0.highlightRelated_yieldPoints_enable,
1885-
closure_captures: self.root_config.global.0.highlightRelated_closureCaptures_enable,
1886-
}
1887-
}
1888-
18891889
pub fn prime_caches_num_threads(&self) -> u8 {
18901890
match self.root_config.global.0.cachePriming_numThreads {
18911891
0 => num_cpus::get_physical().try_into().unwrap_or(u8::MAX),

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,10 @@ pub(crate) fn handle_document_highlight(
13651365
let position = from_proto::file_position(&snap, params.text_document_position_params)?;
13661366
let line_index = snap.file_line_index(position.file_id)?;
13671367

1368-
let refs = match snap.analysis.highlight_related(snap.config.highlight_related(), position)? {
1368+
let refs = match snap.analysis.highlight_related(
1369+
snap.config.localize_by_file_id(position.file_id).highlight_related(),
1370+
position,
1371+
)? {
13691372
None => return Ok(None),
13701373
Some(refs) => refs,
13711374
};

0 commit comments

Comments
 (0)