Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cat ~/.local/share/scalacli/bloop/daemon/output

rm .jvmopts
touch .jvmopts
echo "-Xss4m" >> .jvmopts
echo "-Xmx1G" >> .jvmopts
echo "-Xss4m" >> .jvmopts
echo "-Xmx2G" >> .jvmopts
echo "-XX:ReservedCodeCacheSize=1024m" >> .jvmopts
echo "-XX:+TieredCompilation" >> .jvmopts
echo "-Dfile.encoding=UTF-8" >> .jvmopts
Expand Down
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ val sharedScalacOptions = List(
)

val sharedSettings = sharedJavacOptions ++ sharedScalacOptions ++ List(
Compile / packageDoc / publishArtifact := false,
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
Expand Down Expand Up @@ -316,8 +317,6 @@ val mtagsSettings = List(
(ThisBuild / baseDirectory).value / "mtags",
scalaVersion.value,
),
// @note needed to deal with issues with dottyDoc
Compile / doc / sources := Seq.empty,
libraryDependencies ++= Seq(
"com.lihaoyi" %% "geny" % V.genyVersion,
"com.thoughtworks.qdox" % "qdox" % V.qdox, // for java mtags
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package scala.meta.internal.pc

import java.net.URI
import java.nio.file.Paths
import java.time.LocalDateTime
import java.util.ArrayList

import scala.annotation.tailrec
Expand All @@ -19,7 +21,9 @@ import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.Flags.ModuleClass
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.Interactive.Include
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.transform.SymUtils.isLocal
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import org.eclipse.lsp4j.Location
Expand Down Expand Up @@ -51,10 +55,10 @@ class PcDefinitionProvider(
given ctx: Context = driver.localContext(params)
val indexedContext = IndexedContext(ctx)
val result =
if findTypeDef then findTypeDefinitions(path, pos, indexedContext)
else findDefinitions(path, pos, indexedContext)
if findTypeDef then findTypeDefinitions(path, pos, indexedContext, uri)
else findDefinitions(path, pos, indexedContext, uri)

if result.locations().isEmpty() then fallbackToUntyped(pos)(using ctx)
if result.locations().isEmpty() then fallbackToUntyped(pos, uri)(using ctx)
else result
end definitions

Expand All @@ -70,30 +74,33 @@ class PcDefinitionProvider(
* @param pos cursor position
* @return definition result
*/
private def fallbackToUntyped(pos: SourcePosition)(using Context) =
private def fallbackToUntyped(pos: SourcePosition, uri: URI)(using Context) =
lazy val untpdPath = NavigateAST
.untypedPath(pos.span)
.collect { case t: untpd.Tree => t }

definitionsForSymbol(untpdPath.headOption.map(_.symbol).toList, pos)
definitionsForSymbol(untpdPath.headOption.map(_.symbol).toList, uri, pos)
end fallbackToUntyped

private def findDefinitions(
path: List[Tree],
pos: SourcePosition,
indexed: IndexedContext,
uri: URI,
): DefinitionResult =
import indexed.ctx
definitionsForSymbol(
MetalsInteractive.enclosingSymbols(path, pos, indexed),
pos,
uri,
pos
)
end findDefinitions

private def findTypeDefinitions(
path: List[Tree],
pos: SourcePosition,
indexed: IndexedContext,
uri: URI,
): DefinitionResult =
import indexed.ctx
val enclosing = path.expandRangeToEnclosingApply(pos)
Expand All @@ -106,25 +113,26 @@ class PcDefinitionProvider(
case Nil =>
path.headOption match
case Some(value: Literal) =>
definitionsForSymbol(List(value.tpe.widen.typeSymbol), pos)
definitionsForSymbol(List(value.tpe.widen.typeSymbol), uri, pos)
case _ => DefinitionResultImpl.empty
case _ =>
definitionsForSymbol(typeSymbols, pos)
definitionsForSymbol(typeSymbols, uri, pos)

end findTypeDefinitions

private def definitionsForSymbol(
symbols: List[Symbol],
pos: SourcePosition,
uri: URI,
pos: SourcePosition
)(using ctx: Context): DefinitionResult =
symbols match
case symbols @ (sym :: other) =>
val isLocal = sym.source == pos.source
if isLocal then
@tailrec
def findDefsForSymbol(sym: Symbol): DefinitionResult =
val defs =
Interactive.findDefinitions(List(sym), driver, false, false)
val include = Include.definitions | Include.local
val defs = Interactive.findTreesMatching(driver.openedTrees(uri), include, sym)
defs.headOption match
case Some(srcTree) =>
val pos = srcTree.namePos
Expand Down
Loading