Forked from olafurpg/gist:d15833f9b519ac286e36a5daad8f07a5
Created
February 6, 2020 19:49
-
-
Save kubukoz/3527793480b0117b2117e5863958a55b to your computer and use it in GitHub Desktop.
Revisions
-
kubukoz renamed this gist
Feb 6, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
olafurpg created this gist
Jan 17, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ 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