-
Notifications
You must be signed in to change notification settings - Fork 326
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
Use DefinitionProvider instead of index in RenameProvider #1637
Conversation
…e we always get the definition for Dotty
val symbolOccurence = | ||
definitionProvider.symbolOccurrence(source, params.getPosition) | ||
for { | ||
(occurence, _) <- symbolOccurence |
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.
rename symbolOccurence
-> symbolOccurrence
let's fix this once and for all in this file 💪
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.
Fixed
a little unrelated but when I looked at
in second |
} | ||
|
||
private def symbolIsLocal(symbol: String): Boolean = { | ||
private def symbolIsLocal( |
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.
maybe we could rename it to isLocalSymbol
?
also inside it is symbol.startsWith("local")
but we can simply reuse symbol.isLocal
which is performing exactly this check.
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.
fixed, but renamed isWorkspaceSymbol
isLocal | ||
} | ||
def isFromWorkspace = { | ||
val isLocal = definitionPath.isWorkspaceSource(workspace) |
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.
for me isLocal
has a meaning that symbol is localXXX
(anonymous in a given file) and here we talk about isInWorkspace
?
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.
Changed to isInWorkspace
@@ -267,7 +279,11 @@ final class RenameProvider( | |||
} | |||
} | |||
|
|||
private def canRenameSymbol(symbol: String, newName: Option[String]) = { | |||
private def canRenameSymbol( | |||
symbol: String, |
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.
I think you try to bind symbol with AbsolutePath and propagate them together through multiple functions, maybe it is worth making case class containing those 2 things and just pass one thing. Also it will be easier to see this path is related to this 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.
Okay actually I would go with symbol <-> List[AbsolutePath] as it looks like there can be multiple definitions of a symbol. This would fix a problem with <-
above
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.
And then you can decide in symbolIsLocal
if given symbol with all definition locations is local or not.
Previously we did .exists
which means at least one location must be in workspace, but maybe .all
would make more sense here?
I don't know many multi def locations examples, is it only class/trait + object scenario?
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.
I don't think we have multiple definitions anywhere currently really. And even if we get one, I can't imagine one being inside workspace and the other outside.
I can rework it a bit, but I don't think we need to add a case class just for 2 methods.
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.
Moved isWorkspaceSymbol
up, so that we don't propagate the path now.
includeSynthetics = includeSynthetic | ||
val allReferences = for { | ||
(occurence, semanticDb) <- symbolOccurence.toIterable | ||
definitionLoc <- definition.locations.asScala |
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.
I would not go with <-
here as it means if you get more locations all references and will be calculated twice for each location
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.
I should most likely go with headOption, but we don't have really currently a situation with multiple definitions.
From what I see you basically replace
|
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.
(Some comments might not be directly related to changes in code in this PR, ignore if you feel like unrelated)
DefProvider does it already, uses index to locate the SemanticDB with the definition and then searches that SemanticDB. If it's not available there then we fallaback to PC
It might make sense, but before Dotty this wasn't needed. We might need to go through all the functionalities and confirm they're working sensibly in all scenarios. |
d9f4dd5
to
cc52b2d
Compare
cc52b2d
to
fc20da6
Compare
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.
LGTM 👍
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.
LGTM too
(occurence, semanticDb) <- symbolOccurrence.toIterable | ||
definitionLoc <- definition.locations.asScala.headOption.toIterable | ||
definitionPath = definitionLoc.getUri().toAbsolutePath | ||
if canRenameSymbol(occurence.symbol, Option(newName)) && |
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.
OPT: same than Some(newName)
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.
Will fix it maybe next time, shouldn't be a big issue.
Previously, we would use GlobalSymbolIndex, which might not always work for Scala 3 in case of non-parsable code. Now, we use the definitionProvider, which will in turn ask the PresentationCompiler if the definition is missing. For Scala 2 it will still work mostly the same.
The test might fail locally due to issue being fixed scalacenter/bloop#1253, which makes the test fail on even tries 😅