From d3882c165f2d54dbdb60ed036ddf2bd01f78f885 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 12 Oct 2016 12:04:54 +0200 Subject: [PATCH] :art: --- spec/tokenized-buffer-spec.coffee | 22 +++++++++++++--------- src/null-grammar.js | 4 ++-- src/tokenized-buffer.coffee | 19 ++++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/spec/tokenized-buffer-spec.coffee b/spec/tokenized-buffer-spec.coffee index a21db2fe3..16fc4849c 100644 --- a/spec/tokenized-buffer-spec.coffee +++ b/spec/tokenized-buffer-spec.coffee @@ -1,3 +1,4 @@ +NullGrammar = require '../src/null-grammar' TokenizedBuffer = require '../src/tokenized-buffer' {Point} = TextBuffer = require 'text-buffer' _ = require 'underscore-plus' @@ -568,26 +569,29 @@ describe "TokenizedBuffer", -> expect(tokenizedBuffer.isFoldableAtRow(8)).toBe false describe "when the buffer is configured with the null grammar", -> - it "uses the placeholder tokens and does not actually tokenize using the grammar", -> - spyOn(atom.grammars.nullGrammar, 'tokenizeLine').andCallThrough() + it "does not actually tokenize using the grammar", -> + spyOn(NullGrammar, 'tokenizeLine').andCallThrough() buffer = atom.project.bufferForPathSync('sample.will-use-the-null-grammar') buffer.setText('a\nb\nc') - tokenizedBuffer = new TokenizedBuffer({ buffer, grammarRegistry: atom.grammars, packageManager: atom.packages, - assert: atom.assert, tabLength: 2, + assert: atom.assert, tabLength: 2 }) tokenizeCallback = jasmine.createSpy('onDidTokenize') tokenizedBuffer.onDidTokenize(tokenizeCallback) - fullyTokenize(tokenizedBuffer) - - expect(tokenizeCallback.callCount).toBe 1 - expect(atom.grammars.nullGrammar.tokenizeLine.callCount).toBe 0 - expect(tokenizedBuffer.tokenizedLines[0]).toBeUndefined() expect(tokenizedBuffer.tokenizedLines[1]).toBeUndefined() expect(tokenizedBuffer.tokenizedLines[2]).toBeUndefined() + expect(tokenizeCallback.callCount).toBe(0) + expect(NullGrammar.tokenizeLine).not.toHaveBeenCalled() + + fullyTokenize(tokenizedBuffer) + expect(tokenizedBuffer.tokenizedLines[0]).toBeUndefined() + expect(tokenizedBuffer.tokenizedLines[1]).toBeUndefined() + expect(tokenizedBuffer.tokenizedLines[2]).toBeUndefined() + expect(tokenizeCallback.callCount).toBe(0) + expect(NullGrammar.tokenizeLine).not.toHaveBeenCalled() describe "text decoration layer API", -> describe "iterator", -> diff --git a/src/null-grammar.js b/src/null-grammar.js index 01841346e..fe9c3889e 100644 --- a/src/null-grammar.js +++ b/src/null-grammar.js @@ -2,7 +2,7 @@ import {Disposable} from 'event-kit' -export default Object.freeze({ +export default { name: 'Null Grammar', scopeName: 'text.plain.null-grammar', scopeForId (id) { @@ -35,6 +35,6 @@ export default Object.freeze({ onDidUpdate (callback) { return new Disposable(noop) } -}) +} function noop () {} diff --git a/src/tokenized-buffer.coffee b/src/tokenized-buffer.coffee index ff2d72019..20e79d28a 100644 --- a/src/tokenized-buffer.coffee +++ b/src/tokenized-buffer.coffee @@ -94,11 +94,13 @@ class TokenizedBuffer extends Model false retokenizeLines: -> - lastRow = @buffer.getLastRow() @fullyTokenized = false - @tokenizedLines = new Array(lastRow + 1) + @tokenizedLines = new Array(@buffer.getLineCount()) @invalidRows = [] - @invalidateRow(0) + if @largeFileMode or @grammar.name is 'Null Grammar' + @markTokenizationComplete() + else + @invalidateRow(0) setVisible: (@visible) -> @tokenizeInBackground() if @visible @@ -167,11 +169,10 @@ class TokenizedBuffer extends Model return invalidateRow: (row) -> - return if @largeFileMode - - @invalidRows.push(row) - @invalidRows.sort (a, b) -> a - b - @tokenizeInBackground() + if @grammar.name isnt 'Null Grammar' and not @largeFileMode + @invalidRows.push(row) + @invalidRows.sort (a, b) -> a - b + @tokenizeInBackground() updateInvalidRows: (start, end, delta) -> @invalidRows = @invalidRows.map (row) -> @@ -238,7 +239,7 @@ class TokenizedBuffer extends Model openScopes = startingopenScopes stopTokenizingAt = startRow + @chunkSize tokenizedLines = for row in [startRow..endRow] by 1 - if (not @firstInvalidRow()? or row < @firstInvalidRow()) and row < stopTokenizingAt + if (ruleStack or row is 0) and row < stopTokenizingAt tokenizedLine = @buildTokenizedLineForRow(row, ruleStack, openScopes) ruleStack = tokenizedLine.ruleStack openScopes = @scopesFromTags(openScopes, tokenizedLine.tags)