mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Add a setting for keyword hover popups
This commit is contained in:
parent
b6fae56e38
commit
0616cee92b
7 changed files with 57 additions and 10 deletions
|
@ -27,6 +27,7 @@ use crate::{
|
||||||
pub struct HoverConfig {
|
pub struct HoverConfig {
|
||||||
pub links_in_hover: bool,
|
pub links_in_hover: bool,
|
||||||
pub documentation: Option<HoverDocFormat>,
|
pub documentation: Option<HoverDocFormat>,
|
||||||
|
pub keywords: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HoverConfig {
|
impl HoverConfig {
|
||||||
|
|
|
@ -230,7 +230,7 @@ pub(super) fn keyword(
|
||||||
config: &HoverConfig,
|
config: &HoverConfig,
|
||||||
token: &SyntaxToken,
|
token: &SyntaxToken,
|
||||||
) -> Option<HoverResult> {
|
) -> Option<HoverResult> {
|
||||||
if !token.kind().is_keyword() || !config.documentation.is_some() {
|
if !token.kind().is_keyword() || !config.documentation.is_some() || !config.keywords {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let parent = token.parent()?;
|
let parent = token.parent()?;
|
||||||
|
|
|
@ -8,7 +8,11 @@ fn check_hover_no_result(ra_fixture: &str) {
|
||||||
let (analysis, position) = fixture::position(ra_fixture);
|
let (analysis, position) = fixture::position(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
|
&HoverConfig {
|
||||||
|
links_in_hover: true,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -20,7 +24,11 @@ fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, position) = fixture::position(ra_fixture);
|
let (analysis, position) = fixture::position(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
|
&HoverConfig {
|
||||||
|
links_in_hover: true,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -37,7 +45,11 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, position) = fixture::position(ra_fixture);
|
let (analysis, position) = fixture::position(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
|
&HoverConfig {
|
||||||
|
links_in_hover: false,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -54,7 +66,11 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, position) = fixture::position(ra_fixture);
|
let (analysis, position) = fixture::position(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::PlainText) },
|
&HoverConfig {
|
||||||
|
links_in_hover: true,
|
||||||
|
documentation: Some(HoverDocFormat::PlainText),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -71,7 +87,11 @@ fn check_actions(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
|
let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
|
&HoverConfig {
|
||||||
|
links_in_hover: true,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
FileRange { file_id, range: position.range_or_empty() },
|
FileRange { file_id, range: position.range_or_empty() },
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -83,7 +103,11 @@ fn check_hover_range(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, range) = fixture::range(ra_fixture);
|
let (analysis, range) = fixture::range(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
|
&HoverConfig {
|
||||||
|
links_in_hover: false,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
range,
|
range,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -95,7 +119,11 @@ fn check_hover_range_no_results(ra_fixture: &str) {
|
||||||
let (analysis, range) = fixture::range(ra_fixture);
|
let (analysis, range) = fixture::range(ra_fixture);
|
||||||
let hover = analysis
|
let hover = analysis
|
||||||
.hover(
|
.hover(
|
||||||
&HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
|
&HoverConfig {
|
||||||
|
links_in_hover: false,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
},
|
||||||
range,
|
range,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -130,8 +130,11 @@ impl StaticIndex<'_> {
|
||||||
syntax::NodeOrToken::Node(_) => None,
|
syntax::NodeOrToken::Node(_) => None,
|
||||||
syntax::NodeOrToken::Token(x) => Some(x),
|
syntax::NodeOrToken::Token(x) => Some(x),
|
||||||
});
|
});
|
||||||
let hover_config =
|
let hover_config = HoverConfig {
|
||||||
HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) };
|
links_in_hover: true,
|
||||||
|
documentation: Some(HoverDocFormat::Markdown),
|
||||||
|
keywords: true,
|
||||||
|
};
|
||||||
let tokens = tokens.filter(|token| {
|
let tokens = tokens.filter(|token| {
|
||||||
matches!(
|
matches!(
|
||||||
token.kind(),
|
token.kind(),
|
||||||
|
|
|
@ -244,6 +244,9 @@ config_data! {
|
||||||
|
|
||||||
/// Whether to show documentation on hover.
|
/// Whether to show documentation on hover.
|
||||||
hover_documentation_enable: bool = "true",
|
hover_documentation_enable: bool = "true",
|
||||||
|
/// Whether to show keyword hover popups. Only applies when
|
||||||
|
/// `#rust-analyzer.hover.documentation.enable#` is set.
|
||||||
|
hover_documentation_keywords: bool = "true",
|
||||||
/// Use markdown syntax for links in hover.
|
/// Use markdown syntax for links in hover.
|
||||||
hover_links_enable: bool = "true",
|
hover_links_enable: bool = "true",
|
||||||
|
|
||||||
|
@ -1187,6 +1190,7 @@ impl Config {
|
||||||
HoverDocFormat::PlainText
|
HoverDocFormat::PlainText
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
keywords: self.data.hover_documentation_keywords,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,6 +318,12 @@ Whether to show `Run` action. Only applies when
|
||||||
--
|
--
|
||||||
Whether to show documentation on hover.
|
Whether to show documentation on hover.
|
||||||
--
|
--
|
||||||
|
[[rust-analyzer.hover.documentation.keywords]]rust-analyzer.hover.documentation.keywords (default: `true`)::
|
||||||
|
+
|
||||||
|
--
|
||||||
|
Whether to show keyword hover popups. Only applies when
|
||||||
|
`#rust-analyzer.hover.documentation.enable#` is set.
|
||||||
|
--
|
||||||
[[rust-analyzer.hover.links.enable]]rust-analyzer.hover.links.enable (default: `true`)::
|
[[rust-analyzer.hover.links.enable]]rust-analyzer.hover.links.enable (default: `true`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
|
|
@ -756,6 +756,11 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.hover.documentation.keywords": {
|
||||||
|
"markdownDescription": "Whether to show keyword hover popups. Only applies when\n`#rust-analyzer.hover.documentation.enable#` is set.",
|
||||||
|
"default": true,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"rust-analyzer.hover.links.enable": {
|
"rust-analyzer.hover.links.enable": {
|
||||||
"markdownDescription": "Use markdown syntax for links in hover.",
|
"markdownDescription": "Use markdown syntax for links in hover.",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
|
Loading…
Reference in a new issue