feature: treesitter folding syntax highlight

pull/296/head
ray-x 6 months ago
parent 236fb062d2
commit 18304b8a84

@ -1,4 +1,4 @@
12 require('nvim-autopairs').setup{
# Navigator
- Source code analysis and navigate tool
@ -102,7 +102,11 @@ variable is:
- ccls call hierarchy (Non-standard `ccls/call` API) supports
- Syntax folding based on treesitter or LSP_fold folding algorithm. (It behaves similar to vs-code); dedicated comment folding.
- Incorporates a modified folding algorithm based on treesitter or LSP_fold, providing a user experience comparable to Visual Studio Code.
- Ensures end or closing brackets remain visible.
- Features specific functionality for comment folding.
- Enables the display of folded lines.
- Includes syntax highlighting capabilities (supported in Neovim version 0.10.x and above).
- Treesitter symbols sidebar, LSP document symbole sidebar. Both with preview and folding
@ -244,7 +248,7 @@ Nondefault configuration example:
```lua
require'navigator'.setup({
debug = false, -- log output, set to true and log path: ~/.cache/nvim/gh.log
debug = false, -- log output, set to true and log path: ~/.cache/nvim/gh.log
-- slowdownd startup and some actions
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width)
height = 0.3, -- max list window height, 0.3 by default
@ -557,7 +561,7 @@ LspDiagnosticsXXX are used for diagnostic. Please check highlight.lua and dochig
The plugin can be loaded lazily (packer `opt = true` ), And it will check if optional plugins existance and load those plugins only if they existed.
The terminal will need to be able to output nerdfont(v.3.0+) and emoji correctly. I am using Kitty with nerdfont (Victor Mono).
The terminal will need to be able to output nerdfont and emoji correctly. I am using Kitty with nerdfont (Victor Mono).
## Integrate with mason (williamboman/mason.nvim)

@ -201,6 +201,10 @@ _NgConfigValues = {
bracket_left = '',
bracket_right = '',
},
fold = {
prefix = '',
separator = '',
},
-- Treesitter
-- Note: many more node.type or kind may be available

@ -16,8 +16,9 @@ function M.on_attach()
M.setup_fold()
-- M.update_folds()
end
function NG_custom_fold_text()
local prefix = _NgConfigValues.icons.fold.prefix
local sep = _NgConfigValues.icons.fold.separator
local function custom_fold_text()
local line = vim.fn.getline(vim.v.foldstart)
local line_count = vim.v.foldend - vim.v.foldstart + 1
-- log("" .. line .. " // " .. line_count .. " lines")
@ -25,8 +26,40 @@ function NG_custom_fold_text()
local spaces = line:sub(ss, se)
local tabspace = string.rep(' ', vim.o.tabstop)
spaces = spaces:gsub('\t', tabspace)
line = line:gsub('^%s*(.-)%s*$', '%1')
return spaces .. '' .. line .. ': ' .. line_count .. ' lines'
line = line:gsub('^%s*(.-)%s*$', '%1') -- trim leading and trailing whitespace
return spaces .. prefix .. line .. ': ' .. line_count .. ' lines'
end
function NG_custom_fold_text()
if vim.treesitter.foldtext then
local line_syntax = vim.treesitter.foldtext()
if type(line_syntax) ~= 'table' or #line_syntax < 1 then
return line_syntax
end
local line_count = vim.v.foldend - vim.v.foldstart + 1
if prefix ~= '' then
local spaces = line_syntax[1]
local s = spaces[1]
local first_char = s:sub(1, 1)
if first_char == '\t' then
local tabspace = string.rep(' ', vim.o.tabstop)
s = s:gsub('\t', tabspace)
end
s = s:gsub('^ ', prefix)
if s ~= spaces[1] then
spaces[1] = s
spaces[2] = { '@keyword' }
end
end
local sep2 = ' ' .. string.rep(sep, 3)
table.insert(line_syntax, { sep2, { '@comment' } })
table.insert(line_syntax, { ' ' .. tostring(line_count), { '@number' } })
table.insert(line_syntax, { ' lines', { '@comment' } })
table.insert(line_syntax, { sep, { '@comment' } })
return line_syntax
end
return custom_fold_text()
end
vim.opt.foldtext = NG_custom_fold_text()

Loading…
Cancel
Save