Skip to content

Conversation

@jonas-schievink
Copy link
Contributor

Fixes #4836

Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but I think we shouldn't be using hir::Path here. To constcut hir::Path you need to know hygine info, and that's not something IDE should now about (hopefully :) )

I think just threading ast::Path everywhere should work. You'll need compare_paths(lhs: &ast::Path, rhs: &ast::Path) -> bool function, but it shoudn't be hard to do (and I think already is implemented in merge_use_items intention?)

));
// Now that we've brought the name into scope, re-qualify all paths that could be
// affected (that is, all paths inside the node we added the `use` to).
let hir_path = match hir::Path::from_ast(path.clone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like it should either be ModPath, or maybe even ast::Path?

utils::{find_insert_use_container, insert_use_statement},
AssistContext, AssistId, Assists,
};
use either::Either;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be with other extern crates.

None => return,
};
let mut rewriter = SyntaxRewriter::default();
match container {
Copy link
Contributor

Choose a reason for hiding this comment

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

I belive there's a combinator to map Either<A, B> to T which you can use to avoid duplicate arms.

}

/// Adds replacements to `re` that shorten `path` in all descendants of `node`.
fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) {
fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) {

We generely try to use verbose names.

p: &ast::Path,
path: &ModPath,
) -> Option<()> {
let hir_path = hir::Path::from_ast(p.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

hir::Path::from_ast should really die in flames. It's a broken API, because it can't take hygiene into account. There's only a couple of calls to this function from IDE, and we probably should find ways to remove them.

fn replaces_all_affected_paths() {
check_assist(
replace_qualified_name_with_use,
"
Copy link
Contributor

@matklad matklad Jun 15, 2020

Choose a reason for hiding this comment

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

We generally use raw literals here, even if that's not required, because they get syntax higlighting.

@matklad
Copy link
Contributor

matklad commented Jun 15, 2020

@matklad
Copy link
Contributor

matklad commented Jun 16, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 16, 2020

@bors bors bot merged commit 83a16e8 into rust-lang:master Jun 16, 2020
@lnicola

This comment has been minimized.

@jonas-schievink
Copy link
Contributor Author

Does that test assists?

@lnicola
Copy link
Member

lnicola commented Jun 21, 2020

Ah, sorry, that was #4849. Not sure how I ended up on the wrong PR.

@jonas-schievink jonas-schievink deleted the replace-all-paths branch June 21, 2020 10:02
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.

"Replace qualified path with use" should replace all paths in the module

3 participants