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

"Insert explicit type " assist fix #2869, fix typo #2877

Merged
merged 5 commits into from
Jan 20, 2020
Merged

"Insert explicit type " assist fix #2869, fix typo #2877

merged 5 commits into from
Jan 20, 2020

Conversation

to-mas-kral
Copy link
Contributor

So this was quite straightforward. I basically looked at how the other assists work and tried doing something simillar. I also fixed a typo in the other assist.

@@ -34,6 +35,14 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi
// The binding must have a name
let name = pat.name()?;
let name_range = name.syntax().text_range();
// Assist should only be applicable if cursor is between 'let' and '='
let stmt_range = stmt.syntax().text_range();
let eq_range = stmt.syntax().descendants_with_tokens().find(|t| t.kind() == EQ)?.text_range();
Copy link
Member

Choose a reason for hiding this comment

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

Let’s add an eq_token method to ast::LetStmt, so that it can be used elsewhere. There’s extensions.rs module for that

Copy link
Member

Choose a reason for hiding this comment

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

Other than this, looks good to me!


pub fn eq_token(&self) -> Option<SyntaxToken> {
self.syntax()
.descendants_with_tokens()
Copy link
Member

Choose a reason for hiding this comment

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

Oh, we should also use children instead of descendants here: descendants is recursive, and so can be much slower. Everything is ok!

bors d+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. Is there any documentation for Rowan ?

Copy link
Member

Choose a reason for hiding this comment

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

Nope :-(

Though, the API is stable-ish now, so writing docs should be a good investment. There's api_walkthoruh test which might be helpful.

@matklad
Copy link
Member

matklad commented Jan 20, 2020

bors r+

bors bot added a commit that referenced this pull request Jan 20, 2020
2877: "Insert explicit type " assist fix #2869, fix typo r=matklad a=TomasKralCZ

So this was quite straightforward. I basically looked at how the other assists work and tried doing something simillar. I also fixed a typo in the other assist.

Co-authored-by: TomasKralCZ <tomas@kral.hk>
@bors
Copy link
Contributor

bors bot commented Jan 20, 2020

Build succeeded

  • Rust (macos-latest)
  • Rust (ubuntu-latest)
  • TypeScript

@bors bors bot merged commit 72792f6 into rust-lang:master Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants