Skip to content

Commit

Permalink
Make package objects present in source
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishiking committed Jul 26, 2021
1 parent c0e7b88 commit 4f60d9f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ class ExtractSemanticDB extends Phase:
if content.lift(span.end - 1).map(_ == '`').getOrElse(false) then
(span.start + 1, span.end - 1)
else (span.start, span.end)
content.slice(start, end).mkString == sym.name.stripModuleClassSuffix.lastPart.toString
val target = if sym.isPackageObject then sym.owner else sym
content.slice(start, end).mkString == target.name.stripModuleClassSuffix.lastPart.toString

private def spanOfSymbol(sym: Symbol, span: Span, treeSource: SourceFile)(using Context): Span =
val contents = if treeSource.exists then treeSource.content() else Array.empty[Char]
Expand Down
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/EndMarkers2.expect.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package object endmarkers2:
package object endmarkers2/*<-endmarkers2::package.*/:

type Foo/*<-endmarkers2::package.Foo#*/ =
Unit/*->scala::Unit#*/
end Foo/*->endmarkers2::package.Foo#*/

end endmarkers2
end endmarkers2/*->endmarkers2::package.*/
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/semanticdb-Flags.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package flags

import scala.language/*->scala::language.*/.experimental/*->scala::language.experimental.*/.macros/*->scala::language.experimental.macros.*/

package object p {
package object p/*<-flags::p::package.*/ {
private lazy val x/*<-flags::p::package.x.*/ = 1
protected implicit var y/*<-flags::p::package.y().*/: Int/*->scala::Int#*/ = 2
def z/*<-flags::p::package.z().*/(pp/*<-flags::p::package.z().(pp)*/: Int/*->scala::Int#*/) = 3
Expand Down
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/toplevel.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ def combine/*<-_empty_::toplevel$package.combine(+1).*/(x/*<-_empty_::toplevel$p
def combine/*<-_empty_::toplevel$package.combine(+2).*/ = 0
def foo/*<-_empty_::toplevel$package.foo().*/ = "foo"
@main/*->scala::main#*/ def MyProgram/*<-_empty_::toplevel$package.MyProgram().*/(times/*<-_empty_::toplevel$package.MyProgram().(times)*/: Int/*->scala::Int#*/): Unit/*->scala::Unit#*/ = (1 to/*->scala::runtime::RichInt#to().*/ times/*->_empty_::toplevel$package.MyProgram().(times)*/) foreach/*->scala::collection::immutable::Range#foreach().*/ (_ => println/*->scala::Predef.println(+1).*/("hello"))
def fooRef/*<-_empty_::toplevel$package.fooRef().*/ = toplevel$package/*->_empty_::toplevel$package.*/.foo/*->_empty_::toplevel$package.foo().*/
def fooRef/*<-_empty_::toplevel$package.fooRef().*/ = toplevel$package.foo/*->_empty_::toplevel$package.foo().*/
10 changes: 6 additions & 4 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -734,16 +734,18 @@ Uri => EndMarkers2.scala
Text => empty
Language => Scala
Symbols => 2 entries
Occurrences => 3 entries
Occurrences => 5 entries

Symbols:
endmarkers2/package. => final package object endmarkers2 extends Object { self: endmarkers2.type => +2 decls }
endmarkers2/package.Foo# => type Foo = Unit

Occurrences:
[0:15..0:26): endmarkers2 <- endmarkers2/package.
[2:7..2:10): Foo <- endmarkers2/package.Foo#
[3:4..3:8): Unit -> scala/Unit#
[4:6..4:9): Foo -> endmarkers2/package.Foo#
[6:4..6:15): endmarkers2 -> endmarkers2/package.

expect/EnumVal.scala
--------------------
Expand Down Expand Up @@ -3877,7 +3879,7 @@ Uri => semanticdb-Flags.scala
Text => empty
Language => Scala
Symbols => 50 entries
Occurrences => 70 entries
Occurrences => 71 entries

Symbols:
flags/p/package. => final package object p extends Object { self: p.type => +23 decls }
Expand Down Expand Up @@ -3937,6 +3939,7 @@ Occurrences:
[2:13..2:21): language -> scala/language.
[2:22..2:34): experimental -> scala/language.experimental.
[2:35..2:41): macros -> scala/language.experimental.macros.
[4:15..4:16): p <- flags/p/package.
[5:2..5:3): p -> flags/p/
[5:19..5:20): x <- flags/p/package.x.
[6:25..6:26): y <- flags/p/package.y().
Expand Down Expand Up @@ -4447,7 +4450,7 @@ Uri => toplevel.scala
Text => empty
Language => Scala
Symbols => 19 entries
Occurrences => 35 entries
Occurrences => 34 entries

Symbols:
_empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls }
Expand Down Expand Up @@ -4504,6 +4507,5 @@ Occurrences:
[5:53..5:60): foreach -> scala/collection/immutable/Range#foreach().
[5:67..5:74): println -> scala/Predef.println(+1).
[6:4..6:10): fooRef <- _empty_/toplevel$package.fooRef().
[6:13..6:29): toplevel$package -> _empty_/toplevel$package.
[6:30..6:33): foo -> _empty_/toplevel$package.foo().

0 comments on commit 4f60d9f

Please sign in to comment.