Created
January 17, 2020 00:15
-
-
Save olafurpg/d15833f9b519ac286e36a5daad8f07a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mtags/src/main/scala/scala/meta/internal/pc/AutoImports.scala b/mtags/src/main/scala/scala/meta/internal/pc/AutoImports.scala | |
index 34c7258..11f34b6 100644 | |
--- a/mtags/src/main/scala/scala/meta/internal/pc/AutoImports.scala | |
+++ b/mtags/src/main/scala/scala/meta/internal/pc/AutoImports.scala | |
@@ -37,14 +37,14 @@ trait AutoImports { this: MetalsGlobal => | |
} | |
} | |
+ def isImportPosition: Boolean = | |
+ findLastVisitedParentTree(pos).exists(_.isInstanceOf[Import]) | |
+ | |
def autoImportPosition( | |
pos: Position, | |
text: String | |
): Option[AutoImportPosition] = { | |
- if (lastVisistedParentTrees.isEmpty) { | |
- locateTree(pos) | |
- } | |
- lastVisistedParentTrees.headOption match { | |
+ findLastVisitedParentTree(pos) match { | |
case Some(_: Import) => None | |
case _ => | |
val enclosingPackage = lastVisistedParentTrees.collectFirst { | |
diff --git a/mtags/src/main/scala/scala/meta/internal/pc/Completions.scala b/mtags/src/main/scala/scala/meta/internal/pc/Completions.scala | |
index 2361c66..0f9a807 100644 | |
--- a/mtags/src/main/scala/scala/meta/internal/pc/Completions.scala | |
+++ b/mtags/src/main/scala/scala/meta/internal/pc/Completions.scala | |
@@ -336,6 +336,12 @@ trait Completions { this: MetalsGlobal => | |
// variable but it avoids repeating traversals from the compiler | |
// implementation of `completionsAt(pos)`. | |
var lastVisistedParentTrees: List[Tree] = Nil | |
+ def findLastVisitedParentTree(pos: Position): Option[Tree] = { | |
+ if (lastVisistedParentTrees.isEmpty) { | |
+ locateTree(pos) | |
+ } | |
+ lastVisistedParentTrees.headOption | |
+ } | |
abstract class CompletionPosition { | |
def isType: Boolean = false | |
def isNew: Boolean = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment