@@ -23,9 +23,8 @@ object ScriptSourceFile {
23
23
private val headerStarts = List (" #!" , " ::#!" )
24
24
25
25
/** 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(_))
29
28
30
29
def apply (file : AbstractFile , content : Array [Char ]): SourceFile = {
31
30
/** Length of the script header from the given content, if there is one.
@@ -40,14 +39,14 @@ object ScriptSourceFile {
40
39
}
41
40
else 0
42
41
43
- // overwrite hash-bang lines with all spaces
42
+ // overwrite hash-bang lines with all spaces to preserve line numbers
44
43
val hashBangLines = content.take(headerLength).mkString.split(" \\ r?\\ n" )
45
44
if hashBangLines.nonEmpty then
46
45
for i <- 0 until headerLength do
47
46
content(i) match {
48
- case '\r ' | '\n ' =>
49
- case _ =>
50
- content(i) = ' '
47
+ case '\r ' | '\n ' =>
48
+ case _ =>
49
+ content(i) = ' '
51
50
}
52
51
53
52
new SourceFile (file, content) {
@@ -266,15 +265,16 @@ object SourceFile {
266
265
* if filename extension is not .scala and has a script header.
267
266
*/
268
267
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)
273
269
274
270
def apply (file : AbstractFile , codec : Codec ): SourceFile =
275
271
// 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
+
278
278
if isScript(file, chars) then
279
279
ScriptSourceFile (file, chars)
280
280
else
0 commit comments