From e045491ec1e8a92bfaf707759761cf9515e7b0ad Mon Sep 17 00:00:00 2001 From: yaso Date: Tue, 7 Jul 2026 15:10:01 +0200 Subject: [PATCH] fix lag and add buffer management --- README.md | 11 +++++ lazy-lock.json | 4 +- lua/config/keybinds.lua | 2 + lua/plugins/cmd_popup.lua | 18 ++++---- lua/plugins/early_retirement.lua | 16 +++++++ lua/plugins/flutter.lua | 75 +++++++++++++++++++++++++++----- lua/plugins/lsp.lua | 2 +- lua/plugins/telescope.lua | 17 +++++++- 8 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 lua/plugins/early_retirement.lua diff --git a/README.md b/README.md index a030ac4..43fb234 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,16 @@ The **Leader Key** is set to `Space`. | **Harpoon Find** | `fl` | Use Telescope to search your Harpoon list. | | **Quick Nav** | `Ctrl + h/t/n/s` | Jump instantly to Harpoon files 1, 2, 3, or 4. | +### Telescope Navigation & Buffer Management + +| Action | Keybinding | Description | +| :--- | :--- | :--- | +| **Find Files** | `ff` | Fuzzy find files in your project.[cite: 3] | +| **Live Grep** | `fg` | Search for specific text across all project files.[cite: 3] | +| **Help Tags** | `fh` | Search through Neovim help documentation.[cite: 3] | +| **Active Buffers List** | `fb` | View, search, and switch between your currently open buffers.[cite: 3] | +| **Delete Buffer (Normal Mode)** | `d` | Close the selected buffer after pressing `` inside the `fb` menu. | + ### LSP & Development | Action | Keybinding | Description | | :--- | :--- | :--- | @@ -172,6 +182,7 @@ The **Leader Key** is set to `Space`. | **List Devices** | `:FDevices` | Show a list of available physical/virtual devices. | | **Toggle Logs** | `:FLogs` | Open or close the Flutter Dev Log split. | | **Clear Logs** | `:FLogsClear` | Clear the current Flutter Dev Log buffer. | +| **Restart LSP** | `:FLspRestart` | Restart the Dart lsp is not working correctly. | | **Clean Project** | `:FClean` | Execute flutter clean in split terminal. | | **Pub Get** | `:FPubGet` | Fetches project dependencies. | | **Start DevTools** | `:FDevToolsStart` | Start the local Flutter DevTools server | diff --git a/lazy-lock.json b/lazy-lock.json index 2135922..204ffbf 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -23,7 +23,7 @@ "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-autopairs": { "branch": "master", "commit": "7b9923abad60b903ece7c52940e1321d39eccc79" }, "nvim-cmp": { "branch": "main", "commit": "a1d504892f2bc56c2e79b65c6faded2fd21f3eca" }, - "nvim-lspconfig": { "branch": "master", "commit": "292f44408498103c47996ff5c18fd366293840d8" }, + "nvim-lspconfig": { "branch": "master", "commit": "d224a1920728ba129880efc700d4a0180ac4ecbb" }, "nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" }, "nvim-treesitter": { "branch": "main", "commit": "4916d6592ede8c07973490d9322f187e07dfefac" }, "nvim-web-devicons": { "branch": "master", "commit": "dad71387de386a946b123079d0e53f23028f3abd" }, @@ -31,5 +31,5 @@ "telescope-fzf-native.nvim": { "branch": "main", "commit": "b25b749b9db64d375d782094e2b9dce53ad53a40" }, "telescope.nvim": { "branch": "master", "commit": "5255aa27c422de944791318024167ad5d40aad20" }, "tokyonight.nvim": { "branch": "main", "commit": "cdc07ac78467a233fd62c493de29a17e0cf2b2b6" }, - "yazi.nvim": { "branch": "main", "commit": "2314e0eb074996acc30183e3e9dfbfefd82f24aa" } + "yazi.nvim": { "branch": "main", "commit": "8d6c25cb4e7c5702d6cd5a263cb36129fa78aa4c" } } diff --git a/lua/config/keybinds.lua b/lua/config/keybinds.lua index ce7ede2..32332a0 100644 --- a/lua/config/keybinds.lua +++ b/lua/config/keybinds.lua @@ -7,6 +7,8 @@ vim.keymap.set("v", "y", '"+y', { desc = "Copy to system clipboard" }) vim.keymap.set({ "n", "v" }, "p", '"+p', { desc = "Paste from system clipboard after" }) -- Paste from system clipboard BEFORE the cursor (Normal & Visual mode) vim.keymap.set({ "n", "v" }, "P", '"+P', { desc = "Paste from system clipboard before" }) +-- Native LSP restart keymap (No plugins or custom functions required!) +vim.keymap.set("n", "lx", "lsp restart", { desc = "Restart LSP Server" }) vim.api.nvim_create_autocmd("FileType", { pattern = "netrw", callback = function(event) diff --git a/lua/plugins/cmd_popup.lua b/lua/plugins/cmd_popup.lua index 1c813ee..66bb109 100644 --- a/lua/plugins/cmd_popup.lua +++ b/lua/plugins/cmd_popup.lua @@ -5,15 +5,15 @@ return { cmdline = { view = "cmdline_popup", -- This ensures it's a popup and not at the bottom }, - routes = { - { - filter = { - event = "lsp", - kind = "progress", - }, - opts = { skip = true }, - }, - }, + -- routes = { + -- { + -- filter = { + -- event = "lsp", + -- kind = "progress", + -- }, + -- opts = { skip = true }, + -- }, + -- }, presets = { bottom_search = false, -- use a classic bottom cmdline for search command_palette = true, -- position the cmdline and popupmenu together diff --git a/lua/plugins/early_retirement.lua b/lua/plugins/early_retirement.lua new file mode 100644 index 0000000..983db71 --- /dev/null +++ b/lua/plugins/early_retirement.lua @@ -0,0 +1,16 @@ +return { + "chrisgrieser/nvim-early-retirement", + event = "VeryLazy", + opts = { + ignoreFilenamePattern = "FLUTTER_DEV_LOG", + ignoredFiletypes = { "log" }, + retirementAgeMins = 10, + minimumBufferNum = 5, + ignoreUnsavedChangesBufs = true, + ignoreVisibleBufs = true, + ignoreSpecialBuftypes = true, + ignoreAltFile = true, + notificationOnAutoClose = true, + deleteBufferWhenFileDeleted = false, + }, +} diff --git a/lua/plugins/flutter.lua b/lua/plugins/flutter.lua index 48ae094..2a2f1df 100644 --- a/lua/plugins/flutter.lua +++ b/lua/plugins/flutter.lua @@ -8,14 +8,49 @@ return { }, config = function() vim.opt.termguicolors = true - vim.api.nvim_create_autocmd({ "TextChanged", "BufWinEnter" }, { - pattern = "*__FLUTTER_DEV_LOG__*", - callback = function() - local buf = vim.api.nvim_get_current_buf() - - if vim.bo[buf].filetype == "log" or vim.fn.bufname(buf):match("flutter%-dev%.log") then - vim.cmd("normal! G") + vim.api.nvim_create_autocmd("FileType", { + pattern = "log", + callback = function(ev) + if not vim.fn.bufname(ev.buf):match("FLUTTER_DEV_LOG") then + return end + + if vim.b[ev.buf].flutter_autoscroll_attached then + return + end + vim.b[ev.buf].flutter_autoscroll_attached = true + + local pinned = true + + vim.api.nvim_create_autocmd("WinScrolled", { + callback = function() + local wins = vim.fn.win_findbuf(ev.buf) + for _, win in ipairs(wins) do + local info = vim.fn.getwininfo(win)[1] + if info then + pinned = info.botline >= vim.api.nvim_buf_line_count(ev.buf) + end + end + end, + }) + + vim.api.nvim_buf_attach(ev.buf, false, { + on_lines = function() + if not pinned then + return + end + vim.schedule(function() + local line_count = vim.api.nvim_buf_line_count(ev.buf) + local wins = vim.fn.win_findbuf(ev.buf) + for _, win in ipairs(wins) do + pcall(vim.api.nvim_win_set_cursor, win, { line_count, 0 }) + end + end) + end, + on_detach = function() + vim.b[ev.buf].flutter_autoscroll_attached = nil + end, + }) end, }) @@ -34,18 +69,36 @@ return { capabilities = require("cmp_nvim_lsp").default_capabilities(), on_attach = function(client, bufnr) client.server_capabilities.semanticTokensProvider = nil - client.server_capabilities.documentOnTypeFormattingProvider = nil + -- client.server_capabilities.documentOnTypeFormattingProvider = nil -- client.server_capabilities.diagnosticProvider = nil end, flags = { debounce_text_changes = 150, -- milliseconds }, settings = { - showTodos = true, - completeFunctionCalls = false, + showTodos = false, + completeFunctionCalls = true, renameFilesWithClasses = "prompt", enableSnippets = true, updateImportsOnRename = true, + analysisExcludedFolders = { + vim.fn.expand("$HOME/.pub-cache"), + vim.fn.expand("$HOME/Git/flutter"), + vim.fn.getcwd() .. "/android", + vim.fn.getcwd() .. "/app", + vim.fn.getcwd() .. "/build", + vim.fn.getcwd() .. "/build-dir", + vim.fn.getcwd() .. "/flatpak", + vim.fn.getcwd() .. "/ios", + vim.fn.getcwd() .. "/linux", + vim.fn.getcwd() .. "/macos", + vim.fn.getcwd() .. "/repo", + vim.fn.getcwd() .. "/web", + vim.fn.getcwd() .. "/windows", + vim.fn.getcwd() .. "/.dart_tool", + vim.fn.getcwd() .. "/.flatpak-builder", + vim.fn.getcwd() .. "/.idea", + }, }, }, widget_guides = { @@ -77,6 +130,8 @@ return { user_command("FEmulators", "FlutterEmulators", {}) user_command("FLogs", "FlutterLogToggle", {}) user_command("FLogsClear", "FlutterLogClear", {}) + user_command("FLogs", "FlutterLogToggle", {}) + user_command("FLspRestart", "lsp restart", {}) user_command("FPubGet", "FlutterPubGet", {}) user_command("FDevToolsStart", "FlutterDevTools", {}) user_command("FDevToolsOpen", "FlutterOpenDevTools", {}) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 0f25cd7..ee3754b 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -88,7 +88,7 @@ return { vim.api.nvim_create_autocmd("BufWritePre", { buffer = ev.buf, callback = function() - vim.lsp.buf.format({ async = false }) + vim.lsp.buf.format({ bufnr = ev.buf, async = false }) end, }) end, diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 7e107b3..6bc8b59 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -12,8 +12,21 @@ return { telescope.setup({ defaults = { - -- The "vimgrep_arguments" here are what make Telescope lag-free - -- when working with large generated codebases. + file_ignore_patterns = { + "%.dart_tool/", + "%.flatpak%-builder/", + "%.idea/", + "%.git/", + "build/", + "build%-dir/", + "android/", + "ios/", + "linux/", + "macos/", + "windows/", + "web/", + "%.g%.dart$", -- Catches generated files in find_files too + }, vimgrep_arguments = { "rg", "--color=never",