-
Notifications
You must be signed in to change notification settings - Fork 337
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: use alternative with stripped synthetic filename$package.
#7000
Conversation
018f323
to
86fdb34
Compare
mtags/src/main/scala/scala/meta/internal/metals/Docstrings.scala
Outdated
Show resolved
Hide resolved
@@ -26,6 +29,27 @@ object DefinitionAlternatives { | |||
Some(sym.owner -> sym.value.desc) | |||
} | |||
|
|||
private def stripSyntheticPackageObjectFromObject( |
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.
Do we need to validate this? Could there be an option where we have both object with the $package prefix and without?
And if we really need to we should have something like:
case class Alternative(private val symbol: Symbol, validation: (loc: SymbolLocation) => Boolean = true) {
def symbol(loc: SymbolLocation) = {
if (validation(loc)) Some(symbol)
else None
}
}
this way we make sure that Validation is not ignored at any point
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 we can skip it... One would have to specifically create an object / package object called something$package
(where I think that $
is generally reserved for the compiler) and still this is only a fallback...
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.
Let's maybe skip it then.
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.
Nice idea! LGTM aside from the small nitpick
@@ -224,7 +224,7 @@ class SymbolIndexBucket( | |||
if (!definitions.contains(symbol.value)) { | |||
// Fallback 3: guess related symbols from the enclosing class. | |||
DefinitionAlternatives(symbol) | |||
.flatMap(alternative => query0(querySymbol, alternative)) | |||
.flatMap { case (alternative) => query0(querySymbol, alternative) } |
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.
This is not needed now I think
fixes: #6852
Root cause of the problem
A toplevel object that is a companion for a top-level type has a synthetic parent -
filename$package
. This is not reflected by Metals symbol indexer (ScalaMtags
). It would be problematic, since the the type definition might be after the object definitionExample
For this code:
Symbols in compiler and what is in semanticDB is
Where Metals symbol indexer produces:
Solution
filename$package
to alternatives in definition search