feat(provider): allow using tree-sitter node types as kinds (#243)

* feat(provider): allow using tree-sitter node types as kinds
(adding tree-sitter support to close_fold_kinds_for_ft)

* fix(provider): guard treesitter node type and add mention to README

---------

Co-authored-by: 3rd <3rd@users.noreply.github.com>
Co-authored-by: anon <anon@localhost>
This commit is contained in:
Andrei Neculaesei 2024-08-23 17:25:45 +03:00 committed by GitHub
parent 7dcb8fea3e
commit b23a46aa06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -153,7 +153,8 @@ For example, Changing the text in a buffer will request the providers for folds.
close_fold_kinds_for_ft = {
description = [[After the buffer is displayed (opened for the first time), close the
folds whose range with `kind` field is included in this option. For now,
'lsp' provider's standardized kinds are 'comment', 'imports' and 'region'.
'lsp' provider's standardized kinds are 'comment', 'imports' and 'region',
and the 'treesitter' provider exposes the underlying node types.
This option is a table with filetype as key and fold kinds as value. Use a
default value if value of filetype is absent.
Run `UfoInspect` for details if your provider has extended the kinds.]],

View file

@ -179,7 +179,8 @@ function Treesitter.getFolds(bufnr)
stop = stop - 1
end
if stop > start then
table.insert(ranges, foldingrange.new(start, stop))
local type = node.type and node:type() or nil
table.insert(ranges, foldingrange.new(start, stop, nil, nil, type))
end
end
foldingrange.sortRanges(ranges)