From 06f0332a8f8c8b30da42e7bd1f58d025d4c63784 Mon Sep 17 00:00:00 2001 From: asep komarudin Date: Fri, 3 Mar 2023 19:15:17 +0700 Subject: [PATCH] new feature custom lsp progress --- lazy-lock.json | 2 +- lua/custom/plugins/cmdline.lua | 8 ++- lua/custom/ui.lua | 6 +++ lua/plugins/init.lua | 92 ---------------------------------- lua/plugins/lspprogress.lua | 47 +++++++++++++++++ lua/plugins/ui.lua | 7 --- lua/user/lualine.lua | 7 ++- lua/user/treesitter.lua | 4 ++ 8 files changed, 71 insertions(+), 102 deletions(-) create mode 100644 lua/custom/ui.lua create mode 100644 lua/plugins/lspprogress.lua diff --git a/lazy-lock.json b/lazy-lock.json index 1d26292..cf9cb6b 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -12,7 +12,6 @@ "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, "code_runner.nvim": { "branch": "main", "commit": "a010649236fe245eaab2641a13228cd601499715" }, "dressing.nvim": { "branch": "master", "commit": "5f44f829481640be0f96759c965ae22a3bcaf7ce" }, - "fidget.nvim": { "branch": "main", "commit": "688b4fec4517650e29c3e63cfbb6e498b3112ba1" }, "friendly-snippets": { "branch": "main", "commit": "009887b76f15d16f69ae1341f86a7862f61cf2a1" }, "gitsigns.nvim": { "branch": "main", "commit": "bb808fc7376ed7bac0fbe8f47b83d4bf01738167" }, "impatient.nvim": { "branch": "main", "commit": "969f2c5c90457612c09cf2a13fee1adaa986d350" }, @@ -20,6 +19,7 @@ "jaq-nvim": { "branch": "master", "commit": "236296aae555657487d1bb4d066cbde9d79d8cd4" }, "lazy.nvim": { "branch": "main", "commit": "8d18ef44e769e98a8dc974ca85275de1d8cc7c04" }, "live-server": { "branch": "main", "commit": "ecd7c1418823b65dd2bca710587c80afe42c973e" }, + "lsp-progress.nvim": { "branch": "main", "commit": "9c0cf47587ee3cf2c9267ff2296876f214e631e5" }, "lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" }, "lunar.nvim": { "branch": "master", "commit": "29eedf78c430ad9acebdcba814d77619edbe2bac" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "e4badf7984f7a5f0ac7dc10657dbedbd99a82f94" }, diff --git a/lua/custom/plugins/cmdline.lua b/lua/custom/plugins/cmdline.lua index d6cd1cd..b194ba2 100644 --- a/lua/custom/plugins/cmdline.lua +++ b/lua/custom/plugins/cmdline.lua @@ -10,7 +10,13 @@ return { event = "BufWinEnter", config = function() vim.opt.lazyredraw = false - require("noice").setup() + require("noice").setup({ + lsp = { + progress = { + enabled = false, + }, + }, + }) end, }, { diff --git a/lua/custom/ui.lua b/lua/custom/ui.lua new file mode 100644 index 0000000..3396f6c --- /dev/null +++ b/lua/custom/ui.lua @@ -0,0 +1,6 @@ +local m = {} +-- 0 disable progress +-- 1 lualine lsp progress +-- 2 fidget progress +m.progress = 1 +return m diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index d8d666e..653e5de 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -66,98 +66,6 @@ return { { "", function() require("luasnip").jump(-1) end, mode = { "i", "s" } }, }, }, - -- for cmp - { - "hrsh7th/nvim-cmp", - version = false, -- last release is way too old - event = "InsertEnter", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "saadparwaiz1/cmp_luasnip", - "hrsh7th/cmp-nvim-lua", - -- { - -- "hrsh7th/cmp-cmdline", - -- --event = "BufWinEnter", - -- event = "VeryLazy", - -- config = function() - -- require("user.cmdline") - -- end, - -- }, - }, - opts = function() - local cmp = require("cmp") - local luasnip = require("luasnip") - - local check_backspace = function() - local col = vim.fn.col(".") - 1 - return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") - end - - return { - completion = { - completeopt = "menu,menuone,noinsert", - }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif check_backspace() then - fallback() - else - fallback() - end - end, { - "i", - "s", - }), - }), - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - { name = "nvim_lua" }, - }), - formatting = { - fields = { "kind", "abbr", "menu" }, - format = function(entry, vim_item) - vim_item.kind = string.format("%s", require("user.icons")["kind"][vim_item.kind]) - vim_item.menu = ({ - nvim_lsp = "(LSP)", - luasnip = "(Snippet)", - buffer = "(Buffer)", - path = "(Path)", - })[entry.source.name] - return vim_item - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - experimental = { - ghost_text = false, - native_menu = false, - }, - } - end, - }, { "neovim/nvim-lspconfig", event = "BufWinEnter", diff --git a/lua/plugins/lspprogress.lua b/lua/plugins/lspprogress.lua new file mode 100644 index 0000000..1b20108 --- /dev/null +++ b/lua/plugins/lspprogress.lua @@ -0,0 +1,47 @@ +local fidget = true +local lualine = false +local data_exists, custom_ui = pcall(require, "custom.ui") +if data_exists then + if type(custom_ui) == "table" then + if custom_ui.progress == 1 then + fidget = false + lualine = true + elseif custom_ui.progress == 2 then + fidget = true + lualine = false + elseif custom_ui.progress == 0 then + fidget = false + lualine = false + else + fidget = true + lualine = false + end + end +else + fidget = true + lualine = false +end +return { + { + "j-hui/fidget.nvim", + enabled = fidget, + event = "BufRead", + config = function() + require("fidget").setup() + end, + }, + { + "linrongbin16/lsp-progress.nvim", + enabled = lualine, + branch = "main", + event = { "BufRead" }, + config = function() + require("lsp-progress").setup({ + format = function(client_messages) + local sign = "" -- nf-fa-gear \uf013 + return #client_messages > 0 and (sign .. " " .. table.concat(client_messages, " ")) or sign + end, + }) + end, + }, +} diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index 829a00c..6abc96c 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -87,11 +87,4 @@ return { require("user.telescope") end, }, - { - "j-hui/fidget.nvim", - event = "BufRead", - config = function() - require("fidget").setup() - end, - }, } diff --git a/lua/user/lualine.lua b/lua/user/lualine.lua index f45dbe3..c485305 100644 --- a/lua/user/lualine.lua +++ b/lua/user/lualine.lua @@ -170,6 +170,11 @@ local lsp_info = { --icon = " ", icon = icons.ui.Gear .. "", } +local lsp_progress = {} +local data_exists, lspprogress = pcall(require, "lsp-progress") +if data_exists then + lsp_progress = lspprogress.progress +end lualine.setup({ options = { @@ -202,7 +207,7 @@ lualine.setup({ sections = { lualine_a = { branch }, lualine_b = { mode }, - lualine_c = { diagnostics, lsp_info }, + lualine_c = { diagnostics, lsp_info, lsp_progress }, -- lualine_c = { diagnostics, lsp_info, "lsp_progress" }, -- lualine_c = { file_name, lsp_info }, -- lualine_x = { "encoding", "fileformat", "filetype" }, diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua index e82342b..f5e5fcc 100644 --- a/lua/user/treesitter.lua +++ b/lua/user/treesitter.lua @@ -3,6 +3,10 @@ if not status_ok then return end configs.setup({ + ensure_installed = { + "lua", + "vim", + }, ignore_install = { "phpdoc" }, -- List of parsers to ignore installing highlight = { enable = true,