Skip to content

Commit 4e76e88

Browse files
committed
correct hover for items with doc attribute with raw strings
1 parent 8b3c851 commit 4e76e88

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

crates/ide/src/hover.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,33 @@ fn main() { }
637637
);
638638
}
639639

640+
#[test]
641+
fn hover_shows_fn_doc_attr_raw_string() {
642+
check(
643+
r##"
644+
#[doc = r#"Raw string doc attr"#]
645+
pub fn foo<|>(_: &Path) {}
646+
647+
fn main() { }
648+
"##,
649+
expect![[r##"
650+
*foo*
651+
652+
```rust
653+
test
654+
```
655+
656+
```rust
657+
pub fn foo(_: &Path)
658+
```
659+
660+
---
661+
662+
Raw string doc attr
663+
"##]],
664+
);
665+
}
666+
640667
#[test]
641668
fn hover_shows_struct_field_info() {
642669
// Hovering over the field when instantiating

crates/syntax/src/ast/node_ext.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use itertools::Itertools;
77
use parser::SyntaxKind;
88

99
use crate::{
10-
ast::{self, support, AstNode, NameOwner, SyntaxNode},
10+
ast::{self, support, token_ext::HasStringValue, AstNode, AstToken, NameOwner, SyntaxNode},
1111
SmolStr, SyntaxElement, SyntaxToken, T,
1212
};
1313

@@ -53,8 +53,16 @@ impl ast::Attr {
5353
pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> {
5454
let lit = self.literal()?;
5555
let key = self.simple_name()?;
56-
// FIXME: escape? raw string?
57-
let value = lit.syntax().first_token()?.text().trim_matches('"').into();
56+
let value_token = lit.syntax().first_token()?;
57+
58+
let value: SmolStr = if let Some(s) = ast::String::cast(value_token.clone()) {
59+
s.value()?.into()
60+
} else if let Some(s) = ast::RawString::cast(value_token) {
61+
s.value()?.into()
62+
} else {
63+
return None;
64+
};
65+
5866
Some((key, value))
5967
}
6068

0 commit comments

Comments
 (0)