Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Don't insert imports when method calls are created through searcher #1209

Merged
merged 18 commits into from
Mar 8, 2021

Conversation

mwu-tow
Copy link
Contributor

@mwu-tow mwu-tow commented Feb 17, 2021

Pull Request Description

When method call is inserted as a suggestion from searcher, the import of the relevant module won't be added anymore.
It is not needed and may cause trouble with name collisions, like #1145.
Issue #1178

Important Notes

Checklist

Please include the following checklist in your PR:

  • The CHANGELOG.md was updated with the changes introduced in this PR.
  • The documentation has been updated if necessary.
  • All code conforms to the Rust style guide.
  • All code has automatic tests where possible.
  • All code has been profiled where possible.
  • All code has been manually tested in the IDE.
  • All code has been manually tested in the "debug/interface" scene.
  • All code has been manually tested by the PR owner against our test scenarios.
  • All code has been manually tested by at least one reviewer against our test scenarios.

@mwu-tow mwu-tow requested a review from farmaazon February 17, 2021 09:47
@mwu-tow mwu-tow self-assigned this Feb 17, 2021
@mwu-tow mwu-tow changed the title Wip/mwu/no import for methods 1178 Don't insert imports when method calls are created through searcher Feb 17, 2021
@mwu-tow mwu-tow marked this pull request as ready for review February 17, 2021 14:54
@mwu-tow mwu-tow requested a review from wdanilo as a code owner February 17, 2021 14:54
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@farmaazon farmaazon left a comment

Choose a reason for hiding this comment

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

Unfortunately, the reality is more complex than I expected. Actually there is scenario which works wrong with the current solution: press tab without any node selected, pick Table.new and press enter.

the new is a method, but it is a method of not imported module "Table". So actually we should skip importing only when we pick a method for this argument.

@kustosz
Copy link

kustosz commented Feb 18, 2021

@farmaazon @mwu-tow it's even more complex! Even if you have the this, some methods are extension methods. For an example, Json.to_table is a method in defined Table, even though Json comes from Base. So the rule for "import is not necessary" is:

  1. The method being called comes from the same module as this. In this case, never import.
  2. The method being called comes from a different module than this. Then check if the method's module is already imported and don't import if it aready is.

@farmaazon
Copy link
Collaborator

As for point 2: in scope of this task is only checking if we literally have the same import (as we do with other suggestions).

@kustosz
Copy link

kustosz commented Feb 18, 2021

@farmaazon sure, point 1 is the most important one, because it could lead you towards overoptimization – i.e. not importing extension methods, which would break programs (and not just make them ugly by too many imports)

@kustosz
Copy link

kustosz commented Feb 18, 2021

I have not read this code btw. it's very possible you've already taken everything into account :P Just saw this discussion and randomly commented

@farmaazon
Copy link
Collaborator

No, no, the point 1 in your comment is important (cc @mwu), and no, we don't handle it in our code.

@mwu-tow mwu-tow marked this pull request as draft February 19, 2021 13:46
@mwu-tow mwu-tow marked this pull request as ready for review February 23, 2021 15:01
@farmaazon farmaazon self-requested a review February 24, 2021 15:45
Copy link
Collaborator

@farmaazon farmaazon left a comment

Choose a reason for hiding this comment

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

Please, update the branch so I could easily test it with all new changes.

src/rust/ide/src/model/suggestion_database/entry.rs Outdated Show resolved Hide resolved
src/rust/ide/src/model/suggestion_database/entry.rs Outdated Show resolved Hide resolved
src/rust/ide/src/model/suggestion_database/entry.rs Outdated Show resolved Hide resolved
@mwu-tow mwu-tow requested a review from farmaazon March 5, 2021 13:37
@wdanilo wdanilo merged commit fef2e4f into develop Mar 8, 2021
@wdanilo wdanilo deleted the wip/mwu/no-import-for-methods-1178 branch April 3, 2021 07:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants