@@ -95,9 +95,9 @@ final class JLineTerminal extends java.io.Closeable {
95
95
def words = java.util.Collections .emptyList[String ]
96
96
}
97
97
98
- def parse (line : String , cursor : Int , context : ParseContext ): reader.ParsedLine = {
98
+ def parse (input : String , cursor : Int , context : ParseContext ): reader.ParsedLine = {
99
99
def parsedLine (word : String , wordCursor : Int ) =
100
- new ParsedLine (cursor, line , word, wordCursor)
100
+ new ParsedLine (cursor, input , word, wordCursor)
101
101
// Used when no word is being completed
102
102
def defaultParsedLine = parsedLine(" " , 0 )
103
103
@@ -110,7 +110,7 @@ final class JLineTerminal extends java.io.Closeable {
110
110
111
111
case class TokenData (token : Token , start : Int , end : Int )
112
112
def currentToken : TokenData /* | Null */ = {
113
- val source = new SourceFile (" <completions>" , line )
113
+ val source = new SourceFile (" <completions>" , input )
114
114
val scanner = new Scanner (source)(ctx.fresh.setReporter(Reporter .NoReporter ))
115
115
while (scanner.token != EOF ) {
116
116
val start = scanner.offset
@@ -125,23 +125,22 @@ final class JLineTerminal extends java.io.Closeable {
125
125
null
126
126
}
127
127
128
+ def acceptLine = {
129
+ val onLastLine = ! input.substring(cursor).contains(System .lineSeparator)
130
+ onLastLine && ! ParseResult .isIncomplete(input)
131
+ }
132
+
128
133
context match {
129
- case ParseContext .ACCEPT_LINE =>
130
- // ENTER means SUBMIT when
131
- // - cursor is at end (discarding whitespaces)
132
- // - and, input line is complete
133
- val cursorIsAtEnd = line.indexWhere(! _.isWhitespace, from = cursor) < 0
134
- if (cursorIsAtEnd && ! ParseResult .isIncomplete(line))
135
- defaultParsedLine // using dummy values, resulting parsed line is probably unused
136
- else
137
- incomplete()
134
+ case ParseContext .ACCEPT_LINE if acceptLine =>
135
+ // using dummy values, resulting parsed input is probably unused
136
+ defaultParsedLine
138
137
139
138
case ParseContext .COMPLETE =>
140
139
// Parse to find completions (typically after a Tab).
141
140
def isCompletable (token : Token ) = isIdentifier(token) || isKeyword(token)
142
141
currentToken match {
143
142
case TokenData (token, start, end) if isCompletable(token) =>
144
- val word = line .substring(start, end)
143
+ val word = input .substring(start, end)
145
144
val wordCursor = cursor - start
146
145
parsedLine(word, wordCursor)
147
146
case _ =>
0 commit comments