diff --git a/mtags/src/main/scala/scala/meta/internal/pc/ScriptFirstImportPosition.scala b/mtags/src/main/scala/scala/meta/internal/pc/ScriptFirstImportPosition.scala index 3eff79e84ea..10cef33ed76 100644 --- a/mtags/src/main/scala/scala/meta/internal/pc/ScriptFirstImportPosition.scala +++ b/mtags/src/main/scala/scala/meta/internal/pc/ScriptFirstImportPosition.scala @@ -27,10 +27,14 @@ import scala.meta._ object ScriptFirstImportPosition { val usingDirectives: List[String] = List("// using", "//> using") + val shebang = "#!" val ammHeaders: List[String] = List("// scala", "// ammonite") + private def adjustShebang(text: String): String = + text.replaceFirst(shebang, s"//$shebang") + def ammoniteScStartOffset(text: String): Option[Int] = { - val it = tokenize(text).iterator + val it = tokenize(adjustShebang(text)).iterator startMarkerOffset(it, "/**/").map { startOffset => val offset = skipPrefixesOffset(ammHeaders, it, None) @@ -41,7 +45,7 @@ object ScriptFirstImportPosition { } def scalaCliScStartOffset(text: String): Option[Int] = { - val iterator = tokenize(text).iterator + val iterator = tokenize(adjustShebang(text)).iterator startMarkerOffset(iterator, "/*