mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Tweak TreeSitterLanguageMode folding configuration
This commit is contained in:
@@ -73,7 +73,7 @@ describe('TreeSitterLanguageMode', () => {
|
||||
editor.displayLayer.reset({foldCharacter: '…'})
|
||||
})
|
||||
|
||||
it('folds nodes that start and end with specified tokens and span multiple lines', () => {
|
||||
it('can fold nodes that start and end with specified tokens and span multiple lines', () => {
|
||||
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
|
||||
parser: 'tree-sitter-javascript',
|
||||
scopes: {'program': 'source'},
|
||||
@@ -123,6 +123,51 @@ describe('TreeSitterLanguageMode', () => {
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('can fold specified types of multi-line nodes', () => {
|
||||
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
|
||||
parser: 'tree-sitter-javascript',
|
||||
scopes: {'program': 'source'},
|
||||
folds: {
|
||||
nodes: [
|
||||
'template_string',
|
||||
'comment'
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
buffer.setLanguageMode(new TreeSitterLanguageMode({buffer, grammar}))
|
||||
buffer.setText(dedent `
|
||||
/**
|
||||
* Important
|
||||
*/
|
||||
const x = \`one
|
||||
two
|
||||
three\`
|
||||
`)
|
||||
|
||||
editor.screenLineForScreenRow(0)
|
||||
|
||||
expect(editor.isFoldableAtBufferRow(0)).toBe(true)
|
||||
expect(editor.isFoldableAtBufferRow(1)).toBe(false)
|
||||
expect(editor.isFoldableAtBufferRow(2)).toBe(false)
|
||||
expect(editor.isFoldableAtBufferRow(3)).toBe(true)
|
||||
expect(editor.isFoldableAtBufferRow(4)).toBe(false)
|
||||
|
||||
editor.foldBufferRow(0)
|
||||
expect(getDisplayText(editor)).toBe(dedent `
|
||||
/**… */
|
||||
const x = \`one
|
||||
two
|
||||
three\`
|
||||
`)
|
||||
|
||||
editor.foldBufferRow(3)
|
||||
expect(getDisplayText(editor)).toBe(dedent `
|
||||
/**… */
|
||||
const x = \`one… three\`
|
||||
`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user