mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
🎨
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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 () {}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user