Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct hover text for items with doc attribute with raw strings #6331

Merged
merged 1 commit into from Oct 24, 2020

Conversation

JoshMcguigan
Copy link
Contributor

@JoshMcguigan JoshMcguigan commented Oct 23, 2020

Fixes #6300 by improving the handling of raw string literals in attribute style doc comments.

This still has a bug where it could consume too many " at the start or end of the comment text, just as the original code had. Not sure if we want to fix that as part of this PR or not? If so, I think I'd prefer to add a unit test for either the as_simple_key_value function (I'm not exactly sure where this would belong / how to set this up) or create a fn(&SmolStr) -> &SmolStr to unit test by factoring out the trim operations from as_simple_key_value. Thoughts on this?

@@ -53,8 +53,21 @@ 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have "correct" way to do this implemented: https://github.com/rust-analyzer/rust-analyzer/blob/ea25ae614b21237c4a536304da875bdc29f0c65a/crates/syntax/src/ast/token_ext.rs#L149

We can just ast::String::cast our way to victory here, but, ideally, we should improve the API surrounding string literals somewhat: #6308

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out! I've updated this to cast to ast::String/ast::RawString then use the value method.

I did take a look at #6308 but I think that would take a bit more time than I have right now. But I understand if you'd rather handle this after that, so feel free to close this PR if so.

Thanks for the review!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

bors r+

@lnicola lnicola added the hacktoberfest-accepted Hacktoberfest accepted PR label Oct 24, 2020
@bors
Copy link
Contributor

bors bot commented Oct 24, 2020

@bors bors bot merged commit bf84e49 into rust-lang:master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Hacktoberfest accepted PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hover includes raw string prefix
3 participants