Async-tokenize remaining buffer changes that exceed chunk size

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-12-11 16:51:05 -08:00
parent 7ead4d7390
commit dc60017c02
2 changed files with 26 additions and 3 deletions

View File

@ -262,6 +262,18 @@ describe "TokenizedBuffer", ->
delete event.bufferChange
expect(event).toEqual(start: 5, end: 7, delta: 0)
describe "when there is an insertion that is larger than the chunk size", ->
it "tokenizes the initial chunk synchronously, then tokenizes the remaining lines in the background", ->
commentBlock = _.multiplyString("// a comment\n", tokenizedBuffer.chunkSize + 2)
buffer.insert([0,0], commentBlock)
expect(tokenizedBuffer.lineForScreenRow(0).ruleStack?).toBeTruthy()
expect(tokenizedBuffer.lineForScreenRow(4).ruleStack?).toBeTruthy()
expect(tokenizedBuffer.lineForScreenRow(5).ruleStack?).toBeFalsy()
advanceClock()
expect(tokenizedBuffer.lineForScreenRow(5).ruleStack?).toBeTruthy()
expect(tokenizedBuffer.lineForScreenRow(6).ruleStack?).toBeTruthy()
describe ".findOpeningBracket(closingBufferPosition)", ->
it "returns the position of the matching bracket, skipping any nested brackets", ->
expect(tokenizedBuffer.findOpeningBracket([9, 2])).toEqual [1, 29]

View File

@ -107,7 +107,7 @@ class TokenizedBuffer
else
@screenLines[start..end] = @buildPlaceholderScreenLinesForRows(start, end + delta, stack)
unless _.isEqual(@stackForRow(end + delta), previousStack)
if @stackForRow(end + delta) and not _.isEqual(@stackForRow(end + delta), previousStack)
@invalidateRow(end + delta + 1)
@trigger "change", { start, end, delta, bufferChange: e }
@ -122,11 +122,22 @@ class TokenizedBuffer
buildTokenizedScreenLinesForRows: (startRow, endRow, startingStack) ->
ruleStack = startingStack
for row in [startRow..endRow]
screenLine = @buildTokenizedScreenLineForRow(row, ruleStack)
lastRowToTokenize = startRow + @chunkSize - 1
screenLines = for row in [startRow..endRow]
if row <= lastRowToTokenize
screenLine = @buildTokenizedScreenLineForRow(row, ruleStack)
else
screenLine = @buildPlaceholderScreenLineForRow(row)
ruleStack = screenLine.ruleStack
screenLine
if endRow > lastRowToTokenize
@invalidateRow(lastRowToTokenize + 1)
@tokenizeInBackground()
screenLines
buildTokenizedScreenLineForRow: (row, ruleStack) ->
line = @buffer.lineForRow(row)
{ tokens, ruleStack } = @languageMode.tokenizeLine(line, ruleStack)