Skip to content

Commit

Permalink
feat: adding ufo plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukerten committed Nov 20, 2024
1 parent 535d2cb commit a498c98
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
51 changes: 51 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@
url = "github:moll/vim-bbye";
flake = false;
};
plugins-ufo = {
url = "github:kevinhwang91/nvim-ufo";
flake = false;
};
plugins-async = {
url = "github:kevinhwang91/promise-async";
flake = false;
};
plugins-statuscolumn = {
url = "github:luukvbaal/statuscol.nvim";
flake = false;
};

# Key binding help
plugins-which-key = {
Expand Down
10 changes: 9 additions & 1 deletion modules/lsp/lightbulb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ in {
*/
''
-- Enable trouble diagnostics viewer
require'nvim-lightbulb'.setup()
local opts = {
sign = {
enabled = true,
text = "",
lens_text = "",
hl = "LightBulbSign",
},
}
require'nvim-lightbulb'.setup(opts)
'';
};
}
2 changes: 2 additions & 0 deletions modules/visual/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ in {
./nwd.nix
./theme.nix
./todo.nix
./ufo.nix
];

options.vim.visual = {
Expand All @@ -40,5 +41,6 @@ in {
nvimWebDevicons.enable = mkDefault true;
todo.enable = mkDefault true;
theme.enable = mkDefault true;
ufo.enable = mkDefault true;
};
}
90 changes: 90 additions & 0 deletions modules/visual/ufo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
config,
lib,
...
}:
with lib; let
cfg = config.vim.visual.ufo;
in {
options.vim.visual.ufo = {
enable = mkEnableOption "Todo highlights [nvim-todo]";
};

config = mkIf cfg.enable {
vim.startPlugins = ["ufo" "async" "statuscolumn"];
vim.luaConfigRC.todo =
nvim.dag.entryAnywhere #lua
''
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
vim.o.foldcolumn = '1'
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
local handler = function(virtText, lnum, endLnum, width, truncate)
local newVirtText = {}
local totalLines = vim.api.nvim_buf_line_count(0)
local foldedLines = endLnum - lnum
local suffix = (" ... %d lines ommitted"):format(foldedLines, foldedLines / totalLines * 100)
local sufWidth = vim.fn.strdisplaywidth(suffix)
local targetWidth = width - sufWidth
local curWidth = 0
for _, chunk in ipairs(virtText) do
local chunkText = chunk[1]
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
if targetWidth > curWidth + chunkWidth then
table.insert(newVirtText, chunk)
else
chunkText = truncate(chunkText, targetWidth - curWidth)
local hlGroup = chunk[2]
table.insert(newVirtText, { chunkText, hlGroup })
chunkWidth = vim.fn.strdisplaywidth(chunkText)
-- str width returned from truncate() may less than 2nd argument, need padding
if curWidth + chunkWidth < targetWidth then
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
end
break
end
curWidth = curWidth + chunkWidth
end
local rAlignAppndx =
math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0)
suffix = (" "):rep(rAlignAppndx) .. suffix
table.insert(newVirtText, { suffix, "MoreMsg" })
return newVirtText
end
local builtin = require("statuscol.builtin")
require("statuscol").setup(
{
relculright = true,
segments = {
{text = {"%s"}, click = "v:lua.ScSa"},
{text = {builtin.foldfunc}, click = "v:lua.ScFa"},
{text = {builtin.lnumfunc, " "}, click = "v:lua.ScLa"}
}
}
)
require('ufo').setup({
fold_virt_text_handler = handler,
open_fold_hl_timeout = 400,
close_fold_kinds = { "imports", "comment" },
preview = {
win_config = {
border = { "", "─", "", "", "", "─", "", "" },
winblend = 0,
},
mappings = {
scrollU = "<C-u>",
scrollD = "<C-d>",
jumpTop = "[",
jumpBot = "]",
},
},
})
vim.keymap.set("n", "zR", require("ufo").openAllFolds)
vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
vim.keymap.set("n", "zr", require("ufo").openFoldsExceptKinds)
'';
};
}

0 comments on commit a498c98

Please sign in to comment.