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: Regions based on indent #5260
Conversation
Previously, we were not always changing region based on indent correctly. Also, for vals/defs/... defined directly in package, we have to look inside module class.
@@ -64,7 +68,7 @@ object SemanticdbSymbols: | |||
.alternatives | |||
.iterator | |||
.map(_.symbol) | |||
.filter(sym => symbolName(sym) == s) | |||
// .filter(sym => symbolName(sym) == s) |
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.
Turns out this line was actually needed for overloaded methods 😅
Basically, the problem is: For code like
// Filename: Main.scala
package a:
def fooBar(x: Int) = x + 1
def foobar(x: String) = x.length
Semanticdb contains names
a/Main$package.fooBar().
a/Main$package.fooBar(+1).
But MtagsIndexer
creates names
a/fooBar().
a/fooBar(+1).
So I have to fix it in the indexer
98fd8f7
to
ae15600
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.
I added some comments explaining changes
@@ -128,7 +135,8 @@ class ScalaToplevelMtags( | |||
if (dialect.allowSignificantIndentation) { | |||
data.token match { | |||
case WHITESPACE | COMMENT => region | |||
case _ => exitIndented(region, indent) | |||
case _ => |
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 were not always changing owner correctly when escaping indent
@@ -185,7 +192,7 @@ class ScalaToplevelMtags( | |||
withOwner(currRegion.owner) { | |||
term(name.name, name.pos, Kind.METHOD, EXTENSION) | |||
} | |||
loop(indent, isAfterNewline = false, region, newExpectIgnoreBody) | |||
loop(indent, isAfterNewline = false, currRegion, newExpectIgnoreBody) |
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 should always use currRegion
instead of region
, to account for regions based on indent
override def isExtension = extension | ||
|
||
override val withTermOwner: String => InBrace = termOwner => |
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.
Previously, withTermOwner(newOwner)
had no effect, which was very confusing
def acceptMembers: Boolean = | ||
owner.endsWith("/") | ||
val produceSourceToplevel: Boolean = false | ||
val produceSourceToplevel: Boolean = termOwner.isPackage |
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.
After adding <filename>$package
, termOwner is no longer a package, so this suffix is not added again, and its being removed when leaving this package. Previously this logic was based on global mutable variable, which wasn't changed after escaping a package
@@ -87,8 +87,8 @@ trait PCSuite { | |||
|
|||
private def addSourceToIndex(filename: String, code2: String): Unit = { | |||
val file = tmp.resolve(filename) | |||
Files.createDirectories(file.toNIO.getParent) |
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 test CompletionFilenameSuite.paths
ae15600
to
b8d51d9
Compare
b8d51d9
to
8d4fb6a
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.
This is awesome, it seems you caught a few issues there.
I think that it could be also useful to add an analogue of ToplevelSuite
for Mtags.toplevels
(not in this PR but in general), to see if any of those cases are not handled properly.
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.
Great work! 🚀
|package b: | ||
| def main: Unit = incre@@ | ||
|""".stripMargin, | ||
"""|increment3: Int |
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.
Any dea why this isn't ordered? Not important for this PR though
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.
increment3
is a val
, the other two are def
s, I think this causes this ordering
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.
Great work! 🚀
solves #5241
The problem was not connected to packages being in the same file, but to
extensions
being defined in package at the toplevel. This PR contains multiple fixes:val/def/extension/...
defined insidepackage
, their owner ismodule class <filename>$package$
, not the package directly, so ininverseSemanticdbSymbol
, we have to look insidemodule class
es too.