From fa86178061881399dfb25b7d4086a95130a720e8 Mon Sep 17 00:00:00 2001 From: Anup Sebastian Date: Thu, 30 Oct 2025 22:27:37 -0500 Subject: [PATCH] feat: folding, mini.pairs --- init.lua | 36 ++++++++++++++++++++ lua/custom/plugins/flutter.lua | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/init.lua b/init.lua index 48521702..167b5472 100644 --- a/init.lua +++ b/init.lua @@ -196,6 +196,31 @@ vim.o.scrolloff = 10 -- See `:help 'confirm'` vim.o.confirm = true +-- ======================================================================== +-- FOLDING CONFIGURATION - For Flutter widgets and code blocks +-- ======================================================================== +-- Enable folding based on Treesitter (for Flutter widgets, functions, etc.) +vim.o.foldmethod = 'expr' +vim.o.foldexpr = 'nvim_treesitter#foldexpr()' +-- Start with all folds open (don't fold on file open) +vim.o.foldenable = false +-- Set fold level (higher = more unfolded by default) +vim.o.foldlevel = 99 +vim.o.foldlevelstart = 99 +-- Customize fold text to show more context +vim.o.foldtext = '' +-- Hide fold column globally (saves space, folds still work with za/zc/zo) +vim.o.foldcolumn = '0' -- Set to '1' if you want the fold column back + +-- Folding keymaps: +-- za - Toggle fold under cursor +-- zc - Close fold under cursor +-- zo - Open fold under cursor +-- zM - Close all folds +-- zR - Open all folds +-- zj - Move to next fold +-- zk - Move to previous fold + -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -995,6 +1020,13 @@ require('lazy').setup({ -- - sr)' - [S]urround [R]eplace [)] ['] require('mini.surround').setup() + -- Autopairs - automatically close brackets, quotes, etc. + -- + -- When you type { it automatically adds } + -- When you type " it automatically adds the closing " + -- Press between brackets to add proper indentation + require('mini.pairs').setup() + -- Simple and easy statusline. -- You could remove this setup call if you don't like it, -- and try some other statusline plugin @@ -1051,6 +1083,10 @@ require('lazy').setup({ additional_vim_regex_highlighting = { 'ruby' }, }, indent = { enable = true, disable = { 'ruby' } }, + -- Enable folding based on Treesitter + fold = { + enable = true, + }, }, -- There are additional nvim-treesitter modules that you can use to interact -- with nvim-treesitter. You should go explore a few and see what interests you: diff --git a/lua/custom/plugins/flutter.lua b/lua/custom/plugins/flutter.lua index 7bbad8eb..a1f17127 100644 --- a/lua/custom/plugins/flutter.lua +++ b/lua/custom/plugins/flutter.lua @@ -246,6 +246,43 @@ return { end, }) + -- ======================================================================== + -- ENABLE TREESITTER FOLDING FOR DART FILES + -- ======================================================================== + -- Set fold method to use Treesitter for Flutter widgets + -- Using multiple autocmds to ensure it sticks (some plugins override it) + local fold_augroup = vim.api.nvim_create_augroup('DartFolding', { clear = true }) + + vim.api.nvim_create_autocmd({ 'BufRead', 'BufEnter', 'BufWinEnter' }, { + group = fold_augroup, + pattern = '*.dart', + callback = function() + vim.opt_local.foldmethod = 'expr' + vim.opt_local.foldexpr = 'nvim_treesitter#foldexpr()' + vim.opt_local.foldlevel = 99 -- High level = everything unfolded + vim.opt_local.foldlevelstart = 99 -- Start with everything unfolded + + -- Hide fold column (no extra column, folds still work!) + vim.opt_local.foldcolumn = '0' + + -- Minimal fold display (VS Code style - just shows first line) + vim.opt_local.foldtext = '' + end, + }) + + -- Also set after LSP attaches (flutter-tools might reset it) + vim.api.nvim_create_autocmd('LspAttach', { + group = fold_augroup, + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if client and client.name == 'dartls' then + vim.opt_local.foldmethod = 'expr' + vim.opt_local.foldexpr = 'nvim_treesitter#foldexpr()' + vim.opt_local.foldlevel = 99 -- Everything unfolded + end + end, + }) + -- ======================================================================== -- FLUTTER-SPECIFIC KEYMAPS -- ======================================================================== @@ -257,6 +294,16 @@ return { callback = function() local opts = { buffer = true, silent = true } + -- ======================================================================== + -- ENABLE TREESITTER FOLDING FOR DART FILES + -- ======================================================================== + -- Set fold method to use Treesitter for Flutter widgets + vim.opt_local.foldmethod = 'expr' + vim.opt_local.foldexpr = 'nvim_treesitter#foldexpr()' + vim.opt_local.foldenable = false -- Start with folds open + vim.opt_local.foldlevel = 99 + vim.opt_local.foldlevelstart = 99 + -- Flutter run/quit -- WORKFLOW: -- 1. First time: fd to select device @@ -338,4 +385,18 @@ return { }) end, }, + + -- ======================================================================== + -- DART TREESITTER - Ensure dart parser is installed for proper folding + -- ======================================================================== + { + 'nvim-treesitter/nvim-treesitter', + ft = 'dart', + opts = function(_, opts) + -- Ensure Dart parser is installed + opts.ensure_installed = opts.ensure_installed or {} + vim.list_extend(opts.ensure_installed, { 'dart' }) + return opts + end, + }, }