Skip to content

Commit

Permalink
Clean up fold comments/documents and update align to latest code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Nov 11, 2023
1 parent 059973f commit 164e8ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ require'navigator'.setup({
-- Diagnostics
diagnostic_head = '🐛',
diagnostic_head_severity_1 = "🈲",
fold = {
prefix = '', -- icon to show before the folding need to be 2 spaces in display width
separator = '', -- e.g. shows  3 lines 
},
},
mason = false, -- set to true if you would like use the lsp installed by williamboman/mason
lsp = {
Expand Down
2 changes: 1 addition & 1 deletion lua/navigator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ _NgConfigValues = {
},
fold = {
prefix = '',
separator = '',
separator = '',
},

-- Treesitter
Expand Down
29 changes: 14 additions & 15 deletions lua/navigator/foldts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ M.current_buf_folds = {}

function M.on_attach()
M.setup_fold()
-- M.update_folds()
end
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")
-- trace("" .. line .. " // " .. line_count .. " lines")
local ss, se = line:find('^%s*')
local spaces = line:sub(ss, se)
local tabspace = string.rep(' ', vim.o.tabstop)
Expand Down Expand Up @@ -55,9 +54,9 @@ function NG_custom_fold_text()
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' } })
table.insert(line_syntax, { ' ' .. tostring(line_count), { '@number' } })
table.insert(line_syntax, { ' lines ', { '@comment' } })
table.insert(line_syntax, { sep2, { '@comment' } })
return line_syntax
end
return custom_fold_text()
Expand Down Expand Up @@ -135,27 +134,27 @@ local function indent_levels(scopes, total_lines)
local prev = { -1, -1 }
for _, scope in ipairs(scopes) do
if not (prev[1] == scope[1] and prev[2] == scope[2]) then
events[scope[1]] = (events[scope[1]] or 0) + 1
events[scope[1]] = (events[scope[1]] or 0) + 1 -- incase there is a fold inside a fold
events[scope[2]] = (events[scope[2]] or 0) - 1
end
prev = scope
end
trace(events)

local currentIndent = 0
local indentLevels = {}
local prevIndentLevel = 0
local current_indent = 0
local indent_lvls = {}
local prev_indent_lvl = 0
local levels = {}
for line = 0, total_lines - 1 do
if events[line] then
currentIndent = currentIndent + events[line]
current_indent = current_indent + events[line]
end
indentLevels[line] = currentIndent
indent_lvls[line] = current_indent

local indentSymbol = indentLevels[line] > prevIndentLevel and '>' or ' '
trace('Line ' .. line .. ': ' .. indentSymbol .. indentLevels[line])
levels[line + 1] = indentSymbol .. tostring(trim_level(indentLevels[line]))
prevIndentLevel = indentLevels[line]
local indent_symbol = indent_lvls[line] > prev_indent_lvl and '>' or ''
trace('Line ' .. line .. ': ' .. indent_symbol .. indent_lvls[line])
levels[line + 1] = indent_symbol .. tostring(trim_level(indent_lvls[line]))
prev_indent_lvl = indent_lvls[line]
end
trace(levels)
return levels
Expand Down

0 comments on commit 164e8ad

Please sign in to comment.