Merge pull request #18502 from atom/mb-fold-marker-updates

Fix typo that messed up fold marker updates
This commit is contained in:
Max Brunsfeld
2018-11-27 11:11:33 -08:00
committed by GitHub
2 changed files with 37 additions and 1 deletions

View File

@@ -1307,6 +1307,42 @@ describe('TreeSitterLanguageMode', () => {
`)
})
it('updates fold locations when the buffer changes', () => {
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
parser: 'tree-sitter-javascript',
folds: [
{
start: {type: '{', index: 0},
end: {type: '}', index: -1}
}
]
})
buffer.setText(dedent `
class A {
// a
constructor (b) {
this.b = b
}
}
`)
const languageMode = new TreeSitterLanguageMode({buffer, grammar})
buffer.setLanguageMode(languageMode)
expect(languageMode.isFoldableAtRow(0)).toBe(true)
expect(languageMode.isFoldableAtRow(1)).toBe(false)
expect(languageMode.isFoldableAtRow(2)).toBe(true)
expect(languageMode.isFoldableAtRow(3)).toBe(false)
expect(languageMode.isFoldableAtRow(4)).toBe(false)
buffer.insert([0, 0], '\n')
expect(languageMode.isFoldableAtRow(0)).toBe(false)
expect(languageMode.isFoldableAtRow(1)).toBe(true)
expect(languageMode.isFoldableAtRow(2)).toBe(false)
expect(languageMode.isFoldableAtRow(3)).toBe(true)
expect(languageMode.isFoldableAtRow(4)).toBe(false)
})
describe('when folding a node that ends with a line break', () => {
it('ends the fold at the end of the previous line', async () => {
const grammar = new TreeSitterGrammar(atom.grammars, pythonGrammarPath, {

View File

@@ -94,7 +94,7 @@ class TreeSitterLanguageMode {
}
}
bufferDidFinishTransaction (changes) {
bufferDidFinishTransaction ({changes}) {
for (let i = 0, {length} = changes; i < length; i++) {
const {oldRange, newRange} = changes[i]
spliceArray(