diff --git a/README.md b/README.md index d50bae9..d54a9a8 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ require("lspconfig").clangd.setup { >NOTE: You can set `vim.b.navic_lazy_update_context = true` for specific buffers, where you want the the updates to not occur on every `CursorMoved` event. It should help if you are facing performance issues in large files. Read the docs for example usage of this variable. Alternatively, you can pass `lazy_update_context=true` to the `setup` function to turn off context updates on the `CursorMoved` event completely for all buffers. It's useful when you just want context updates to happen only on `CursorHold` events and not on `CursorMoved`. +>NOTE: You can set `vim.b.navic_lazy_update_in_insert = false` for specific buffers, where you don't want for context updates to occur on `CursorMovedI` events. Just as with `vim.b.navic_lazy_update_context = true`, this should help mitigate performance issues in large files, for Insert mode. + +>NOTE: You can set `vim.b.navic_update_in_insert = false` to completely disable context updates for specific buffers, for `CursorMovedI` and `CursorHoldI` events. + ## 🪄 Customise Use the `setup` function to modify default parameters. @@ -80,6 +84,7 @@ Use the `setup` function to modify default parameters. * `depth_limit_indicator` : Icon to indicate that `depth_limit` was hit and the shown context is truncated. * `format_text` : A function to customize the text displayed in each segment. * `lazy_update_context` : If true, turns off context updates for the "CursorMoved" event. +* `update_in_insert` : If true, turns on context updates for the "CursorMovedI" and "CursorHoldI" events. * `safe_output` : Sanitize the output for use in statusline and winbar. * `click` : Single click to goto element, double click to open nvim-navbuddy on the clicked element. * `lsp` : @@ -126,6 +131,8 @@ navic.setup { depth_limit_indicator = "..", safe_output = true, lazy_update_context = false, + update_in_insert = false, + lazy_update_in_insert = false, click = false, format_text = function(text) return text diff --git a/doc/navic.txt b/doc/navic.txt index 3bbcf11..e2c74bb 100644 --- a/doc/navic.txt +++ b/doc/navic.txt @@ -202,6 +202,23 @@ you are facing performance issues on large files. Example usage end, }) < + +*vim.b.navic_lazy_update_in_insert* +Set it to true to update context only on CursorHoldI event, if using `update_in_insert`. Could be usefull if +you are facing performance issues on large files. Example usage +>lua + vim.api.nvim_create_autocmd("BufEnter", { + callback = function() + if vim.api.nvim_buf_line_count(0) > 10000 then + vim.b.navic_lazy_update_in_insert = true + end + end, + }) +< + +*vim.b.navic_update_in_insert* +Set it to false to disable updating context on CursorHoldI and CursorMovedI events. + ============================================================================= Customisation *navic-customise* @@ -243,6 +260,15 @@ Use |navic.setup| to override any of the default options behavior with more flexibility, like disabling context updates depending on file size, total lines etc. + update_in_insert: boolean + If true, turns on context updates for "CursorHoldI" and "CursorMovedI" events, + to see changes in context while in Insert mode. + + lazy_update_in_insert: boolean + If true, turns off context updates for the "CursorMovedI" event, + with updates happening only on the "CursorHoldI" event. + The same benefits as with the `lazy_update_context` option apply, just for Insert mode. + lsp : auto_attach: boolean Enable to have nvim-navic automatically attach to every LSP for @@ -296,6 +322,8 @@ Defaults >lua depth_limit_indicator = "..", safe_output = true, lazy_update_context = false, + update_in_insert = false, + lazy_update_in_insert = false, click = false } < diff --git a/lua/nvim-navic/init.lua b/lua/nvim-navic/init.lua index 65aadcd..351d198 100644 --- a/lua/nvim-navic/init.lua +++ b/lua/nvim-navic/init.lua @@ -11,6 +11,8 @@ local lib = require("nvim-navic.lib") ---@field depth_limit number | nil ---@field depth_limit_indicator string | nil ---@field lazy_update_context boolean | nil +---@field update_in_insert boolean | nil +---@field lazy_update_in_insert boolean | nil ---@field safe_output boolean | nil ---@field click boolean | nil ---@field lsp LspOptions | nil @@ -56,6 +58,8 @@ local config = { depth_limit_indicator = "..", safe_output = true, lazy_update_context = false, + update_in_insert = false, + lazy_update_in_insert = false, click = false, lsp = { auto_attach = false, @@ -147,6 +151,12 @@ function M.setup(opts) if opts.lazy_update_context then config.lazy_update_context = opts.lazy_update_context end + if opts.update_in_insert then + config.update_in_insert = opts.update_in_insert + end + if opts.lazy_update_in_insert then + config.lazy_update_in_insert = opts.lazy_update_in_insert + end if opts.click then config.click = opts.click end @@ -385,6 +395,33 @@ function M.attach(client, bufnr) buffer = bufnr, }) end + if config.update_in_insert then + vim.api.nvim_create_autocmd("CursorHoldI", { + callback = function() + if type(vim.b.navic_update_in_insert) == "nil" + or vim.b.navic_update_in_insert ~= false + then + lib.update_context(bufnr) + end + end, + group = navic_augroup, + buffer = bufnr, + }) + if config.lazy_update_context ~= true then + vim.api.nvim_create_autocmd("CursorMovedI", { + callback = function() + if vim.b.navic_lazy_update_in_insert ~= true + and (type(vim.b.navic_update_in_insert) == "nil" + or vim.b.navic_update_in_insert ~= false) + then + lib.update_context(bufnr) + end + end, + group = navic_augroup, + buffer = bufnr, + }) + end + end vim.api.nvim_create_autocmd("BufDelete", { callback = function() lib.clear_buffer_data(bufnr)