From 4e76e884bd74430223919f29d49d7ae9710b48cf Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Thu, 22 Oct 2020 20:43:07 -0700 Subject: correct hover for items with doc attribute with raw strings --- crates/syntax/src/ast/node_ext.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'crates/syntax/src/ast') diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 50c1c157d..c5cd1c504 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -7,7 +7,7 @@ use itertools::Itertools; use parser::SyntaxKind; use crate::{ - ast::{self, support, AstNode, NameOwner, SyntaxNode}, + ast::{self, support, token_ext::HasStringValue, AstNode, AstToken, NameOwner, SyntaxNode}, SmolStr, SyntaxElement, SyntaxToken, T, }; @@ -53,8 +53,16 @@ impl ast::Attr { pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> { let lit = self.literal()?; let key = self.simple_name()?; - // FIXME: escape? raw string? - let value = lit.syntax().first_token()?.text().trim_matches('"').into(); + let value_token = lit.syntax().first_token()?; + + let value: SmolStr = if let Some(s) = ast::String::cast(value_token.clone()) { + s.value()?.into() + } else if let Some(s) = ast::RawString::cast(value_token) { + s.value()?.into() + } else { + return None; + }; + Some((key, value)) } -- cgit v1.2.3