@@ -23,9 +23,8 @@ object ScriptSourceFile {
2323 private val headerStarts = List (" #!" , " ::#!" )
2424
2525 /** Return true if has a script header */
26- def hasScriptHeader (content : Array [Char ]): Boolean = {
27- headerStarts exists (content startsWith _)
28- }
26+ def hasScriptHeader (content : Array [Char ]): Boolean =
27+ headerStarts.exists(content.startsWith(_))
2928
3029 def apply (file : AbstractFile , content : Array [Char ]): SourceFile = {
3130 /** Length of the script header from the given content, if there is one.
@@ -40,14 +39,14 @@ object ScriptSourceFile {
4039 }
4140 else 0
4241
43- // overwrite hash-bang lines with all spaces
42+ // overwrite hash-bang lines with all spaces to preserve line numbers
4443 val hashBangLines = content.take(headerLength).mkString.split(" \\ r?\\ n" )
4544 if hashBangLines.nonEmpty then
4645 for i <- 0 until headerLength do
4746 content(i) match {
48- case '\r ' | '\n ' =>
49- case _ =>
50- content(i) = ' '
47+ case '\r ' | '\n ' =>
48+ case _ =>
49+ content(i) = ' '
5150 }
5251
5352 new SourceFile (file, content) {
@@ -266,15 +265,16 @@ object SourceFile {
266265 * if filename extension is not .scala and has a script header.
267266 */
268267 def isScript (file : AbstractFile , content : Array [Char ]): Boolean =
269- if file.hasExtension(" .scala" ) then
270- false
271- else
272- ScriptSourceFile .hasScriptHeader(content)
268+ ScriptSourceFile .hasScriptHeader(content)
273269
274270 def apply (file : AbstractFile , codec : Codec ): SourceFile =
275271 // see note above re: Files.exists is remarkably slow
276- val chars = try new String (file.toByteArray, codec.charSet).toCharArray
277- catch case _ : java.nio.file.NoSuchFileException => Array [Char ]()
272+ val chars =
273+ try
274+ new String (file.toByteArray, codec.charSet).toCharArray
275+ catch
276+ case _ : java.nio.file.NoSuchFileException => Array [Char ]()
277+
278278 if isScript(file, chars) then
279279 ScriptSourceFile (file, chars)
280280 else
0 commit comments