From 047417b36d5c21c944a1bb4c450517587ffe9e8e Mon Sep 17 00:00:00 2001 From: linrongbin16 Date: Tue, 2 Apr 2024 18:24:12 +0800 Subject: [PATCH] fix: fix integration tutorials on lazy dependency issue (#133) --- README.md | 14 ++-- minimal_init/minimal_lualine_init.lua | 69 +++++++++++++++++++ .../minimal_neodev_init.lua | 0 .../minimal_telescope_init.vim | 0 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 minimal_init/minimal_lualine_init.lua rename {test/minimal_init => minimal_init}/minimal_neodev_init.lua (100%) rename {test/minimal_init => minimal_init}/minimal_telescope_init.vim (100%) diff --git a/README.md b/README.md index 8f88b29..f2a7478 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,10 @@ lua require('lsp-progress').setup() ## Integration +> [!IMPORTANT] +> +> Don't directly put `require('lsp-progress').progress` as lualine component or heirline's component provider, wrap it with a function to avoid the dependency issue, see [#131](https://github.com/linrongbin16/lsp-progress.nvim/issues/131). + ### [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim) ```lua @@ -248,7 +252,9 @@ require("lualine").setup({ lualine_b = { ... }, lualine_c = { -- invoke `progress` here. - require('lsp-progress').progress, + function() + return require('lsp-progress').progress() + end, }, ... } @@ -267,7 +273,9 @@ vim.api.nvim_create_autocmd("User", { ```lua local LspProgress = { - provider = require('lsp-progress').progress, + provider = function() + return require('lsp-progress').progress(), + end, update = { 'User', pattern = 'LspProgressStatusUpdated', @@ -280,11 +288,9 @@ local LspProgress = { local StatusLine = { -- Other StatusLine components { ... }, - { ... }, -- Lsp progress status component here LspProgress, - ... } require('heirline').setup({ diff --git a/minimal_init/minimal_lualine_init.lua b/minimal_init/minimal_lualine_init.lua new file mode 100644 index 0000000..824b02f --- /dev/null +++ b/minimal_init/minimal_lualine_init.lua @@ -0,0 +1,69 @@ +-- bootstrap lazy +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + lazypath, + }) +end +vim.opt.runtimepath:prepend(lazypath) + +-- install plugins +local plugins = { + { + "nvim-lualine/lualine.nvim", + event = "VimEnter", + dependencies = { + "nvim-tree/nvim-web-devicons", + { + "linrongbin16/lsp-progress.nvim", + opts = {}, + }, + }, + config = function(_, opts) + require("lualine").setup(opts) + + vim.api.nvim_create_augroup("lualine_augroup", { clear = true }) + vim.api.nvim_create_autocmd("User", { + group = "lualine_augroup", + pattern = "LspProgressStatusUpdated", + callback = require("lualine").refresh, + }) + end, + opts = { + options = { + component_separators = { left = "|", right = "|" }, + globalstatus = true, + }, + sections = { + lualine_a = { + { + "mode", + fmt = function(str) + return str:sub(1, 1) + end, + }, + }, + lualine_b = { + { "branch", icons_enabled = false }, + }, + lualine_c = { + function() + return require("lsp-progress").progress() + end, + }, + }, + tabline = { + lualine_a = { + "buffers", + }, + }, + }, + }, +} + +-- Setup lazy.nvim +require("lazy").setup(plugins) diff --git a/test/minimal_init/minimal_neodev_init.lua b/minimal_init/minimal_neodev_init.lua similarity index 100% rename from test/minimal_init/minimal_neodev_init.lua rename to minimal_init/minimal_neodev_init.lua diff --git a/test/minimal_init/minimal_telescope_init.vim b/minimal_init/minimal_telescope_init.vim similarity index 100% rename from test/minimal_init/minimal_telescope_init.vim rename to minimal_init/minimal_telescope_init.vim