Skip to content

Commit 45c7caa

Browse files
committed
Declare semanticHighlighting_* as local
1 parent 5c063b9 commit 45c7caa

File tree

2 files changed

+63
-75
lines changed

2 files changed

+63
-75
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 56 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -342,42 +342,6 @@ config_data! {
342342
/// available on a nightly build.
343343
rustfmt_rangeFormatting_enable: bool = "false",
344344

345-
/// Inject additional highlighting into doc comments.
346-
///
347-
/// When enabled, rust-analyzer will highlight rust source in doc comments as well as intra
348-
/// doc links.
349-
semanticHighlighting_doc_comment_inject_enable: bool = "true",
350-
/// Whether the server is allowed to emit non-standard tokens and modifiers.
351-
semanticHighlighting_nonStandardTokens: bool = "true",
352-
/// Use semantic tokens for operators.
353-
///
354-
/// When disabled, rust-analyzer will emit semantic tokens only for operator tokens when
355-
/// they are tagged with modifiers.
356-
semanticHighlighting_operator_enable: bool = "true",
357-
/// Use specialized semantic tokens for operators.
358-
///
359-
/// When enabled, rust-analyzer will emit special token types for operator tokens instead
360-
/// of the generic `operator` token type.
361-
semanticHighlighting_operator_specialization_enable: bool = "false",
362-
/// Use semantic tokens for punctuation.
363-
///
364-
/// When disabled, rust-analyzer will emit semantic tokens only for punctuation tokens when
365-
/// they are tagged with modifiers or have a special role.
366-
semanticHighlighting_punctuation_enable: bool = "false",
367-
/// When enabled, rust-analyzer will emit a punctuation semantic token for the `!` of macro
368-
/// calls.
369-
semanticHighlighting_punctuation_separate_macro_bang: bool = "false",
370-
/// Use specialized semantic tokens for punctuation.
371-
///
372-
/// When enabled, rust-analyzer will emit special token types for punctuation tokens instead
373-
/// of the generic `punctuation` token type.
374-
semanticHighlighting_punctuation_specialization_enable: bool = "false",
375-
/// Use semantic tokens for strings.
376-
///
377-
/// In some editors (e.g. vscode) semantic tokens override other highlighting grammars.
378-
/// By disabling semantic tokens for strings, other grammars can be used to highlight
379-
/// their contents.
380-
semanticHighlighting_strings_enable: bool = "true",
381345

382346
/// Show full signature of the callable. Only shows parameters if disabled.
383347
signatureInfo_detail: SignatureDetail = "\"full\"",
@@ -575,6 +539,43 @@ config_data! {
575539
joinLines_removeTrailingComma: bool = "true",
576540
/// Join lines unwraps trivial blocks.
577541
joinLines_unwrapTrivialBlock: bool = "true",
542+
543+
/// Inject additional highlighting into doc comments.
544+
///
545+
/// When enabled, rust-analyzer will highlight rust source in doc comments as well as intra
546+
/// doc links.
547+
semanticHighlighting_doc_comment_inject_enable: bool = "true",
548+
/// Whether the server is allowed to emit non-standard tokens and modifiers.
549+
semanticHighlighting_nonStandardTokens: bool = "true",
550+
/// Use semantic tokens for operators.
551+
///
552+
/// When disabled, rust-analyzer will emit semantic tokens only for operator tokens when
553+
/// they are tagged with modifiers.
554+
semanticHighlighting_operator_enable: bool = "true",
555+
/// Use specialized semantic tokens for operators.
556+
///
557+
/// When enabled, rust-analyzer will emit special token types for operator tokens instead
558+
/// of the generic `operator` token type.
559+
semanticHighlighting_operator_specialization_enable: bool = "false",
560+
/// Use semantic tokens for punctuation.
561+
///
562+
/// When disabled, rust-analyzer will emit semantic tokens only for punctuation tokens when
563+
/// they are tagged with modifiers or have a special role.
564+
semanticHighlighting_punctuation_enable: bool = "false",
565+
/// When enabled, rust-analyzer will emit a punctuation semantic token for the `!` of macro
566+
/// calls.
567+
semanticHighlighting_punctuation_separate_macro_bang: bool = "false",
568+
/// Use specialized semantic tokens for punctuation.
569+
///
570+
/// When enabled, rust-analyzer will emit special token types for punctuation tokens instead
571+
/// of the generic `punctuation` token type.
572+
semanticHighlighting_punctuation_specialization_enable: bool = "false",
573+
/// Use semantic tokens for strings.
574+
///
575+
/// In some editors (e.g. vscode) semantic tokens override other highlighting grammars.
576+
/// By disabling semantic tokens for strings, other grammars can be used to highlight
577+
/// their contents.
578+
semanticHighlighting_strings_enable: bool = "true",
578579
}
579580
}
580581

@@ -903,6 +904,25 @@ impl<'a> LocalConfigView<'a> {
903904
join_assignments: self.local.joinLines_joinAssignments,
904905
}
905906
}
907+
908+
pub fn highlighting_non_standard_tokens(&self) -> bool {
909+
self.local.semanticHighlighting_nonStandardTokens
910+
}
911+
912+
pub fn highlighting_config(&self) -> HighlightConfig {
913+
HighlightConfig {
914+
strings: self.local.semanticHighlighting_strings_enable,
915+
punctuation: self.local.semanticHighlighting_punctuation_enable,
916+
specialize_punctuation: self
917+
.local
918+
.semanticHighlighting_punctuation_specialization_enable,
919+
macro_bang: self.local.semanticHighlighting_punctuation_separate_macro_bang,
920+
operator: self.local.semanticHighlighting_operator_enable,
921+
specialize_operator: self.local.semanticHighlighting_operator_specialization_enable,
922+
inject_doc_comment: self.local.semanticHighlighting_doc_comment_inject_enable,
923+
syntactic_name_ref_highlighting: false,
924+
}
925+
}
906926
}
907927

908928
type ParallelCachePrimingNumThreads = u8;
@@ -1792,39 +1812,6 @@ impl Config {
17921812
}
17931813
}
17941814

1795-
pub fn highlighting_non_standard_tokens(&self) -> bool {
1796-
self.root_config.global.0.semanticHighlighting_nonStandardTokens
1797-
}
1798-
1799-
pub fn highlighting_config(&self) -> HighlightConfig {
1800-
HighlightConfig {
1801-
strings: self.root_config.global.0.semanticHighlighting_strings_enable,
1802-
punctuation: self.root_config.global.0.semanticHighlighting_punctuation_enable,
1803-
specialize_punctuation: self
1804-
.root_config
1805-
.global
1806-
.0
1807-
.semanticHighlighting_punctuation_specialization_enable,
1808-
macro_bang: self
1809-
.root_config
1810-
.global
1811-
.0
1812-
.semanticHighlighting_punctuation_separate_macro_bang,
1813-
operator: self.root_config.global.0.semanticHighlighting_operator_enable,
1814-
specialize_operator: self
1815-
.root_config
1816-
.global
1817-
.0
1818-
.semanticHighlighting_operator_specialization_enable,
1819-
inject_doc_comment: self
1820-
.root_config
1821-
.global
1822-
.0
1823-
.semanticHighlighting_doc_comment_inject_enable,
1824-
syntactic_name_ref_highlighting: false,
1825-
}
1826-
}
1827-
18281815
pub fn workspace_symbol(&self) -> WorkspaceSymbolConfig {
18291816
WorkspaceSymbolConfig {
18301817
search_scope: match self.root_config.global.0.workspace_symbol_search_scope {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ pub(crate) fn handle_semantic_tokens_full(
15921592
let text = snap.analysis.file_text(file_id)?;
15931593
let line_index = snap.file_line_index(file_id)?;
15941594

1595-
let mut highlight_config = snap.config.highlighting_config();
1595+
let mut highlight_config = snap.config.localize_by_file_id(file_id).highlighting_config();
15961596
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
15971597
highlight_config.syntactic_name_ref_highlighting =
15981598
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
@@ -1603,7 +1603,7 @@ pub(crate) fn handle_semantic_tokens_full(
16031603
&line_index,
16041604
highlights,
16051605
snap.config.semantics_tokens_augments_syntax_tokens(),
1606-
snap.config.highlighting_non_standard_tokens(),
1606+
snap.config.localize_by_file_id(file_id).highlighting_non_standard_tokens(),
16071607
);
16081608

16091609
// Unconditionally cache the tokens
@@ -1622,7 +1622,7 @@ pub(crate) fn handle_semantic_tokens_full_delta(
16221622
let text = snap.analysis.file_text(file_id)?;
16231623
let line_index = snap.file_line_index(file_id)?;
16241624

1625-
let mut highlight_config = snap.config.highlighting_config();
1625+
let mut highlight_config = snap.config.localize_by_file_id(file_id).highlighting_config();
16261626
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
16271627
highlight_config.syntactic_name_ref_highlighting =
16281628
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
@@ -1633,7 +1633,7 @@ pub(crate) fn handle_semantic_tokens_full_delta(
16331633
&line_index,
16341634
highlights,
16351635
snap.config.semantics_tokens_augments_syntax_tokens(),
1636-
snap.config.highlighting_non_standard_tokens(),
1636+
snap.config.localize_by_file_id(file_id).highlighting_non_standard_tokens(),
16371637
);
16381638

16391639
let cached_tokens = snap.semantic_tokens_cache.lock().remove(&params.text_document.uri);
@@ -1665,7 +1665,8 @@ pub(crate) fn handle_semantic_tokens_range(
16651665
let text = snap.analysis.file_text(frange.file_id)?;
16661666
let line_index = snap.file_line_index(frange.file_id)?;
16671667

1668-
let mut highlight_config = snap.config.highlighting_config();
1668+
let mut highlight_config =
1669+
snap.config.localize_by_file_id(frange.file_id).highlighting_config();
16691670
// Avoid flashing a bunch of unresolved references when the proc-macro servers haven't been spawned yet.
16701671
highlight_config.syntactic_name_ref_highlighting =
16711672
snap.workspaces.is_empty() || !snap.proc_macros_loaded;
@@ -1676,7 +1677,7 @@ pub(crate) fn handle_semantic_tokens_range(
16761677
&line_index,
16771678
highlights,
16781679
snap.config.semantics_tokens_augments_syntax_tokens(),
1679-
snap.config.highlighting_non_standard_tokens(),
1680+
snap.config.localize_by_file_id(frange.file_id).highlighting_non_standard_tokens(),
16801681
);
16811682
Ok(Some(semantic_tokens.into()))
16821683
}

0 commit comments

Comments
 (0)