mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Tweak TreeSitterLanguageMode folding configuration
This commit is contained in:
@@ -10,9 +10,10 @@ class TreeSitterGrammar {
|
||||
this.id = params.id
|
||||
this.name = params.name
|
||||
|
||||
this.foldConfig = params.folds || {}
|
||||
if (!this.foldConfig.delimiters) this.foldConfig.delimiters = []
|
||||
if (!this.foldConfig.tokens) this.foldConfig.tokens = []
|
||||
this.foldConfig = {
|
||||
delimiters: params.folds && params.folds.delimiters || [],
|
||||
nodes: new Set(params.folds && params.folds.nodes || [])
|
||||
}
|
||||
|
||||
this.commentStrings = {
|
||||
commentStartString: params.comments && params.comments.start,
|
||||
|
||||
@@ -207,18 +207,15 @@ class TreeSitterLanguageMode {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0, n = this.grammar.foldConfig.tokens.length; i < n; i++) {
|
||||
const foldableToken = this.grammar.foldConfig.tokens[i]
|
||||
if (node.type === foldableToken[0]) {
|
||||
if (existenceOnly) return true
|
||||
const start = node.startPosition
|
||||
const end = node.endPosition
|
||||
start.column += foldableToken[1]
|
||||
end.column -= foldableToken[2]
|
||||
return Range(start, end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.grammar.foldConfig.nodes.has(node.type)) {
|
||||
if (existenceOnly) return true
|
||||
const start = node.startPosition
|
||||
const end = node.endPosition
|
||||
start.column = Infinity
|
||||
end.column = 0
|
||||
return Range(start, end)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user