Handle positions between CR and LF characters in TreeSitterTextBufferInput.seek

This commit is contained in:
Max Brunsfeld
2018-02-14 07:49:02 -08:00
parent b9e4febf03
commit 3e7e8aecce
3 changed files with 55 additions and 6 deletions

View File

@@ -170,6 +170,49 @@ describe('TreeSitterLanguageMode', () => {
[{text: ')', scopes: []}]
])
})
it('handles edits after tokens that end between CR and LF characters (regression)', () => {
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
parser: 'tree-sitter-javascript',
scopes: {
'comment': 'comment',
'string': 'string',
'property_identifier': 'property',
}
})
buffer.setLanguageMode(new TreeSitterLanguageMode({buffer, grammar}))
buffer.setText([
'// abc',
'',
'a("b").c'
].join('\r\n'))
expectTokensToEqual(editor, [
[{text: '// abc', scopes: ['comment']}],
[{text: '', scopes: []}],
[
{text: 'a(', scopes: []},
{text: '"b"', scopes: ['string']},
{text: ').', scopes: []},
{text: 'c', scopes: ['property']}
]
])
buffer.insert([2, 0], ' ')
expectTokensToEqual(editor, [
[{text: '// abc', scopes: ['comment']}],
[{text: '', scopes: []}],
[
{text: ' ', scopes: ['whitespace']},
{text: 'a(', scopes: []},
{text: '"b"', scopes: ['string']},
{text: ').', scopes: []},
{text: 'c', scopes: ['property']}
]
])
})
})
describe('folding', () => {