-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix #3979: Completion for renamed imports #4977
Conversation
Rebased |
Rebased and took a stab at #5508 |
@smarter Thanks, I've addressed your comments. |
One `Completion` represents one completion results that should be included in the list of completion options. It can represent zero symbols (for instance, a wildcard import), or more than one (a class and its companion object). Each `Completion` also has a `description` which should be displayed in the tool that shows the completion candidates. Fixes scala#5508
We introduce a new `RenameAwareScope` that tracks the name associated with a symbol in the scope. Calling `toListWithNames` returns the list of symbols in this scope along with the name that should be used to refer to the symbol in this scope. Fixes scala#3979
For instance, Scala classes have a synthetic accompanying `Module` which doesn't have a corresponding source symbol. We don't want to show the `Module` in the completions.
When multiple symbols are concerned by one completion result, we show the different kinds of symbols.
@smarter The |
sym <- syms | ||
} yield (sym, name) | ||
/** Get the names that are known in this scope, along with the list of symbols they refer to. */ | ||
def mappings(implicit ctx: Context): Map[SimpleName, List[Symbol]] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't the body of this method just be equal to nameToSymbols
? (assuming def enter
above is changed to do stripModuleClassSufffix
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch. That should have been the case from the beginning, since nameToSymbold
contained exactly one symbol per name. Thanks
|
||
/** Enter the symbol `sym` in this scope, recording a potential renaming. */ | ||
def enter[T <: Symbol](sym: T, name: Name)(implicit ctx: Context): T = { | ||
nameToSymbols += name -> (sym :: nameToSymbols.getOrElse(name, Nil)) | ||
val simpleName = name.stripModuleClassSuffix.toSimpleName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come toSimpleName
is needed ? Aren't we already filtering out all non-simple-names with the completionsFilter ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, completionsFilter
filters names based on their kind (Simple
, Qualified
, Numbered
and so on), which is a different distinction from SimpleName
/ TermName
/ TypeName
as far as I can tell.
We need to do toSimpleName
here so that TermName
s and TypeName
s are grouped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, I would do toTermName
then since SimpleNames are TermNames anyway, and it means that we don't accidentally mangle encoded names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We introduce a new
RenameAwareScope
that tracks the name associatedwith a symbol in the scope. Calling
toListWithNames
returns the listof symbols in this scope along with the name that should be used to
refer to the symbol in this scope.
Fixes #3979