Skip to content

Commit 8fa8bf1

Browse files
committed
Auto merge of rust-lang#13037 - jonas-schievink:keyword-hover-setting, r=jonas-schievink
feat: Add a setting for keyword hover popups This adds `rust-analyzer.hover.documentation.keywords.enable`, which defaults to `true` and can be turned off to disable the keyword documentation hover popups, which can be somewhat distracting when triggered by accident, and offer relatively little value if you're already familiar with the language. Fixes rust-lang/rust-analyzer#12950
2 parents b6fae56 + 7fb7c24 commit 8fa8bf1

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

crates/ide/src/hover.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::{
2727
pub struct HoverConfig {
2828
pub links_in_hover: bool,
2929
pub documentation: Option<HoverDocFormat>,
30+
pub keywords: bool,
3031
}
3132

3233
impl HoverConfig {

crates/ide/src/hover/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub(super) fn keyword(
230230
config: &HoverConfig,
231231
token: &SyntaxToken,
232232
) -> Option<HoverResult> {
233-
if !token.kind().is_keyword() || !config.documentation.is_some() {
233+
if !token.kind().is_keyword() || !config.documentation.is_some() || !config.keywords {
234234
return None;
235235
}
236236
let parent = token.parent()?;

crates/ide/src/hover/tests.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ fn check_hover_no_result(ra_fixture: &str) {
88
let (analysis, position) = fixture::position(ra_fixture);
99
let hover = analysis
1010
.hover(
11-
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
11+
&HoverConfig {
12+
links_in_hover: true,
13+
documentation: Some(HoverDocFormat::Markdown),
14+
keywords: true,
15+
},
1216
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
1317
)
1418
.unwrap();
@@ -20,7 +24,11 @@ fn check(ra_fixture: &str, expect: Expect) {
2024
let (analysis, position) = fixture::position(ra_fixture);
2125
let hover = analysis
2226
.hover(
23-
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
27+
&HoverConfig {
28+
links_in_hover: true,
29+
documentation: Some(HoverDocFormat::Markdown),
30+
keywords: true,
31+
},
2432
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
2533
)
2634
.unwrap()
@@ -37,7 +45,11 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
3745
let (analysis, position) = fixture::position(ra_fixture);
3846
let hover = analysis
3947
.hover(
40-
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
48+
&HoverConfig {
49+
links_in_hover: false,
50+
documentation: Some(HoverDocFormat::Markdown),
51+
keywords: true,
52+
},
4153
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
4254
)
4355
.unwrap()
@@ -54,7 +66,11 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
5466
let (analysis, position) = fixture::position(ra_fixture);
5567
let hover = analysis
5668
.hover(
57-
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::PlainText) },
69+
&HoverConfig {
70+
links_in_hover: true,
71+
documentation: Some(HoverDocFormat::PlainText),
72+
keywords: true,
73+
},
5874
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
5975
)
6076
.unwrap()
@@ -71,7 +87,11 @@ fn check_actions(ra_fixture: &str, expect: Expect) {
7187
let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
7288
let hover = analysis
7389
.hover(
74-
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
90+
&HoverConfig {
91+
links_in_hover: true,
92+
documentation: Some(HoverDocFormat::Markdown),
93+
keywords: true,
94+
},
7595
FileRange { file_id, range: position.range_or_empty() },
7696
)
7797
.unwrap()
@@ -83,7 +103,11 @@ fn check_hover_range(ra_fixture: &str, expect: Expect) {
83103
let (analysis, range) = fixture::range(ra_fixture);
84104
let hover = analysis
85105
.hover(
86-
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
106+
&HoverConfig {
107+
links_in_hover: false,
108+
documentation: Some(HoverDocFormat::Markdown),
109+
keywords: true,
110+
},
87111
range,
88112
)
89113
.unwrap()
@@ -95,7 +119,11 @@ fn check_hover_range_no_results(ra_fixture: &str) {
95119
let (analysis, range) = fixture::range(ra_fixture);
96120
let hover = analysis
97121
.hover(
98-
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
122+
&HoverConfig {
123+
links_in_hover: false,
124+
documentation: Some(HoverDocFormat::Markdown),
125+
keywords: true,
126+
},
99127
range,
100128
)
101129
.unwrap();

crates/ide/src/static_index.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ impl StaticIndex<'_> {
130130
syntax::NodeOrToken::Node(_) => None,
131131
syntax::NodeOrToken::Token(x) => Some(x),
132132
});
133-
let hover_config =
134-
HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) };
133+
let hover_config = HoverConfig {
134+
links_in_hover: true,
135+
documentation: Some(HoverDocFormat::Markdown),
136+
keywords: true,
137+
};
135138
let tokens = tokens.filter(|token| {
136139
matches!(
137140
token.kind(),

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ config_data! {
243243
hover_actions_run_enable: bool = "true",
244244

245245
/// Whether to show documentation on hover.
246-
hover_documentation_enable: bool = "true",
246+
hover_documentation_enable: bool = "true",
247+
/// Whether to show keyword hover popups. Only applies when
248+
/// `#rust-analyzer.hover.documentation.enable#` is set.
249+
hover_documentation_keywords_enable: bool = "true",
247250
/// Use markdown syntax for links in hover.
248251
hover_links_enable: bool = "true",
249252

@@ -1187,6 +1190,7 @@ impl Config {
11871190
HoverDocFormat::PlainText
11881191
}
11891192
}),
1193+
keywords: self.data.hover_documentation_keywords_enable,
11901194
}
11911195
}
11921196

docs/user/generated_config.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ Whether to show `Run` action. Only applies when
318318
--
319319
Whether to show documentation on hover.
320320
--
321+
[[rust-analyzer.hover.documentation.keywords.enable]]rust-analyzer.hover.documentation.keywords.enable (default: `true`)::
322+
+
323+
--
324+
Whether to show keyword hover popups. Only applies when
325+
`#rust-analyzer.hover.documentation.enable#` is set.
326+
--
321327
[[rust-analyzer.hover.links.enable]]rust-analyzer.hover.links.enable (default: `true`)::
322328
+
323329
--

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,11 @@
756756
"default": true,
757757
"type": "boolean"
758758
},
759+
"rust-analyzer.hover.documentation.keywords.enable": {
760+
"markdownDescription": "Whether to show keyword hover popups. Only applies when\n`#rust-analyzer.hover.documentation.enable#` is set.",
761+
"default": true,
762+
"type": "boolean"
763+
},
759764
"rust-analyzer.hover.links.enable": {
760765
"markdownDescription": "Use markdown syntax for links in hover.",
761766
"default": true,

0 commit comments

Comments
 (0)