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: (Scala3) Don't navigate to enclosing symbols on go-to-definition if cursor is not on symbol #3807
fix: (Scala3) Don't navigate to enclosing symbols on go-to-definition if cursor is not on symbol #3807
Conversation
* ``` | ||
* @param path - path to the position given by `Interactive.pathTo` | ||
*/ | ||
def isOnName( |
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 from HoverProvider.scala
def contains(tree: Tree): Boolean = tree match | ||
case select: Select => | ||
// using `nameSpan` as SourceTree for Select (especially symbolic-infix e.g. `::` of `1 :: Nil`) miscalculate positions | ||
select.nameSpan.contains(sourcePos.span) |
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.
Added this case
StdNames.nme.flatMap, | ||
StdNames.nme.foreach | ||
) | ||
def isForSynthetic(gtree: Tree)(using Context): Boolean = |
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.
Scala3 version of
metals/mtags/src/main/scala-2/scala/meta/internal/pc/HoverProvider.scala
Lines 308 to 324 in 35efaad
lazy val isForName: Set[Name] = Set[Name]( | |
nme.map, | |
nme.withFilter, | |
nme.flatMap, | |
nme.foreach | |
) | |
def isForSynthetic(gtree: Tree): Boolean = { | |
def isForComprehensionSyntheticName(select: Select): Boolean = { | |
select.pos == select.qualifier.pos && isForName(select.name) | |
} | |
gtree match { | |
case Apply(fun, List(_: Function)) => isForSynthetic(fun) | |
case TypeApply(fun, _) => isForSynthetic(fun) | |
case gtree: Select if isForComprehensionSyntheticName(gtree) => true | |
case _ => false | |
} | |
} |
@@ -429,4 +415,40 @@ class PcDefinitionSuite extends BasePcDefinitionSuite { | |||
|""".stripMargin | |||
) | |||
) | |||
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.
Copied from #3743
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! @tanishiking could you rebase the changes?
0f20821
to
bbfc7e4
Compare
Thank you for reviewing! rebased, merging after CI passed. |
#1707
Basically the same strategy as #3792
But this PR checks
isOnName
insideenclosingSymbols
because this Metals-version ofenclosingSymbols
well deals with synthetic symbols like for-flatMap and caseclass-apply. We checkisOnName
only if it's not on synthetic symbols or special cases (e.g.NameArg
andImport
).Maybe we can make hover (for Scala3) better using this Metals-version of
enclosingSymbols
and it handles the issue #3792 (comment)Remained issues around
go-to-definition
and hover are