diff options
| -rw-r--r-- | lua/keys.lua | 4 | ||||
| -rw-r--r-- | lua/opts.lua | 5 | ||||
| -rw-r--r-- | lua/plugins/bufferline.lua | 323 | ||||
| -rw-r--r-- | lua/plugins/bufferline.lua-202209041657.backup | 322 | ||||
| -rw-r--r-- | lua/plugins/cmp-22.10.14-23:39-bak.lua | 161 | ||||
| -rw-r--r-- | lua/plugins/cmp.lua | 188 | ||||
| -rw-r--r-- | lua/plugins/colorscheme.lua | 3 | ||||
| -rw-r--r-- | lua/plugins/heirline.backup.lua | 733 | ||||
| -rw-r--r-- | lua/plugins/heirline.backup2.lua | 1921 | ||||
| -rw-r--r-- | lua/plugins/heirline.lua-202210111610.backup | 1452 | ||||
| -rw-r--r-- | lua/plugins/heirlinenew.lua | 1342 | ||||
| -rw-r--r-- | lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua | 301 | ||||
| -rw-r--r-- | lua/plugins/lsp-22.10.12-21:29-bak.lua | 301 | ||||
| -rw-r--r-- | lua/plugins/lsp-22.10.14-23:39-bak.lua | 422 | ||||
| -rw-r--r-- | lua/plugins/lsp.lua | 31 | ||||
| -rw-r--r-- | lua/plugins/lspOld.lsp | 531 | ||||
| -rw-r--r-- | lua/plugins/lspconfig.lua | 148 | ||||
| -rw-r--r-- | lua/plugins/lspsaga-22.10.13-22:51-bak.lua | 61 | ||||
| -rw-r--r-- | lua/plugins/lspsaga.lua | 146 | ||||
| -rw-r--r-- | lua/plugins/nvim-tree.lua | 2 | ||||
| -rw-r--r-- | lua/plugins/treesitter.lua | 27 | ||||
| -rw-r--r-- | lua/scripts/lsp-ext.lua | 48 | ||||
| -rw-r--r-- | lua/scripts/toggleLsp.lua | 40 |
23 files changed, 8269 insertions, 243 deletions
diff --git a/lua/keys.lua b/lua/keys.lua index 29b59c4..55e24ac 100644 --- a/lua/keys.lua +++ b/lua/keys.lua @@ -193,7 +193,7 @@ map("n", "<leader>fb", "<cmd>lua require('telescope.builtin').current_buffer_fuz --map("n", "<leader>fz", ":FZF<CR>", opts) --map("t", [[<Esc><Esc>]], [[<C-\><C-N>]], opts) --map("n", "ff", ":NvimTreeToggle<CR>", {}) -map("n", "<leader>ff", ":NvimTreeToggle<CR>", {}) +map("n", "<leader>f", ":NvimTreeToggle<CR>", {}) -- This <Esc><Esc> avoids crashing fzf menu running in TERMINAL MODE (:q if you do) -- Find files in config dirs --key_map("n", "<leader>e", ":lua require('plugins.telescope').find_configs()<CR>", opts) @@ -369,7 +369,7 @@ map("n", "<leader>.", ":unhide<CR>", opts) ---- Open the current file in the default program (on Mac this should just be just `open`) --keymap('n', '<leader>x', ':!xdg-open %<cr><cr>') ---keymap("n", "<leader>ff", "<cmd>lua require('telescope.builtin').find_files()<cr>", opts) +map("n", "<leader>ff", "<cmd>lua require('telescope.builtin').find_files()<cr>", opts) --keymap("n", "<leader>ff", "<cmd>lua require('telescope.builtin').find_files cwd=..()<cr>", opts) --keymap('n', '<leader>k', ':nohlsearch<CR>') -- diff --git a/lua/opts.lua b/lua/opts.lua index b52bcc8..2bc70d6 100644 --- a/lua/opts.lua +++ b/lua/opts.lua @@ -117,9 +117,10 @@ vim.opt.hlsearch = true -- Keep matches highlighted. vim.opt.ignorecase = true -- ignore case in search patterns UNLESS /C or capital in search vim.opt.smartcase = true -- smart case vim.opt.synmaxcol = 200 -- Only highlight the first 200 columns. -vim.opt.winblend = 0 -- +vim.opt.winblend = 30 vim.opt.wildoptions = "pum" -- -vim.opt.pumblend = 5 -- +--vim.opt.pumblend = 5 -- +vim.opt.pumblend=15 vim.opt.pumheight = 10 -- pop up menu height -- Better Completion diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..6488f29 --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,323 @@ +require("bufferline").setup({ + options = { + numbers = "buffer_id", -- | "ordinal" | "buffer_id" | "both" | "none" | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + --indicator = { + -- icon = '', -- this should be omitted if indicator style is not 'icon' + -- style = 'icon', -- | 'underline' | 'none', + --}, + --indicator_icon = " ", + --left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + modified_icon = '●', + left_trunc_marker = "", + right_trunc_marker = "", + show_buffer_close_icons = true, + --diagnostics = "nvim_lsp", + diagnostics = false, --"nvim_lsp", --false, -- | "nvim_lsp" | "coc", + diagnostics_update_in_insert = false, + buffer_close_icon = "", + separator_style = "thin", + enforce_regular_tabs = true, + always_show_bufferline = true, + max_name_length = 25, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + highlight = "StatusLine", + text_align = "center", + }, + }, + custom_areas = { + right = function() + local result = {} + local error = vim.diagnostic.get_count(0, [[Error]]) + local warning = vim.diagnostic.get_count(0, [[Warning]]) + local info = vim.diagnostic.get_count(0, [[Information]]) + local hint = vim.diagnostic.get_count(0, [[Hint]]) + + if error ~= 0 then + result[1] = { text = " " .. error, fg = "#EC5241" } + end + + if warning ~= 0 then + result[2] = { text = " " .. warning, fg = "#EFB839" } + end + + if hint ~= 0 then + result[3] = { text = " " .. hint, fg = "#A3BA5E" } + end + + if info ~= 0 then + result[4] = { text = " " .. info, fg = "#7EA9A7" } + end + + return result + end, + }, + }, + highlights = { + background = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab_selected = { + fg = "#fdf6e3", + bg = "#002b36", + --fg = tabline_sel_bg, + }, + tab_close = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_selected = { + fg = "002b36", + bg = "#fdf6e3", + bold = true, + italic = true, + }, + numbers = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + hint = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + hint_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + error = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + error_diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + modified = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + duplicate_selected = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true, + }, + duplicate_visible = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + duplicate = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + separator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator = { + fg = "#fdf6e3", + bg = "#002b36", + }, + indicator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + pick_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick_visible = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + --offset_separator = { + -- fg = win_separator_fg, + -- bg = separator_background_color, + --}, + } +}) diff --git a/lua/plugins/bufferline.lua-202209041657.backup b/lua/plugins/bufferline.lua-202209041657.backup new file mode 100644 index 0000000..1d45e5f --- /dev/null +++ b/lua/plugins/bufferline.lua-202209041657.backup @@ -0,0 +1,322 @@ +require("bufferline").setup({ + options = { + numbers = "buffer_id", -- | "ordinal" | "buffer_id" | "both" | "none" | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + --indicator = { + -- icon = '', -- this should be omitted if indicator style is not 'icon' + -- style = 'icon', -- | 'underline' | 'none', + --}, + --indicator_icon = " ", + --left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions" + modified_icon = '●', + left_trunc_marker = "", + right_trunc_marker = "", + show_buffer_close_icons = true, + --diagnostics = "nvim_lsp", + diagnostics = false, --"nvim_lsp", --false, -- | "nvim_lsp" | "coc", + diagnostics_update_in_insert = false, + buffer_close_icon = "", + separator_style = "slant", + enforce_regular_tabs = true, + always_show_bufferline = true, + max_name_length = 25, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + highlight = "StatusLine", + text_align = "center", + }, + }, + custom_areas = { + right = function() + local result = {} + local error = vim.diagnostic.get_count(0, [[Error]]) + local warning = vim.diagnostic.get_count(0, [[Warning]]) + local info = vim.diagnostic.get_count(0, [[Information]]) + local hint = vim.diagnostic.get_count(0, [[Hint]]) + + if error ~= 0 then + result[1] = { text = " " .. error, fg = "#EC5241" } + end + + if warning ~= 0 then + result[2] = { text = " " .. warning, fg = "#EFB839" } + end + + if hint ~= 0 then + result[3] = { text = " " .. hint, fg = "#A3BA5E" } + end + + if info ~= 0 then + result[4] = { text = " " .. info, fg = "#7EA9A7" } + end + + return result + end, + }, + }, + highlights = { + background = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab = { + fg = "#fdf6e3", + bg = "#002b36", + }, + tab_selected = { + fg = tabline_sel_bg, + bg = "#002b36", + }, + tab_close = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + close_button_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + buffer_selected = { + fg = normal_fg, + bg = "#002b36", + bold = true, + italic = true, + }, + numbers = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + numbers_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + hint = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + hint_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + hint_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + hint_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + info_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + info_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + info_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + warning_diagnostic = { + fg = "#fdf6e3", + sp = "#002b36", + bg = "#002b36", + }, + warning_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + warning_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + error = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + error_diagnostic = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + }, + error_diagnostic_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + error_diagnostic_selected = { + fg = "#fdf6e3", + bg = "#002b36", + sp = "#002b36", + bold = true, + italic = true, + }, + modified = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + modified_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + duplicate_selected = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true, + }, + duplicate_visible = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + duplicate = { + fg = "#fdf6e3", + bg = "#002b36", + italic = true + }, + separator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator_visible = { + fg = "#fdf6e3", + bg = "#002b36", + }, + separator = { + fg = "#fdf6e3", + bg = "#002b36", + }, + indicator_selected = { + fg = "#fdf6e3", + bg = "#002b36", + }, + pick_selected = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick_visible = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + pick = { + fg = "#fdf6e3", + bg = "#002b36", + bold = true, + italic = true, + }, + --offset_separator = { + -- fg = win_separator_fg, + -- bg = separator_background_color, + --}, + } +}) diff --git a/lua/plugins/cmp-22.10.14-23:39-bak.lua b/lua/plugins/cmp-22.10.14-23:39-bak.lua new file mode 100644 index 0000000..3b0a8f5 --- /dev/null +++ b/lua/plugins/cmp-22.10.14-23:39-bak.lua @@ -0,0 +1,161 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +vim.o.completeopt = "menu,menuone,noselect" + +--require("luasnip/loaders/from_vscode").lazy_load() +--local luasnip = require "luasnip" + +cmp.setup { + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = { + ['<C-Space>'] = cmp.mapping.complete(), + ['<C-e>'] = cmp.mapping.close(), + ['<CR>'] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + ['<Down>'] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), {'i'}), + ['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), {'i'}), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'treesitter' }, + { name = 'luasnip' }, + } +} +--local lspkind = require("lspkind") +--cmp.setup({ +-- formatting = { +-- format = lspkind.cmp_format({ +-- mode = "symbol", -- show only symbol annotations +-- maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) +-- ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) +-- +-- -- The function below will be called before any actual modifications from lspkind +-- -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) +-- before = function(entry, vim_item) +-- --... +-- return vim_item +-- end, +-- }), +-- }, +--}) +-- +--require("luasnip/loaders/from_vscode").lazy_load() +-- +---- פּ ﯟ some other good icons +--local kind_icons = { +-- Text = "", +-- Method = "", +-- Function = "", +-- Constructor = "⚙️", +-- Field = "", +-- Variable = "", +-- Class = "ﴯ", +-- Interface = "", +-- Module = "", +-- Property = "ﰠ", +-- Unit = "", +-- Value = "", +-- Enum = "", +-- Keyword = "", +-- Snippet = "", +-- Color = "", +-- File = "", +-- Reference = "", +-- Folder = "", +-- EnumMember = "", +-- Constant = "", +-- Struct = "", +-- Event = "", +-- Operator = "", +-- TypeParameter = "", +--} +-- +---- find more here: https://www.nerdfonts.com/cheat-sheet +-- +--cmp.setup({ +-- snippet = { +-- expand = function(args) +-- require("luasnip").lsp_expand(args.body) +-- end, +-- }, +-- mapping = cmp.mapping.preset.insert({ +-- ["<C-d>"] = cmp.mapping.scroll_docs(-4), +-- ["<C-f>"] = cmp.mapping.scroll_docs(4), +-- ["<C-Space>"] = cmp.mapping.complete(), +-- ["<C-e>"] = cmp.mapping.close(), +-- ["<CR>"] = cmp.mapping.confirm({ +-- behavior = cmp.ConfirmBehavior.Replace, +-- select = true, +-- }), +-- }), +-- sources = cmp.config.sources({ +-- { name = "path" }, +-- { name = "nvim_lsp", keyword_length = 3 }, +-- { name = "buffer", keyword_length = 3 }, +-- { name = "luasnip", keyword_length = 4 }, +-- { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, +-- --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this +-- --{name = 'luasnip', keyword_length = 2}, +-- }), +-- formatting = { +-- fields = { "kind", "abbr", "menu" }, +-- format = function(entry, vim_item) +-- -- Kind icons +-- vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) +-- -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind +-- vim_item.menu = ({ +-- nvim_lsp = "[LSP]", +-- luasnip = "[Snippet]", +-- buffer = "[Buffer]", +-- path = "[Path]", +-- })[entry.source.name] +-- return vim_item +-- end, +-- }, +-- confirm_opts = { +-- behavior = cmp.ConfirmBehavior.Replace, +-- select = false, +-- }, +-- window = { +-- documentation = { +-- border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, +-- }, +-- }, +-- experimental = { +-- ghost_text = true, +-- native_menu = false, +-- --view = { +-- -- entries = "native" +-- --}, +-- }, +--}) +-- +----vim.cmd([[ +---- set completeopt=menuone,noinsert,noselect +---- highlight! default link CmpItemKind CmpItemMenuDefault +----]]) +-- +--cmp.setup.cmdline("/", { +-- mapping = cmp.mapping.preset.cmdline(), +-- sources = { +-- { name = "buffer" }, +-- }, +--}) +-- +--cmp.setup.cmdline(":", { +-- mapping = cmp.mapping.preset.cmdline(), +-- sources = cmp.config.sources({ +-- { name = "path" }, +-- }, { +-- { name = "cmdline" }, +-- }), +--}) diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index 93bc5b2..fcec30f 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,58 +1,75 @@ + +-- Setup nvim-cmp. +vim.opt.completeopt = "menu,menuone,noselect" + local cmp_status_ok, cmp = pcall(require, "cmp") if not cmp_status_ok then return end -local lspkind = require("lspkind") -cmp.setup({ - formatting = { - format = lspkind.cmp_format({ - mode = "symbol", -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) - - -- The function below will be called before any actual modifications from lspkind - -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) - before = function(entry, vim_item) - --... - return vim_item - end, - }), - }, -}) -require("luasnip/loaders/from_vscode").lazy_load() +local opts = { + -- whether to highlight the currently hovered symbol + -- disable if your cpu usage is higher than you want it + -- or you just hate the highlight + -- default: true + highlight_hovered_item = true, --- פּ ﯟ some other good icons -local kind_icons = { - Text = "", - Method = "", - Function = "", - Constructor = "⚙️", - Field = "", - Variable = "", - Class = "ﴯ", - Interface = "", - Module = "", - Property = "ﰠ", - Unit = "", - Value = "", - Enum = "", - Keyword = "", - Snippet = "", - Color = "", - File = "", - Reference = "", - Folder = "", - EnumMember = "", - Constant = "", - Struct = "", - Event = "", - Operator = "", - TypeParameter = "", + -- whether to show outline guides + -- default: true + show_guides = true, } +require("symbols-outline").setup(opts) --- find more here: https://www.nerdfonts.com/cheat-sheet +local snippets_paths = function() + local plugins = { "friendly-snippets" } + local paths = {} + local path + local root_path = vim.env.HOME .. "/.vim/plugged/" + for _, plug in ipairs(plugins) do + path = root_path .. plug + if vim.fn.isdirectory(path) ~= 0 then + table.insert(paths, path) + end + end + return paths +end + +require("luasnip.loaders.from_vscode").lazy_load({ + paths = snippets_paths(), + include = nil, -- Load all languages + exclude = {}, +}) + +local lspkind = require("lspkind") + +--local kind_icons = { +-- Text = "", +-- Method = "", +-- Function = "", +-- Constructor = "⚙️", +-- Field = "", +-- Variable = "", +-- Class = "ﴯ", +-- Interface = "", +-- Module = "", +-- Property = "ﰠ", +-- Unit = "", +-- Value = "", +-- Enum = "", +-- Keyword = "", +-- Snippet = "", +-- Color = "", +-- File = "", +-- Reference = "", +-- Folder = "", +-- EnumMember = "", +-- Constant = "", +-- Struct = "", +-- Event = "", +-- Operator = "", +-- TypeParameter = "", +--} cmp.setup({ snippet = { @@ -61,62 +78,65 @@ cmp.setup({ end, }, mapping = cmp.mapping.preset.insert({ - ["<C-d>"] = cmp.mapping.scroll_docs(-4), - ["<C-f>"] = cmp.mapping.scroll_docs(4), - ["<C-Space>"] = cmp.mapping.complete(), +-- ["<CR>"] = cmp.mapping.confirm({ +-- behavior = cmp.ConfirmBehavior.Replace, +-- select = true, +-- }), + ['<C-y>'] = cmp.mapping.confirm({ select = true }), ["<C-e>"] = cmp.mapping.close(), - ["<CR>"] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - }), - sources = cmp.config.sources({ - { name = "path" }, - { name = "nvim_lsp", keyword_length = 3 }, - { name = "buffer", keyword_length = 3 }, - { name = "luasnip", keyword_length = 4 }, - { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, - --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this - --{name = 'luasnip', keyword_length = 2}, + ["<C-u>"] = cmp.mapping.scroll_docs(-4), + ["<C-d>"] = cmp.mapping.scroll_docs(4), + ["<C-Space>"] = cmp.mapping.complete(), }), + formatting = { - fields = { "kind", "abbr", "menu" }, + fields = { "abbr", "kind", "menu" }, format = function(entry, vim_item) -- Kind icons - vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + --vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + vim_item.kind = lspkind.presets.default[vim_item.kind] -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind vim_item.menu = ({ - nvim_lsp = "[LSP]", - luasnip = "[Snippet]", - buffer = "[Buffer]", - path = "[Path]", + nvim_lsp = "LSP", + luasnip = "Snip", + buffer = "Buf", + path = "Path", + cmdline = "Cmd", })[entry.source.name] return vim_item end, }, - confirm_opts = { + sources = cmp.config.sources({ + { name = "path" }, + { name = "nvim_lsp", keyword_length = 3 }, + { name = "luasnip", keyword_length = 4 }, + { name = "buffer", keyword_length = 3 }, + --{ name = 'treesitter' }, + { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, + --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this + --{name = 'luasnip', keyword_length = 2}, + }), + confirm_opts = { behavior = cmp.ConfirmBehavior.Replace, select = false, }, window = { - documentation = { - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - }, - }, - experimental = { - ghost_text = true, - native_menu = false, - --view = { - -- entries = "native" + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + --documentation = { + -- border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, --}, }, +-- experimental = { +-- ghost_text = true, +-- native_menu = true, +-- --native_menu = false, +-- --view = { +-- -- entries = "native" +-- --}, +-- }, }) ---vim.cmd([[ --- set completeopt=menuone,noinsert,noselect --- highlight! default link CmpItemKind CmpItemMenuDefault ---]]) - cmp.setup.cmdline("/", { mapping = cmp.mapping.preset.cmdline(), sources = { @@ -132,3 +152,5 @@ cmp.setup.cmdline(":", { { name = "cmdline" }, }), }) + + diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index a7653e2..11d8834 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -20,6 +20,9 @@ vim.api.nvim_command("highlight StatusLine guibg=#333842 gui=bold") vim.api.nvim_command("highlight TabLineSel guibg=#333842 gui=bold") vim.api.nvim_command("highlight TabLineFill guibg=none gui=bold") vim.api.nvim_command("highlight WinBar guibg=none gui=bold") +--vim.api.nvim_command("highlight PmenuSel guibg=none") +vim.api.nvim_command("highlight NormalFloat guibg=none") +--vim.api.nvim_command("highlight winblend guibg=none") --vim.api.nvim_command("highlight StatusLine guibg=none gui=bold") --vim.api.nvim_command("highlight StatusLineNC guibg=none gui=bold") --vim.api.nvim_command("highlight StatusLineNC guibg=none ctermfg=Cyan guifg=#80a0ff gui=bold") diff --git a/lua/plugins/heirline.backup.lua b/lua/plugins/heirline.backup.lua new file mode 100644 index 0000000..d65de92 --- /dev/null +++ b/lua/plugins/heirline.backup.lua @@ -0,0 +1,733 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +require("nvim-gps").setup({ + icons = { + ["class-name"] = " ", + ["function-name"] = " ", + ["method-name"] = " ", + ["container-name"] = "炙", + ["tag-name"] = "炙", + }, +}) + +vim.o.laststatus = 3 + +local colors = { + bg = "#333842", + brown = "#504945", + white = "#f8f8f0", + grey = "#8F908A", + black = "#000000", + pink = "#f92672", + green = "#a6e22e", + blue = "#66d9ef", + yellow = "#e6db74", + orange = "#fd971f", + purple = "#ae81ff", + red = "#e95678", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +local ViMode = { + -- get vim current mode, this information will be required by the provider + -- and the highlight functions, so we compute it only once per component + -- evaluation and store it as a component attribute + init = function(self) + self.mode = vim.fn.mode(1) -- :h mode() + end, + -- Now we define some dictionaries to map the output of mode() to the + -- corresponding string and color. We can put these into `static` to compute + -- them at initialisation time. + static = { + mode_names = { + -- change the strings if you like it vvvvverbose! + ["n"] = "NORMAL ", + ["no"] = "N·OPERATOR PENDING ", + ["v"] = "VISUAL ", + ["V"] = "V·LINE ", + [""] = "V·BLOCK ", + ["s"] = "SELECT ", + ["S"] = "S·LINE ", + [""] = "S·BLOCK ", + ["i"] = "INSERT ", + ["R"] = "REPLACE ", + ["Rv"] = "V·REPLACE ", + ["c"] = "COMMAND ", + ["cv"] = "VIM EX ", + ["ce"] = "EX ", + ["r"] = "PROMPT ", + ["rm"] = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + ["t"] = "TERMINAL ", + }, + mode_colors = { + n = colors.green, + i = colors.pink, + v = colors.blue, + V = colors.blue, + [""] = colors.blue, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + }, + -- We can now access the value of mode() that, by now, would have been + -- computed by `init()` and use it to index our strings dictionary. + -- note how `static` fields become just regular attributes once the + -- component is instantiated. + -- To be extra meticulous, we can also add some vim statusline syntax to + -- control the padding and make sure our string is always at least 2 + -- characters long. Plus a nice Icon. + provider = function(self) + return " %2(" .. self.mode_names[self.mode] .. "%)" + end, + -- Same goes for the highlight. Now the foreground will change according to the current mode. + hl = function(self) + local mode = self.mode:sub(1, 1) -- get only the first mode character + return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } + end, +} + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} +-- We can now define some children separately and add them later + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "[No Name]" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + hl = { fg = utils.get_highlight("Directory").fg, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return "" + end + end, + hl = { fg = colors.orange }, + }, +} + +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + -- use `force` because we need to override the child's hl foreground + return { fg = colors.cyan, bold = true, force = true, bg = colors.bg } + end + end, +} + +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local Diagnostics = { + condition = conditions.has_diagnostics, + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, +} + +local Git = { + condition = conditions.is_git_repo, + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + hl = { fg = colors.orange, bg = colors.bg }, + { + -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + return count > 0 and (" " .. count) + end, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + return count > 0 and (" " .. count) + end, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + return count > 0 and (" " .. count) + end, + hl = { fg = colors.git.change, bg = colors.bg }, + }, +} + +local WorkDir = { + provider = function() + local icon = " " + local cwd = vim.fn.getcwd(0) + cwd = vim.fn.fnamemodify(cwd, ":~") + if not conditions.width_percent_below(#cwd, 0.25) then + cwd = vim.fn.pathshorten(cwd) + end + local trail = cwd:sub(-1) == "/" and "" or "/" + return icon .. cwd .. trail + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, +} + +local TerminalName = { + -- we could add a condition to check that buftype == 'terminal' + -- or we could do that later (see #conditional-statuslines below) + provider = function() + local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") + return " " .. tname + end, + hl = { bold = true, bg = colors.bg }, +} + +local Ruler = { + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + provider = "%7 %p%% Ln %l, Col %c", +} + +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " " } + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileEncoding = { + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:upper() + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + FileEncoding, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileNameShort = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":t") + if filename == "" then + return "[No Name]" + end + return filename + end, + hl = { fg = colors.gray, bg = colors.bg }, +} + +local FileNameShortBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileNameShortBlock = utils.insert( + FileNameShortBlock, + FileIcon, + FileNameShort, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local Gps = { + condition = require("nvim-gps").is_available, + provider = function() + local loc = require("nvim-gps").get_location() + if loc == "" then + return "" + end + return "> " .. loc + end, + hl = { fg = colors.gray, bg = colors.bg }, +} + +local DefaultStatusline = { + ViMode, + Space, + FileNameBlock, + Space, + Diagnostics, + Align, + Ruler, + Space, + FileInfoBlock, + Space, + Git, +} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + FileType, + Space, + Align, +} + +local TerminalStatusline = { + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + TerminalName, + Align, +} + +local StatusLines = { + fallthrough = false, + SpecialStatusline, + TerminalStatusline, + DefaultStatusline, +} + +local GSpace = { provider = " ", hl = { bg = colors.bg } } + +local WinBars = { + fallthrough = false, + { + -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix", "nofile", "promt" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + provider = "", + }, + { + -- An inactive winbar for regular files + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) and not conditions.is_active() + end, + utils.surround( + { "", "" }, + colors.bright_bg, + { hl = { fg = "gray", force = true }, GSpace, TerminalName, Align } + ), + }, + { + -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, colors.dark_red, { + GSpace, + TerminalName, + Align, + }), + }, + { + -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround( + { "", "" }, + colors.bright_bg, + { hl = { fg = "gray", force = true }, GSpace, FileNameShortBlock, Align } + ), + }, + -- A winbar for regular files + { GSpace, FileNameShortBlock, GSpace, Gps, Align }, +} + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "[No Name]" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+]" + end + end, + hl = { fg = colors.green }, + }, + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return "" + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineDiagnostics = { + static = { + error_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = " " .. vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + init = function(self) + self.errors = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(self.bufnr, { severity = vim.diagnostic.severity.INFO }) + end, + { + provider = function(self) + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + else + return "TabLine" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = true }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineFileIcon, + TablineFileName, + TablineFileFlags, + TablineDiagnostics, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.bo[self.bufnr].modified + end, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLine").bg + end +end, { TablineFileNameBlock, TablineCloseButton }) + +-- and here we go +local BufferLine = utils.make_buflist( + TablineBufferBlock, + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + hl = "TabLine", +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +local TabLine = { TabLineOffset, BufferLine, TabPages } + +require("heirline").setup(StatusLines, WinBars, TabLine) + +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +vim.api.nvim_create_augroup("Heirline", { clear = true }) +vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + local colors = setup_colors() + utils.on_colorscheme(colors) + end, + group = "Heirline", +}) + +local function get_bufs() + return vim.tbl_filter(function(bufnr) + return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted + end, vim.api.nvim_list_bufs()) +end + +local function goto_buf(index) + local bufs = get_bufs() + if index > #bufs then + index = #bufs + end + vim.api.nvim_win_set_buf(0, bufs[index]) +end + +local function addKey(key, index) + vim.keymap.set("", "<A-" .. key .. ">", function() + goto_buf(index) + end, { noremap = true, silent = true }) +end + +for i = 1, 9 do + addKey(i, i) +end +addKey("0", 10) diff --git a/lua/plugins/heirline.backup2.lua b/lua/plugins/heirline.backup2.lua new file mode 100644 index 0000000..9f5c4ca --- /dev/null +++ b/lua/plugins/heirline.backup2.lua @@ -0,0 +1,1921 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +-- Colors +--local colors = { +-- bright_bg = utils.get_highlight("Folded").bg, +-- bright_fg = utils.get_highlight("Folded").fg, +-- red = utils.get_highlight("DiagnosticError").fg, +-- dark_red = utils.get_highlight("DiffDelete").bg, +-- green = utils.get_highlight("String").fg, +-- blue = utils.get_highlight("Function").fg, +-- gray = utils.get_highlight("NonText").fg, +-- orange = utils.get_highlight("Constant").fg, +-- purple = utils.get_highlight("Statement").fg, +-- cyan = utils.get_highlight("Special").fg, +-- diag_warn = utils.get_highlight("DiagnosticWarn").fg, +-- diag_error = utils.get_highlight("DiagnosticError").fg, +-- diag_hint = utils.get_highlight("DiagnosticHint").fg, +-- diag_info = utils.get_highlight("DiagnosticInfo").fg, +-- git_del = utils.get_highlight("diffDeleted").fg, +-- git_add = utils.get_highlight("diffAdded").fg, +-- git_change = utils.get_highlight("diffChanged").fg, +--} + +--local colors = { +-- gray = '#23232e', +-- lightgray = '#5f6a8e', +-- orange = '#ffb86c', +-- purple = '#bd93f9', +-- red = '#ff5555', +-- yellow = '#f1fa8c', +-- green = '#50fa7b', +-- white = '#f8f8f2', +-- black = '#282a36', +--} +local colors = { + bg = "#333842", + nobg = nil, + bright_fg = "#ffffff", + bright_bg = "#000000", + brown = "#504945", + white = "#f8f8f0", + grey = "#8F908A", + pink = "#f92672", + --green = "#a6e22e", + green = "#AAD94C", + --blue = "#66d9ef", + blue = "#39BAE6", + yellow = "#e6db74", + --orange = "#fd971f", + orange = "#FA8D3F", + purple = "#ae81ff", + --red = "#e95678", + red = "#F07171", + cyan = "#66d9eC", + mode_fg = "#242424", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +--local mode_lable = { +-- n = 'NORMAL', +-- no = 'OPPEND', +-- nov = 'N?', +-- noV = 'N?', +-- ['no\22'] = 'N?', +-- niI = 'Ni', +-- niR = 'Nr', +-- niV = 'Nv', +-- nt = 'N-TERM', +-- v = 'VISUAL', +-- vs = 'Vs', +-- V = 'V-LINE', +-- Vs = 'Vs', +-- ['\22'] = 'V-BLCK', +-- ['\22s'] = '^V', +-- s = 'SELECT', +-- S = 'S-LINE', +-- ['\19'] = 'S-BLCK', +-- i = 'INSERT', +-- ic = 'ICOMPL', +-- ix = 'Ix', +-- R = 'REPLACE', +-- Rc = 'Rc', +-- Rx = 'Rx', +-- Rv = 'VRPLCE', +-- Rvc = 'Rv', +-- Rvx = 'Rv', +-- c = 'CMMAND', +-- cv = 'PROMPT', +-- r = '...', +-- rm = 'MORE', +-- ['r?'] = 'CNFIRM', +-- ['!'] = 'SHELL', +-- t = 'TERM', +--} +-- +--local mode_colors_table = { +-- n = 'red', +-- no = 'blue', +-- nov = 'blue', +-- noV = 'blue', +-- niI = 'red', +-- niR = 'red', +-- niV = 'red', +-- nt = 'red', +-- v = 'cyan', +-- vs = 'cyan', +-- V = 'cyan', +-- Vs = 'cyan', +-- ['\22'] = 'cyan', +-- ['\22s'] = 'cyan', +-- s = 'purple', +-- S = 'purple', +-- ['\19'] = 'purple', +-- i = 'blue', +-- ic = 'blue', +-- ix = 'blue', +-- R = 'orange', +-- Rc = 'orange', +-- Rx = 'orange', +-- Rv = 'orange', +-- Rvc = 'orange', +-- Rvx = 'orange', +-- c = 'green', +-- cv = 'green', +-- r = 'green', +-- rm = 'green', +-- ['r?'] = 'green', +-- ['!'] = 'red', +-- t = 'red', +--} +-- +--local mode_colors = setmetatable({ +-- n = { fg = 'red' } +--}, { +-- __index = function(_, mode) +-- return { +-- fg = 'mode_fg', +-- bg = mode_colors_table[mode], +-- } +-- end +--}) +-- +-- +--local VimModeNormal = { +-- condition = function(self) +-- return self.mode == 'n' +-- end, +-- provider = ' ●', +--} +-- +--local VimModeOthers = { +-- condition = function(self) +-- return self.mode ~= 'n' +-- end, +-- +-- utils.surround({ '', '' }, +-- function(self) +-- return mode_colors[self.mode].bg +-- end, +-- { +-- { +-- provider = function(self) +-- return '● ' .. mode_lable[self.mode] +-- end, +-- }, +-- hl = function(self) +-- return mode_colors[self.mode] +-- end +-- } +-- ), +--} +-- +--local ViMode = { +-- init = function(self) +-- self.mode = vim.fn.mode(1) +-- end, +-- +-- VimModeNormal, VimModeOthers, +-- +-- update = { 'ModeChanged' } +--} +--local colors = require'kanagawa.colors'.setup() -- wink + +--utils.surround({ "", "" }, function(self) return self:mode_color() end, {Ruler, hl = {fg = 'black'}} ), +-- we are surrounding the component and adjusting the foreground in one go! + +-- ViMode truemode +--local ViMode = { +-- -- get vim current mode, this information will be required by the provider +-- -- and the highlight functions, so we compute it only once per component +-- -- evaluation and store it as a component attribute +-- init = function(self) +-- self.mode = vim.fn.mode(1) -- :h mode() +-- +-- -- execute this only once, this is required if you want the ViMode +-- -- component to be updated on operator pending mode +-- if not self.once then +-- vim.api.nvim_create_autocmd("ModeChanged", { +-- pattern = "*:*o", +-- command = "redrawstatus", +-- }) +-- self.once = true +-- end +-- end, +-- -- Now we define some dictionaries to map the output of mode() to the +-- -- corresponding string and color. We can put these into `static` to compute +-- -- them at initialisation time. +-- static = { +-- mode_names = { -- change the strings if you like it vvvvverbose! +-- ["n"] = "NORMAL ", +-- ["no"] = "N·OPERATOR PENDING ", +-- ["v"] = "VISUAL ", +-- ["V"] = "V·LINE ", +-- [""] = "V·BLOCK ", +-- ["s"] = "SELECT ", +-- ["S"] = "S·LINE ", +-- [""] = "S·BLOCK ", +-- ["i"] = "INSERT ", +-- ["R"] = "REPLACE ", +-- ["Rv"] = "V·REPLACE ", +-- ["c"] = "COMMAND ", +-- ["cv"] = "VIM EX ", +-- ["ce"] = "EX ", +-- ["r"] = "PROMPT ", +-- ["rm"] = "MORE ", +-- ["r?"] = "CONFIRM ", +-- ["!"] = "SHELL ", +-- ["t"] = "TERMINAL ", +-- }, +-- mode_colors = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- --n = "blue" , +-- --i = "green", +-- --v = "cyan", +-- --V = "cyan", +-- --["\22"] = "cyan", +-- --c = "orange", +-- --s = "purple", +-- --S = "purple", +-- --["\19"] = "purple", +-- --R = "orange", +-- --r = "orange", +-- --["!"] = "red", +-- --t = "red", +-- }, +-- }, +-- -- We can now access the value of mode() that, by now, would have been +-- -- computed by `init()` and use it to index our strings dictionary. +-- -- note how `static` fields become just regular attributes once the +-- -- component is instantiated. +-- -- To be extra meticulous, we can also add some vim statusline syntax to +-- -- control the padding and make sure our string is always at least 2 +-- -- characters long. Plus a nice Icon. +-- provider = function(self) +-- return " %2(" .. self.mode_names[self.mode] .. "%)" +-- --return " %2("..self.mode_names[self.mode].."%)" +-- -- +-- -- +-- -- +-- end, +-- -- Same goes for the highlight. Now the foreground will change according to the current mode. +-- hl = function(self) +-- local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { fg = self.mode_colors[mode], bold = true, } +-- return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +-- end, +-- -- Re-evaluate the component only on ModeChanged event! +-- -- This is not required in any way, but it's there, and it's a small +-- -- performance improvement. +-- update = { +-- "ModeChanged", +-- }, --optional +--} +local ViMode = { + static = { + mode_names = { -- change the strings if you like it vvvvverbose! + ["n"] = "NORMAL ", + ["no"] = "N·OPERATOR PENDING ", + ["v"] = "VISUAL ", + ["V"] = "V·LINE ", + [""] = "V·BLOCK ", + ["s"] = "SELECT ", + ["S"] = "S·LINE ", + [""] = "S·BLOCK ", + ["i"] = "INSERT ", + ["R"] = "REPLACE ", + ["Rv"] = "V·REPLACE ", + ["c"] = "COMMAND ", + ["cv"] = "VIM EX ", + ["ce"] = "EX ", + ["r"] = "PROMPT ", + ["rm"] = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + ["t"] = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[vim.fn.mode(1)] .. "%)" + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color, fg = colors.bg, bold = true } + end, +} + +local ViModeColor = { + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + }, +} + +-- LSP + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = {'LspAttach', 'LspDetach'}, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +-- on_click = { +-- callback = function() +-- vim.defer_fn(function() +-- vim.cmd("LspInfo") +-- end, 100) +-- end, +-- name = "heirline_LSP", +-- }, +--} +-- +---- lsp status +---- I personally use it only to display progress messages! +---- See lsp-status/README.md for configuration options. +-- +---- Note: check "j-hui/fidget.nvim" for a nice statusline-free alternative. +--local LSPMessages = { +-- provider = require("lsp-status").status, +-- hl = { fg = "gray" }, +--} + +-- Nvim Navic +--local Navic = { +-- condition = require("nvim-navic").is_available, +-- provider = require("nvim-navic").get_location, +--} +--local Navic = utils.make_flexible_component(3, Navic, { provider = "" }) + +-- Full nerd (with icon colors)! +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = "bright_fg" }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = "gray" }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + --{ + -- provider = "]", + --}, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileName and Friends + +--local Align = { provider = "%=" } +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local fill = { provider = "%=", hl = { bg = colors.nobg } } +--local LeftSep = { provider = "" hl = { fg = colors.bg } } +--local RightSep = { provider = "" hl = { fg = colors.bg }} + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} +-- We can now define some children separately and add them later +-- + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + --return { fg = self.icon_color } + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "[No Name]" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + --hl = { fg = utils.get_highlight("Directory").fg, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return "" + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + -- use `force` because we need to override the child's hl foreground + --return { fg = "cyan", bold = true, force = true } + return { fg = "blue", bold = true, force = true, bg = colors.bg } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + -- return string.upper(vim.bo.filetype) + --end, + ----hl = { fg = utils.get_highlight("Type").fg, bold = true }, + --hl = { fg = utils.get_highlight("Type").fg, bold = true, bg = colors.bg }, + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +--local FileEncoding = { +-- provider = function() +-- local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' +-- return enc ~= "utf-8" and enc:upper() +-- end, +--} +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:upper() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + return fmt ~= "unix" and fmt:upper() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = "SPELL ", + hl = { bold = true, fg = "orange" }, +} + +-- Cursor position: Ruler and ScrollBar +-- We're getting minimalists here! +local Ruler = { + -- We're getting minimalists here! + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + provider = "%3(%2l%):%c %P", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} +--local ScrollBar = { +-- static = { +-- --sbar = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }, +-- sbar = { "🭶", "🭷", "🭸", "🭹", "🭺", "🭻" }, +-- }, +-- provider = function(self) +-- local curr_line = vim.api.nvim_win_get_cursor(0)[1] +-- local lines = vim.api.nvim_buf_line_count(0) +-- local i = math.floor((curr_line - 1) / lines * #self.sbar) + 1 +-- return string.rep(self.sbar[i], 2) +-- end, +-- --hl = { fg = "blue", bg = "bright_bg" }, +-- hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +--} +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +local Position = { + Space, + { provider = "%l:%c" }, + hl = { bg = colors.bg }, +} + +local Percentage = { + Space, + { provider = "%p%%" }, + hl = { bg = colors.bg }, +} +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + --hl = { fg = "blue", bold = true }, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Terminal Name +-- Special handling of the built-in terminal bufname. See conditional statuslines below to see an example of dedicated statusline for terminals! + +local TerminalName = { + -- we could add a condition to check that buftype == 'terminal' + -- or we could do that later (see #conditional-statuslines below) + provider = function() + local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") + return " " .. tname + end, + --hl = { fg = "blue", bold = true }, + hl = { bold = true, bg = colors.bg }, +} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +--FileNameBlock = utils.insert( +-- FileNameBlock, +--FileEncoding, +--Space, +--FileIcon, +--FileType, +--FileLastModified, +--FileSize, +--FileFormat, +--FileNameModifer, +-- unpack(FileFlags), +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + FileEncoding, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) +--FileNameBlock = utils.insert( +-- FileNameBlock, +-- FileIcon, +-- utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier +-- unpack(FileFlags), -- A small optimisation, since their parent does nothing +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) + +-- Statusline + +local Surrr = { + utils.surround({ "", "" }, "red", { + utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), + { provider = "Normal" }, + }), +} +--ViMode = utils.surround({ "", "" }, "bright_bg", { ViMode, Snippets }) +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +--ViMode = utils.surround({ "◥", "" }, function(self) return self:mode_color() end, { +-- utils.surround({ "█", "" }, function(self) return self:mode_color() end, utils.surround({ "", "" }, function(self) return self:mode_color() end, { {provider = "normal" }, ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } )), +-- { provider = "heyya" }, +-- }) + +--utils.surround({ "█", "█" }, function(self) return self:mode_color() end, { FileNameBlock, hl = { fg = colors.bg, force = true } } ), +local DefaultStatusline = { + ViMode, + Space, + FileNameBlock, + Space, + Git, + Space, + Diagnostics, + Align, + Navic, + DAPMessages, + Align, + Space, + FileInfoBlock, + Space, + WordCount, + Ruler, + Space, + --Position, + --Percentage, + --ScrollBar, + --Space, + --LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar +} + +--local InactiveStatusline = { +-- condition = conditions.is_not_active, +-- FileType, +-- Space, +-- FileName, +-- Align, +--} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + FileType, + Space, + Align, + --FileType, Space, HelpFileName, Align +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + hl = { bg = "dark_red" }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + { condition = conditions.is_active, ViMode, Space }, + FileType, + Space, + TerminalName, + Align, +} + +--local StatusLines = { +-- +-- hl = function() +-- if conditions.is_active() then +-- return "StatusLine" +-- else +-- return "StatusLineNC" +-- end +-- end, +-- +-- -- the first statusline with no condition, or which condition returns true is used. +-- -- think of it as a switch case with breaks to stop fallthrough. +-- fallthrough = false, +-- +-- SpecialStatusline, +-- TerminalStatusline, +-- --InactiveStatusline, +-- DefaultStatusline, +--} +local StatusLines = { + + hl = function() + if conditions.is_active() then + return "StatusLine" + else + return "StatusLineNC" + end + end, + + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + --InactiveStatusline, + DefaultStatusline, +} +--hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +-- hl = { bg = colors.bg }, +--require("heirline").setup(StatusLines) +-- we're done. + +--local FelineStyle = { +-- +-- -- stop at child where buftype/filetype/bufname matches +-- fallthrough = false, +-- +-- { -- Identify the buftype/filetype/bufname first +-- condtion = function() +-- return conditions.buffer_matches({...}) +-- end, +-- +-- -- Evaluate only the "active" or "inactive" child +-- fallthrough = false, +-- +-- { -- If it's the current window, display some components +-- condition = conditions.is_active +-- {...} -- +-- }, +-- { -- Otherwise, display some other components +-- {...} -- +-- } +-- }, +-- { -- this block can be exactly as the one above for a different kind of +-- -- buffer +-- ... +-- } +--} + +-- WinBar + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) +local active_middle_segment = { --{{{ + -- provider = "%999X %X", + + --provider = function(self) + -- --return " %999X %999X " + -- return " %2("..self.mode_names[self.mode].."%)" + -- -- + -- -- + -- -- + --end, + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + provider = "%f", + hl = function(self) + local color = self:mode_color() -- here! + return { fg = color } + end, + -- self.filename will be defined later, just keep looking at the example! + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, "dark_red", { + FileType, + Space, + TerminalName, + }), + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + --utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), + --utils.surround({ "", "" }, function(self) return self:mode_color() end, { FileNameBlock, hl = { fg = colors.bg, force = true } } ), + }, + -- A winbar for regular files + --utils.surround({ "", "" }, "bright_bg", FileNameBlock), + --█🙼🙽🙼█⮘██⮚ + --utils.surround({ "", "" }, function(self) return self:mode_color() end, { FileNameBlock, hl = function(self) + -- local color = self:mode_color() -- here! + -- return { bg = color, bold = true, force = true } + --end, + --}), + --utils.surround({ "", "" }, function(self) return self:mode_color() end, FileNameBlock), +} + +--utils.surround({ "", "" }, function(self) return self:mode_color() end, { active_middle_segment, hl = { fg = colors.bg, force = true } }) + +local WinBars = { + fill, + active_middle_segment, + fill, +} +-- --utils.surround({ " ", " " }, colors.nobg, { fill, active_middle_segment, fill }) +-- --static = { +-- -- mode_colors_map = { +-- -- n = colors.blue, +-- -- i = colors.green, +-- -- v = colors.purple, +-- -- V = colors.purple, +-- -- [""] = colors.purple, +-- -- c = colors.red, +-- -- s = colors.purple, +-- -- S = colors.purple, +-- -- [""] = colors.purple, +-- -- R = colors.orange, +-- -- r = colors.orange, +-- -- ["!"] = colors.red, +-- -- t = colors.red, +-- -- }, +-- -- mode_color = function(self) +-- -- local mode = conditions.is_active() and vim.fn.mode() or "n" +-- -- return self.mode_colors_map[mode] +-- -- end, +-- --}, +-- --utils.surround({ " ", " " }, colors.nobg, { active_middle_segment, hl = function(self) +-- -- local color = self:mode_color() -- here! +-- -- return { bg = color, bold = true, force = true } +-- --end, +-- --}) +--} +on_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +-- Use it anywhere! +--local WinBarFileName = utils.surround({ "", "" }, "bright_bg", { +-- hl = function() +-- if not conditions.is_active() then +-- return { fg = "gray", force = true } +-- end +-- end, +-- FileNameBlock, +-- Space, +-- CloseButton, +--}) + +--local WinBars = { +-- -- init = utils.pick_child_on_condition, +-- fallthrough = false, +-- { +-- condition = function() +-- return conditions.buffer_matches({ +-- buftype = { "nofile", "prompt", "help", "quickfix" }, +-- filetype = { "^git.*", "fugitive" }, +-- }) +-- end, +-- init = function() +-- vim.opt_local.winbar = nil +-- end, +-- }, +-- { +-- condition = function() +-- return conditions.buffer_matches({ buftype = { "terminal" } }) +-- end, +-- utils.surround({ "", "" }, "dark_red", { +-- FileType, +-- Space, +-- TerminalName, +-- CloseButton, +-- }), +-- }, +-- utils.surround({ "", "" }, "bright_bg", { +-- hl = function() +-- if conditions.is_not_active() then +-- return { fg = "gray", force = true } +-- end +-- end, +-- +-- FileNameBlock, +-- CloseButton, +-- }), +--} + +-- TabLine +--local TabLine ={ +-- hl = { bg = colors.bg }, +--} +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. ". " + end, + --hl = "Comment", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "[No Name]" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +-- this looks exactly like the FileFlags component that we saw in +-- #crash-course-part-ii-filename-and-friends, but we are indexing the bufnr explicitly +-- also, we are adding a nice icon for terminal buffers. +--local TablineFileFlags = { +-- { +-- condition = function(self) +-- return vim.api.nvim_buf_get_option(self.bufnr, "modified") +-- end, +-- provider = "[+]", +-- --hl = { fg = colors.green }, +-- hl = { fg = colors.green, bold = true, bg = colors.bg }, +-- }, +-- { +-- condition = function(self) +-- return not vim.api.nvim_buf_get_option(self.bufnr, "modifiable") +-- or vim.api.nvim_buf_get_option(self.bufnr, "readonly") +-- end, +-- provider = function(self) +-- if vim.api.nvim_buf_get_option(self.bufnr, "buftype") == "terminal" then +-- return " " +-- else +-- return "" +-- end +-- end, +-- hl = { fg = "orange", bg = colors.bg }, +-- }, +--} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+]" + end + end, + hl = { fg = colors.green }, + }, + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return "" + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLine" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + --FileIcon, -- turns out the version defined in #crash-course-part-ii-filename-and-friends can be reutilized as is here! + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = "red" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +--local TablineBufferBlock = utils.surround({ "", "", hl = { bg =colors.bg } }, function(self) +-- if self.is_active then +-- return utils.get_highlight("TabLineSel").fg, utils.get_highlight("TabLineSel").bg +-- else +-- return utils.get_highlight("TabLine").fg, utils.get_highlight("TabLine").bg +-- end +----end, { TabLine, TablineFileNameBlock, TablineCloseButton }) +--end, { TablineFileNameBlock, TablineCloseButton }) + +--local TablineBufferBlock = utils.surround({ "█", "█" }, "bg", { +-- hl = function() +-- if not conditions.is_active() then +-- return { fg = "gray", force = true, bg = colors.bg } +-- end +-- end, +-- TablineFileNameBlock, +-- TablineCloseButton, +--}) +--local TablineBufferBlock = utils.surround({ "█", "█" }, +-- { hl = function(self) +-- local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { fg = self.mode_colors[mode], bold = true, } +-- return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +-- end, }, +--{ TablineFileNameBlock, TablineCloseButton, { hl = ViMode }, }) + +--local TablineBufferBlock = { +-- init = function(self) +-- +-- self.mode = vim.fn.mode(1) -- :h mode() +-- +-- vim.api.nvim_create_autocmd("ModeChanged", { +-- pattern = "*:*o", +-- command = "redrawstatus", +-- }) +-- self.once = true +-- end, +-- static = { +-- mode_colors = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- }, +-- }, +-- hl = function(self) +-- if self.is_active then +-- local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { fg = self.mode_colors[mode], bold = true, } +-- return { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +-- else +-- return utils.get_highlight("TabLine").bg +-- end +-- end, +-- update = { +-- "ModeChanged", +-- }, --optional +-- { TablineFileNameBlock, TablineCloseButton } +--} + +--local TabLineSel = { +-- hl = { bg = self.mode_colors[mode], fg = colors.bg, bold = true } +--} +--local ViMode2 = { +-- init = function(self) +-- self.mode = vim.fn.mode() +-- end, +-- static = { +-- mode_colors = { +-- n = "red", +-- i = "green", +-- v = "blue", +-- c = "orange" +-- +-- } +-- }, +-- provider = function(self) +-- return string.upper(self.mode) +-- end, +-- hl = function(self) +-- return { fg = self.mode_colors[self.mode], bold = true, } +-- end +--} +--local surrr = { +-- utils.surround({ "", "" }, "red", { +-- utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), +-- { provider = "Normal" }, +-- }), +--} +--local statusline = ViMode + +--local TablineBufferBlock = utils.surround({ "", "" }, function(self) +-- if self.is_active then +-- --self.mode = vim.fn.mode(1) -- :h mode() +-- +-- --return utils.get_highlight(vim.api.nvim_get_mode().mode).bg +-- return utils.get_highlight("TabLineSel").bg +-- --return utils.get_highlight("Normal").bg +-- --local mode = self.mode:sub(1, 1) -- get only the first mode character +-- --return { bg = TabLineSel, fg = colors.bg, bold = true } +-- else +-- return utils.get_highlight("TabLine").bg +-- end +--end, { TablineFileNameBlock, TablineCloseButton }) + +local TablineBufferBlock = utils.surround({ "█", "▎" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLine").bg + end +end, { TablineFileNameBlock, TablineCloseButton }) +--█ +--local TablineBufferBlock = { +-- init = function(self) +-- self.mode = vim.fn.mode() +-- end, +-- static = { +-- mode_colors = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- }, +-- }, +-- hl = function(self) +-- if conditions.is_active() then +-- return { bg = self.mode_colors[self.mode], fg = colors.bg, bold = true } +-- else +-- return utils.get_highlight("Tabline").bg +-- end +-- end, +-- update = { +-- "ModeChanged", +-- }, --optional +-- { TablineFileNameBlock, TablineCloseButton }, +--} + +--local TablineBufferBlock = { +-- static = { +-- mode_colors_map = { +-- n = colors.blue, +-- i = colors.green, +-- v = colors.purple, +-- V = colors.purple, +-- [""] = colors.purple, +-- c = colors.red, +-- s = colors.purple, +-- S = colors.purple, +-- [""] = colors.purple, +-- R = colors.orange, +-- r = colors.orange, +-- ["!"] = colors.red, +-- t = colors.red, +-- }, +-- mode_color = function(self) +-- local mode = conditions.is_active() and vim.fn.mode() or "n" +-- return self.mode_colors_map[mode] +-- end, +-- }, +-- { -- A special winbar for terminals +-- condition = function() +-- return conditions.buffer_matches({ buftype = { "terminal" } }) +-- end, +-- utils.surround({ "", "" }, "dark_red", { +-- FileType, +-- Space, +-- TerminalName, +-- }), +-- }, +-- { -- An inactive winbar for regular files +-- condition = function() +-- return conditions.is_not_active() +-- end, +-- utils.surround({ "█", "█" }, function() return utils.get_highlight("TabLine").bg end, { TablineFileNameBlock, TablineCloseButton } ) +-- }, +-- { +-- condition = function() +-- return conditions.is_active() +-- end, +-- utils.surround({ "█", "█" }, function(self) return self:mode_color() end, { TablineFileNameBlock, TablineCloseButton, hl = { fg = colors.bg, force = true } } ) +-- }, +--function() +--if self.is_active then +--utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), +--utils.surround({ "", "" }, function(self) return self:mode_color() end, { FileNameBlock, hl = { fg = colors.bg, force = true } } ), +--utils.surround({ "█", "█" }, function() return utils.get_highlight("TabLine").bg end, { TablineFileNameBlock, TablineCloseButton, hl = { fg = colors.bg, force = true } } ), +--} +--ViMode = utils.surround({ "", "" }, function(self) +-- if self.is_active then +-- return self:mode_color() +-- else +-- return utils.get_highlight("TabLine").bg +-- end +-- end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } ) +-- +----} +--local TablineBufferBlock = { +-- ViMode, +-- TablineFileName, +-- TablineCloseButton, +--} +-- A winbar for regular files +--utils.surround({ "", "" }, "bright_bg", FileNameBlock), +--utils.surround({ "", "" }, function(self) return self:mode_color() end, FileNameBlock), +local BufferLine = utils.make_buflist( + TablineBufferBlock, + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + --{ provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + --{ provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +-- if self.is_active then +-- return utils.get_highlight("TabLineSel").bg +-- else +-- return utils.get_highlight("TabLine").bg +-- end +--end, { TablineFileNameBlock, TablineCloseButton, } ) +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local TabLine = { + --hl = { bg = colors.bg }, + fallthrough = false, + TabLineOffset, + BufferLine, + TabPages, +} + +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) +--local StatusLines = { +-- +-- hl = function() +-- if conditions.is_active() then +-- return "StatusLine" +-- else +-- return "StatusLineNC" +-- end +-- end, +-- +-- -- the first statusline with no condition, or which condition returns true is used. +-- -- think of it as a switch case with breaks to stop fallthrough. +-- fallthrough = false, +-- +-- SpecialStatusline, +-- TerminalStatusline, +-- --InactiveStatusline, +-- DefaultStatusline, +--} +-- +-- --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +-- hl = { bg = colors.bg }, +--local TabLine ={ +-- hl = { bg = colors.bg }, +--} +-- Window Close button: Let the callback know from which window it was clicked from! +-- The following is the recommended way of achieving that: +require("heirline").setup(StatusLines, WinBars, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +vim.api.nvim_create_augroup("Heirline", { clear = true }) +vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + local colors = setup_colors() + utils.on_colorscheme(colors) + end, + group = "Heirline", +}) + +local function get_bufs() + return vim.tbl_filter(function(bufnr) + return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted + end, vim.api.nvim_list_bufs()) +end + +local function goto_buf(index) + local bufs = get_bufs() + if index > #bufs then + index = #bufs + end + vim.api.nvim_win_set_buf(0, bufs[index]) +end + +local function addKey(key, index) + vim.keymap.set("", "<A-" .. key .. ">", function() + goto_buf(index) + end, { noremap = true, silent = true }) +end + +for i = 1, 9 do + addKey(i, i) +end +addKey("0", 10) +-- Theming +--local function setup_colors() +-- return { +-- bright_bg = utils.get_highlight("Folded").bg, +-- bright_fg = utils.get_highlight("Folded").fg, +-- red = utils.get_highlight("DiagnosticError").fg, +-- dark_red = utils.get_highlight("DiffDelete").bg, +-- green = utils.get_highlight("String").fg, +-- blue = utils.get_highlight("Function").fg, +-- gray = utils.get_highlight("NonText").fg, +-- orange = utils.get_highlight("Constant").fg, +-- purple = utils.get_highlight("Statement").fg, +-- cyan = utils.get_highlight("Special").fg, +-- diag_warn = utils.get_highlight("DiagnosticWarn").fg, +-- diag_error = utils.get_highlight("DiagnosticError").fg, +-- diag_hint = utils.get_highlight("DiagnosticHint").fg, +-- diag_info = utils.get_highlight("DiagnosticInfo").fg, +-- git_del = utils.get_highlight("diffDeleted").fg, +-- git_add = utils.get_highlight("diffAdded").fg, +-- git_change = utils.get_highlight("diffChanged").fg, +-- } +--end +--require('heirline').load_colors(setup_colors()) +-- +--vim.api.nvim_create_augroup("Heirline", { clear = true }) +--vim.api.nvim_create_autocmd("ColorScheme", { +-- callback = function() +-- local colors = setup_colors() +-- utils.on_colorscheme(colors) +-- end, +-- group = "Heirline", +--}) diff --git a/lua/plugins/heirline.lua-202210111610.backup b/lua/plugins/heirline.lua-202210111610.backup new file mode 100644 index 0000000..e1a54e3 --- /dev/null +++ b/lua/plugins/heirline.lua-202210111610.backup @@ -0,0 +1,1452 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +local colors = { + --bg = "#23232e", + bg = nil, + nobg = nil, + bright_fg = "#ffffff", + bright_bg = "#000000", + white = "#f8f8f2", + --darkgray = "#1c1c29", + --darkgray = "#2d2b3a", + --darkgray = "#181818", + darkgray = "#23232e", + --darkgray = "#404040", + --gray = "#333842", + --gray = "#393547", + --gray = "#333842", + --lightgray = "#888888", + gray = "#2d2b3a", + lightgray = "#d6d3ea", + pink = "#f92672", + green = "#50fa7b", + blue = "#39BAE6", + yellow = "#f1fa8c", + orange = "#ffb86c", + ---purple = "#bd93f9", + ---purple = "#be2ed6", + purple = "#BF40BF", + --purple = "#5D3FD3", + --purple = "#DA70D6", + violet = "#7F00FF", + red = "#ff5555", + cyan = "#66d9eC", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +local ViMode = { + init = function(self) + self.mode = vim.fn.mode(1) + if not self.once then + vim.cmd("au ModeChanged *:*o redrawstatus") + end + self.once = true + end, + static = { + mode_names = { + n = "NORMAL ", + no = "N·OPERATOR PENDING ", + nov = "N?", + noV = "N?", + ["no\22"] = "N? ", + niI = "Ni", + niR = "Nr", + niV = "Nv", + nt = "Nt", + v = "VISUAL ", + vs = "Vs", + V = "V·LINE ", + ["\22"] = "V·BLOCK ", + ["\22s"] = "V·BLOCK ", + s = "SELECT ", + S = "S·LINE ", + ["\19"] = "S·BLOCK ", + i = "INSERT ", + ix = "insert x ", + ic = "insert c ", + R = "REPLACE ", + Rc = "Rc", + Rx = "Rx", + Rv = "V·REPLACE ", + Rvc = "Rv", + Rvx = "Rv", + c = "COMMAND ", + cv = "VIM EX ", + --ce = "EX ", + r = "PROMPT ", + rm = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + t = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[self.mode] .. "%)" + end, + hl = function(self) + local color = self:mode_color() + return { fg = color, bold = true } + end, + update = { + "ModeChanged", + }, +} + +-- +-- +-- +-- +--凜兩 +-- LSP + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = {'LspAttach', 'LspDetach'}, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +-- on_click = { +-- callback = function() +-- vim.defer_fn(function() +-- vim.cmd("LspInfo") +-- end, 100) +-- end, +-- name = "heirline_LSP", +-- }, +--} + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = { "LspAttach", "LspDetach" }, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +--} + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- +-- provider = function() +-- local names = vim.tbl_values(vim.tbl_map(function(cl) +-- return cl.name +-- end, vim.lsp.buf_get_clients(0))) +-- +-- return "LSP " .. table.concat(names, " ") .. "" +-- end, +-- hl = { fg = colors.bg }, +--} +local LSPActive = { + condition = conditions.lsp_attached, + update = { "LspAttach", "LspDetach" }, + + -- You can keep it simple, + -- provider = " [LSP]", + + -- Or complicate things a bit and get the servers names + provider = function() + local buf_clients = vim.lsp.buf_get_clients() + local buf_ft = vim.bo.filetype + local buf_client_names = {} + + -- add client + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) + end + end + return "⚙️ " .. table.concat(buf_client_names, "") + --return table.concat(buf_client_names, " ") + --return "⚙️ " .. table.concat(buf_client_names, ", ") .. " " + --return " " .. table.concat(names, " ") .. " " + end, + hl = { fg = colors.lightgray, bold = false }, +} +--local LSPActive = { +-- function(msg) +-- msg = msg or "LS Inactive" +-- local buf_clients = vim.lsp.buf_get_clients() +-- if next(buf_clients) == nil then +-- if type(msg) == "boolean" or #msg == 0 then +-- return "LS Inactive" +-- end +-- return msg +-- end +-- +-- local buf_ft = vim.bo.filetype +-- local buf_client_names = {} +-- +-- -- add client +-- for _, client in pairs(buf_clients) do +-- if client.name ~= "null-ls" then +-- table.insert(buf_client_names, client.name) +-- end +-- end +-- +-- -- add formatter +-- local formatters = require("user.lsp.null-ls.formatters") +-- local supported_formatters = formatters.list_registered(buf_ft) +-- vim.list_extend(buf_client_names, supported_formatters) +-- +-- -- add linter +-- local linters = require("user.lsp.null-ls.linters") +-- local supported_linters = linters.list_registered(buf_ft) +-- vim.list_extend(buf_client_names, supported_linters) +-- +-- return table.concat(buf_client_names, " ") +-- -- return "[" .. table.concat(buf_client_names, ", ") .. "]" +-- end, +-- hl = { fg = colors.bg }, +--} +-- lsp status +-- I personally use it only to display progress messages! +-- See lsp-status/README.md for configuration options. + +-- Note: check "j-hui/fidget.nvim" for a nice statusline-free alternative. +local LSPMessages = { + provider = require("lsp-status").status, + hl = { fg = "gray" }, +} + +-- Nvim Navic +--local Navic = { +-- condition = require("nvim-navic").is_available, +-- provider = require("nvim-navic").get_location, +--} +--local Navic = utils.make_flexible_component(3, Navic, { provider = "" }) + +-- Full nerd (with icon colors)! +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = "bright_fg" }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = "gray" }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + --{ + -- provider = "]", + --}, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileName and Friends + +--local Align = { provider = "%=" } +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local Tab = { provider = " " } +local Fill = { provider = "%=", hl = { bg = colors.nobg } } +local LeftSep = { provider = "", hl = { fg = colors.bg } } +local RightSep = { provider = "", hl = { fg = colors.bg } } + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} +-- We can now define some children separately and add them later +-- + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "No Name" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + --±[+] + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return " " + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + return { fg = colors.green, bold = false, force = true } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +--local FileEncoding = { +-- provider = function() +-- local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' +-- return enc ~= "utf-8" and enc:upper() +-- end, +-- hl = { bg = colors.bg }, +--} +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:lower() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg, bold = false }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + return fmt ~= "unix" and fmt:upper() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = "SPELL ", + hl = { bold = true, fg = "orange" }, +} + +-- Cursor position: Ruler and ScrollBar +-- We're getting minimalists here! +local Ruler = { + -- We're getting minimalists here! + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + --provider = "%P %(%l/%L%):%c ", + --provider = "%3(%2l%):%c %P ", + --provider = "%7(%l/%3L%):%2c%P ", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + --provider = "%9( %P %2l/%L :%2c %)", + --provider = "%9(%2l%2( : %c%)/%L %P %)", + --provider = "%7(%l:%c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) %P ", + provider = "%3(%l:%1.5c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) ", + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +local Total = { + provider = "%L", + hl = { fg = utils.get_highlight("Statusline").fg, bold = false }, +} + +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +local Position = { + Space, + { provider = "%l:%c" }, + hl = { bg = colors.bg }, +} + +local Percentage = { + Space, + { provider = "%P" }, + hl = { bg = colors.bg }, +} +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Terminal Name +-- Special handling of the built-in terminal bufname. See conditional statuslines below to see an example of dedicated statusline for terminals! + +--local TerminalName = { +-- -- we could add a condition to check that buftype == 'terminal' +-- -- or we could do that later (see #conditional-statuslines below) +-- provider = function() +-- local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") +-- return " " .. tname +-- end, +-- hl = { bold = true, bg = colors.bg }, +--} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +--FileNameBlock = utils.insert( +-- FileNameBlock, +--FileEncoding, +--Space, +--FileIcon, +--FileType, +--FileLastModified, +--FileSize, +--FileFormat, +--FileNameModifer, +-- unpack(FileFlags), +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) +--FileNameBlock = utils.insert( +-- FileNameBlock, +-- FileIcon, +-- utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier +-- unpack(FileFlags), -- A small optimisation, since their parent does nothing +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) + +local Surrr = { + utils.surround({ "", "" }, "red", { + utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), + { provider = "Normal" }, + }), +} +--ViMode = utils.surround({ "", "" }, "bright_bg", { ViMode, Snippets }) +--ViMode = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +--ViMode = utils.surround({ "◥", "" }, function(self) return self:mode_color() end, { +-- utils.surround({ "█", "" }, function(self) return self:mode_color() end, utils.surround({ "", "" }, function(self) return self:mode_color() end, { {provider = "normal" }, ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } )), +-- { provider = "heyya" }, +-- }) +-- Statusline +--BackgroundStatusline = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { BackgroundStatusline, hl = { bg = utils.get_highlight("statusline").bg, force = true } }) +-- +local Surrr = { + utils.surround({ "", "" }, "gray", { + FileInfoBlock, + hl = { bg = colors.gray }, + utils.surround({ "", "" }, "gray", { + Percentage, + utils.surround({ "", "" }, function(self) + return self:mode_color() + end, { Space, Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }), + }), + }), +} + +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +LeftSpace = utils.surround({ "", " " }, function(self) + return self:mode_color() +end, { LeftSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +-- +RightSpace = utils.surround( + { "", "" }, + colors.gray, + { RightSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } } +) + +RightSpace2 = utils.surround( + { "█", "" }, + colors.darkgray, + { RightSpace2, hl = { fg = colors.darkgray, force = true } } +) + +RightSpace3 = utils.surround( + { "█", "" }, + utils.get_highlight("statusline").bg, + { RightSpace3, hl = { fg = colors.darkgray, force = true } } +) +--RightSpace = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +---- +-- +--Percentage = utils.surround({ "", " " }, "red", { Percentage, hl = { bg = colors.red, force = true } }) +-- + +LSPActive = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { Space, LSPActive, hl = { bg = colors.darkgray, force = true } }) + +FileInfoBlock = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { FileInfoBlock, Space, hl = { bg = colors.gray, force = true } }) + +Ruler = utils.surround({ "", "" }, colors.gray, { Space, Ruler, hl = { fg = colors.gray, force = true } }) + +local align = { provider = "%=" } +local left = { + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileNameBlock, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Git, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local middle = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { DAPMessages, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local right = { + { Diagnostics, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { + RightSpace3, + hl = { bg = colors.darkgray, force = true }, + }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { LSPActive, hl = { bg = colors.darkgray, force = true } }, + --{ FileEncoding, hl = { bg = colors.orange, force = true } }, + { RightSpace2, hl = { bg = colors.gray, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileInfoBlock, hl = { bg = colors.gray, force = true } }, + --{ Space, hl = { bg = colors.red, force = true } }, + --{ FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ WordCount, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = colors.gray, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, +} + +local sections = { left, middle, right } +local DefaultStatusline = { sections } + +--local NewSpace = { provider = "", hl = { bg = utils.get_highlight("statusline").bg } } +--local statusline = { +--Space, +--Space, +--Git, +--Space, +--Diagnostics, +--Align, +--Navic, +--DAPMessages, +--Align, +--Space, +--FileInfoBlock, +--Space, +--WordCount, +--Ruler, +--LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar +--} + +local InactiveStatusline = { + condition = conditions.is_not_active, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileName, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + --FileType, + --Space, + --Align, + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + + --FileType, Space, HelpFileName, Align +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + --hl = { bg = colors.red }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + --{ condition = conditions.is_active, ViMode, Space }, + + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + --FileType, + --Space, + --TerminalName, + --Align, +} + +local StatusLine = { + + --hl = function() + -- if conditions.is_active() then + -- return "StatusLine" + -- else + -- return "StatusLineNC" + -- end + --end, + static = { + mode_colors = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + ["\22"] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + ["\19"] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + --mode_colors_map = { + -- n = colors.blue, + -- i = colors.green, + -- v = colors.purple, + -- V = colors.violet, + -- [""] = colors.red, + -- c = colors.yellow, + -- s = colors.orange, + -- S = colors.orange, + -- [""] = colors.purple, + -- R = colors.orange, + -- r = colors.orange, + -- ["!"] = colors.red, + -- t = colors.red, + }, + --mode_color = function(self) + -- local mode = conditions.is_active() and vim.fn.mode() or "n" + -- return self.mode_colors_map[mode] + --end, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors[mode] + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color } + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + InactiveStatusline, + DefaultStatusline, +} + +-- WinBar + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +on_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +local active_middle_segment = { --{{{ + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + provider = "%f", + hl = function(self) + local color = self:mode_color() -- here! + return { fg = color } + end, + -- self.filename will be defined later, just keep looking at the example! + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + FileType, + Space, + --TerminalName, + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, colors.nobg, { hl = { fg = "gray", force = true }, FileNameBlock }), + }, +} + +--local WinBar = { +-- Fill, +-- active_middle_segment, +-- Fill, +--} +local WinBar = { + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + FileType, + Space, + --TerminalName, + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, colors.nobg, { hl = { fg = "gray", force = true }, FileNameBlock }), + }, + -- A winbar for regular files + utils.surround({ "", "" }, colors.nobg, FileNameBlock), +} + +-- TabLine +-- + +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. "." + end, + --hl = "Comment", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "No Name" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+] " + end + end, + hl = { fg = colors.green }, + }, + --+ + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return " " + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLineFill" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + --FileIcon, -- turns out the version defined in #crash-course-part-ii-filename-and-friends can be reutilized as is here! + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = "red" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLineFill").bg + end +end, { Tab, TablineFileNameBlock, TablineCloseButton }) + +local BufferLine = utils.make_buflist( + TablineBufferBlock, + --{ provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + --{ provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local TabLine = { + --hl = { bg = colors.bg }, + fallthrough = false, + TabLineOffset, + BufferLine, + TabPages, +} + +require("heirline").setup(StatusLine, WinBar, TabLine) +--require("heirline").setup(StatusLine, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +--local function get_bufs() +-- return vim.tbl_filter(function(bufnr) +-- return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted +-- end, vim.api.nvim_list_bufs()) +--end +-- +--local function goto_buf(index) +-- local bufs = get_bufs() +-- if index > #bufs then +-- index = #bufs +-- end +-- vim.api.nvim_win_set_buf(0, bufs[index]) +--end +-- +--local function addKey(key, index) +-- vim.keymap.set("", "<A-" .. key .. ">", function() +-- goto_buf(index) +-- end, { noremap = true, silent = true }) +--end +-- +--for i = 1, 9 do +-- addKey(i, i) +--end +--addKey("0", 10) diff --git a/lua/plugins/heirlinenew.lua b/lua/plugins/heirlinenew.lua new file mode 100644 index 0000000..64a33b2 --- /dev/null +++ b/lua/plugins/heirlinenew.lua @@ -0,0 +1,1342 @@ +local conditions = require("heirline.conditions") +local utils = require("heirline.utils") + +local colors = { + --bg = "#23232e", + bg = nil, + nobg = nil, + bright_fg = "#ffffff", + bright_bg = "#000000", + white = "#f8f8f2", + gray = "#23232e", + pink = "#f92672", + green = "#50fa7b", + blue = "#39BAE6", + yellow = "#f1fa8c", + orange = "#ffb86c", + purple = "#bd93f9", + red = "#ff5555", + cyan = "#66d9eC", + diag = { + warn = utils.get_highlight("DiagnosticSignWarn").fg, + error = utils.get_highlight("DiagnosticSignError").fg, + hint = utils.get_highlight("DiagnosticSignHint").fg, + info = utils.get_highlight("DiagnosticSignInfo").fg, + }, + git = { + del = "#e95678", + add = "#a6e22e", + change = "#ae81ff", + }, +} + +require("heirline").load_colors(colors) + +--local function setup_colors() +-- return { +-- bright_bg = utils.get_highlight("Folded").bg, +-- bright_fg = utils.get_highlight("Folded").fg, +-- red = utils.get_highlight("DiagnosticError").fg, +-- dark_red = utils.get_highlight("DiffDelete").bg, +-- green = utils.get_highlight("String").fg, +-- blue = utils.get_highlight("Function").fg, +-- gray = utils.get_highlight("NonText").fg, +-- orange = utils.get_highlight("Constant").fg, +-- purple = utils.get_highlight("Statement").fg, +-- cyan = utils.get_highlight("Special").fg, +-- diag_warn = utils.get_highlight("DiagnosticWarn").fg, +-- diag_error = utils.get_highlight("DiagnosticError").fg, +-- diag_hint = utils.get_highlight("DiagnosticHint").fg, +-- diag_info = utils.get_highlight("DiagnosticInfo").fg, +-- git_del = utils.get_highlight("diffDeleted").fg, +-- git_add = utils.get_highlight("diffAdded").fg, +-- git_change = utils.get_highlight("diffChanged").fg, +-- } +--end +--require('heirline').load_colors(setup_colors()) +-- +--vim.api.nvim_create_augroup("Heirline", { clear = true }) +--vim.api.nvim_create_autocmd("ColorScheme", { +-- callback = function() +-- local colors = setup_colors() +-- utils.on_colorscheme(colors) +-- end, +-- group = "Heirline", +--}) + +local ViMode = { + static = { + mode_names = { -- change the strings if you like it vvvvverbose! + ["n"] = "NORMAL ", + ["no"] = "N·OPERATOR PENDING ", + ["v"] = "VISUAL ", + ["V"] = "V·LINE ", + [""] = "V·BLOCK ", + ["s"] = "SELECT ", + ["S"] = "S·LINE ", + [""] = "S·BLOCK ", + ["i"] = "INSERT ", + ["R"] = "REPLACE ", + ["Rv"] = "V·REPLACE ", + ["c"] = "COMMAND ", + ["cv"] = "VIM EX ", + ["ce"] = "EX ", + ["r"] = "PROMPT ", + ["rm"] = "MORE ", + ["r?"] = "CONFIRM ", + ["!"] = "SHELL ", + ["t"] = "TERMINAL ", + }, + }, + provider = function(self) + return " %2(" .. self.mode_names[vim.fn.mode(1)] .. "%)" + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color, fg = colors.bg, bold = true } + end, +} + +-- LSP + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = {'LspAttach', 'LspDetach'}, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +-- on_click = { +-- callback = function() +-- vim.defer_fn(function() +-- vim.cmd("LspInfo") +-- end, 100) +-- end, +-- name = "heirline_LSP", +-- }, +--} + +--local LSPActive = { +-- condition = conditions.lsp_attached, +-- update = { "LspAttach", "LspDetach" }, +-- +-- -- You can keep it simple, +-- -- provider = " [LSP]", +-- +-- -- Or complicate things a bit and get the servers names +-- provider = function() +-- local names = {} +-- for i, server in pairs(vim.lsp.buf_get_clients(0)) do +-- table.insert(names, server.name) +-- end +-- return " [" .. table.concat(names, " ") .. "]" +-- end, +-- hl = { fg = "green", bold = true }, +--} + +local LSPActive = { + condition = conditions.lsp_attached, + + provider = function() + local names = vim.tbl_values(vim.tbl_map(function(cl) + return cl.name + end, vim.lsp.buf_get_clients(0))) + + return "LSP [" .. table.concat(names, " ") .. "]" + end, + hl = { fg = colors.green }, +} +-- lsp status +-- I personally use it only to display progress messages! +-- See lsp-status/README.md for configuration options. + +-- Note: check "j-hui/fidget.nvim" for a nice statusline-free alternative. +local LSPMessages = { + provider = require("lsp-status").status, + hl = { fg = "gray" }, +} + +-- Nvim Navic +--local Navic = { +-- condition = require("nvim-navic").is_available, +-- provider = require("nvim-navic").get_location, +--} +--local Navic = utils.make_flexible_component(3, Navic, { provider = "" }) + +-- Full nerd (with icon colors)! +local Navic = { + condition = require("nvim-navic").is_available, + static = { + -- create a type highlight map + type_hl = { + File = "Directory", + Module = "Include", + Namespace = "TSNamespace", + Package = "Include", + Class = "Struct", + Method = "Method", + Property = "TSProperty", + Field = "TSField", + Constructor = "TSConstructor ", + Enum = "TSField", + Interface = "Type", + Function = "Function", + Variable = "TSVariable", + Constant = "Constant", + String = "String", + Number = "Number", + Boolean = "Boolean", + Array = "TSField", + Object = "Type", + Key = "TSKeyword", + Null = "Comment", + EnumMember = "TSField", + Struct = "Struct", + Event = "Keyword", + Operator = "Operator", + TypeParameter = "Type", + }, + }, + init = function(self) + local data = require("nvim-navic").get_data() or {} + local children = {} + -- create a child for each level + for i, d in ipairs(data) do + local child = { + { + provider = d.icon, + hl = self.type_hl[d.type], + }, + { + provider = d.name, + -- highlight icon only or location name as well + -- hl = self.type_hl[d.type], + }, + } + -- add a separator only if needed + if #data > 1 and i < #data then + table.insert(child, { + provider = " > ", + hl = { fg = "bright_fg" }, + }) + end + table.insert(children, child) + end + -- instantiate the new child, overwriting the previous one + self[1] = self:new(children, 1) + end, + hl = { fg = "gray" }, +} + +-- Diagnostics +local Diagnostics = { + + condition = conditions.has_diagnostics, + + static = { + error_icon = vim.fn.sign_getdefined("DiagnosticSignError")[1].text, + warn_icon = vim.fn.sign_getdefined("DiagnosticSignWarn")[1].text, + info_icon = vim.fn.sign_getdefined("DiagnosticSignInfo")[1].text, + hint_icon = vim.fn.sign_getdefined("DiagnosticSignHint")[1].text, + }, + + init = function(self) + self.errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + self.warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + self.hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + self.info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + end, + + update = { "DiagnosticChanged", "BufEnter" }, + + { + provider = function(self) + -- 0 is just another output, we can decide to print it or not! + return self.errors > 0 and (self.error_icon .. self.errors .. " ") + end, + hl = { fg = colors.diag.error, bg = colors.bg }, + }, + { + provider = function(self) + return self.warnings > 0 and (self.warn_icon .. self.warnings .. " ") + end, + hl = { fg = colors.diag.warn, bg = colors.bg }, + }, + { + provider = function(self) + return self.info > 0 and (self.info_icon .. self.info .. " ") + end, + hl = { fg = colors.diag.info, bg = colors.bg }, + }, + { + provider = function(self) + return self.hints > 0 and (self.hint_icon .. self.hints) + end, + hl = { fg = colors.diag.hint, bg = colors.bg }, + }, + --{ + -- provider = "]", + --}, + on_click = { + callback = function() + require("trouble").toggle({ mode = "document_diagnostics" }) + -- or + -- vim.diagnostic.setqflist() + end, + name = "heirline_diagnostics", + }, +} + +-- Git +-- For the ones who're not (too) afraid of changes! Uses gitsigns. +local Git = { + condition = conditions.is_git_repo, + + init = function(self) + self.status_dict = vim.b.gitsigns_status_dict + self.has_changes = self.status_dict.added ~= 0 or self.status_dict.removed ~= 0 or self.status_dict.changed ~= 0 + end, + --hl = { fg = "orange" }, + hl = { fg = colors.orange, bg = colors.bg }, + { -- git branch name + provider = function(self) + return " " .. self.status_dict.head + end, + --hl = { bold = true }, + hl = { bold = true, bg = colors.bg }, + }, + -- You could handle delimiters, icons and counts similar to Diagnostics + { + condition = function(self) + return self.has_changes + end, + --provider = "(" + provider = " ", + }, + { + provider = function(self) + local count = self.status_dict.added or 0 + --return count > 0 and ("+" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_add" }, + hl = { fg = colors.git.add, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.removed or 0 + --return count > 0 and ("-" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_del" }, + hl = { fg = colors.git.del, bg = colors.bg }, + }, + { + provider = function(self) + local count = self.status_dict.changed or 0 + --return count > 0 and ("~" .. count) + return count > 0 and (" " .. count) + end, + --hl = { fg = "git_change" }, + hl = { fg = colors.git.change, bg = colors.bg }, + }, + --{ + -- condition = function(self) + -- return self.has_changes + -- end, + -- provider = ")", + --}, + on_click = { + callback = function() + -- If you want to use Fugitive: + -- vim.cmd("G") + + -- If you prefer Lazygit + -- use vim.defer_fn() if the callback requires + -- opening of a floating window + -- (this also applies to telescope) + vim.defer_fn(function() + vim.cmd("Lazygit") + end, 100) + end, + name = "heirline_git", + }, +} + +-- Debugger +-- Display informations from nvim-dap! +local DAPMessages = { + -- display the dap messages only on the debugged file + condition = function() + local session = require("dap").session() + if session then + local filename = vim.api.nvim_buf_get_name(0) + if session.config then + local progname = session.config.program + return filename == progname + end + end + return false + end, + provider = function() + return " " .. require("dap").status() + end, + hl = { fg = utils.get_highlight("Debug").fg }, + -- Debugger on_click: step-over, step-into, next, previous, stop buttons + -- coming soon! +} + +-- Tests +-- This requires the great ultest. +--local UltTest = { +-- condition = function() +-- return vim .api.nvim_call_function("ultest#is_test_file", {}) ~= 0 +-- end, +-- static = { +-- passed_icon = vim.fn.sign_getdefined("test_pass")[1].text, +-- failed_icon = vim.fn.sign_getdefined("test_fail")[1].text, +-- passed_hl = { fg = utils.get_highlight("UltestPass").fg }, +-- failed_hl = { fg = utils.get_highlight("UltestFail").fg }, +-- }, +-- init = function(self) +-- self.status = vim.api.nvim_call_function("ultest#status", {}) +-- end, +-- +-- -- again, if you'd like icons and numbers to be colored differently, +-- -- just split the component in two +-- { +-- provider = function(self) +-- return self.passed_icon .. self.status.passed .. " " +-- end, +-- hl = function(self) +-- return self.passed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return self.failed_icon .. self.status.failed .. " " +-- end, +-- hl = function(self) +-- return self.failed_hl +-- end, +-- }, +-- { +-- provider = function(self) +-- return "of " .. self.status.tests - 1 +-- end, +-- }, +--} + +-- FileName and Friends + +--local Align = { provider = "%=" } +local Align = { provider = "%=", hl = { bg = colors.bg } } +local Space = { provider = " ", hl = { bg = colors.bg } } +local Tab = { provider = " " } +local Fill = { provider = "%=", hl = { bg = colors.nobg } } +local LeftSep = { provider = "", hl = { fg = colors.bg } } +local RightSep = { provider = "", hl = { fg = colors.bg } } + +local FileNameBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg }, +} +-- We can now define some children separately and add them later +-- + +local FileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color, bg = colors.bg } + end, +} + +local FileName = { + provider = function(self) + -- first, trim the pattern relative to the current directory. For other + -- options, see :h filename-modifers + local filename = vim.fn.fnamemodify(self.filename, ":.") + if filename == "" then + return "No Name" + end + -- now, if the filename would occupy more than 1/4th of the available + -- space, we trim the file path to its initials + -- See Flexible Components section below for dynamic truncation + if not conditions.width_percent_below(#filename, 0.25) then + filename = vim.fn.pathshorten(filename) + end + return filename + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +local FileFlags = { + { + provider = function() + if vim.bo.modified then + return " [+]" + --±[+] + end + end, + hl = { fg = colors.green, bg = colors.bg }, + }, + { + provider = function() + if not vim.bo.modifiable or vim.bo.readonly then + return " " + end + end, + --hl = { fg = colors.orange }, + hl = { fg = colors.orange, bold = true, bg = colors.bg }, + }, +} +-- Now, let's say that we want the filename color to change if the buffer is +-- modified. Of course, we could do that directly using the FileName.hl field, +-- but we'll see how easy it is to alter existing components using a "modifier" +-- component + +local FileNameModifer = { + hl = function() + if vim.bo.modified then + return { fg = colors.green, bold = false, force = true } + end + end, +} + +-- FileType, FileEncoding and FileFormat +local FileType = { + provider = function() + return vim.bo.filetype + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = false, bg = colors.bg }, +} + +--local FileEncoding = { +-- provider = function() +-- local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' +-- return enc ~= "utf-8" and enc:upper() +-- end, +-- hl = { bg = colors.bg }, +--} +local FileEncoding = { + Space, + provider = function() + local enc = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc -- :h 'enc' + return enc:lower() + end, + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { bg = colors.bg, bold = false }, +} + +local FileFormat = { + provider = function() + local fmt = vim.bo.fileformat + return fmt ~= "unix" and fmt:upper() + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- FileSize and FileLastModified +local FileSize = { + provider = function() + -- stackoverflow, compute human readable file size + local suffix = { "b", "k", "M", "G", "T", "P", "E" } + local fsize = vim.fn.getfsize(vim.api.nvim_buf_get_name(0)) + fsize = (fsize < 0 and 0) or fsize + if fsize < 1024 then + return fsize .. suffix[1] + end + local i = math.floor((math.log(fsize) / math.log(1024))) + return string.format("%.2g%s", fsize / math.pow(1024, i), suffix[i + 1]) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +local FileLastModified = { + -- did you know? Vim is full of functions! + provider = function() + local ftime = vim.fn.getftime(vim.api.nvim_buf_get_name(0)) + return (ftime > 0) and os.date("%c", ftime) + end, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, +} + +-- Spell +-- Add indicator when spell is set! +local Spell = { + condition = function() + return vim.wo.spell + end, + provider = "SPELL ", + hl = { bold = true, fg = "orange" }, +} + +-- Cursor position: Ruler and ScrollBar +-- We're getting minimalists here! +local Ruler = { + -- We're getting minimalists here! + -- %l = current line number + -- %L = number of lines in the buffer + -- %c = column number + -- %P = percentage through file of displayed window + --provider = "%P %(%l/%L%):%c ", + --provider = "%3(%2l%):%c %P ", + --provider = "%7(%l/%3L%):%2c%P ", + --provider = "%3(%P%)", + --provider = "%7(%l/%3L%):%2c %P", + --provider = "%7 %p%% Ln %l, Col %c", + --provider = "%9( %P %2l/%L :%2c %)", + --provider = "%9(%2l%2( : %c%)/%L %P %)", + --provider = "%7(%l:%c/%L%) ", + --provider = "%6(%l:%1.5c/%L%) %P ", + provider = "%6(%l:%1.5c/%L%) ", + hl = { fg = utils.get_highlight("Statusline").fg, bold = false }, +} + +local WordCount = { + condition = function() + return conditions.buffer_matches({ + filetype = { + "markdown", + "txt", + "vimwiki", + }, + }) + end, + Space, + { + provider = function() + return "W:" .. vim.fn.wordcount().words + end, + }, +} + +local Position = { + Space, + { provider = "%l:%c" }, + hl = { bg = colors.bg }, +} + +local Percentage = { + Space, + { provider = "%P" }, + hl = { bg = colors.bg }, +} +-- Working Directory +local WorkDir = { + provider = function(self) + self.icon = (vim.fn.haslocaldir(0) == 1 and "l" or "g") .. " " .. " " + local cwd = vim.fn.getcwd(0) + self.cwd = vim.fn.fnamemodify(cwd, ":~") + end, + hl = { fg = colors.blue, bold = true, bg = colors.bg }, + + utils.make_flexible_component(1, { + -- evaluates to the full-lenth path + provider = function(self) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. self.cwd .. trail .. " " + end, + }, { + -- evaluates to the shortened path + provider = function(self) + local cwd = vim.fn.pathshorten(self.cwd) + local trail = self.cwd:sub(-1) == "/" and "" or "/" + return self.icon .. cwd .. trail .. " " + end, + }, { + -- evaluates to "", hiding the component + provider = "", + }), +} + +-- Terminal Name +-- Special handling of the built-in terminal bufname. See conditional statuslines below to see an example of dedicated statusline for terminals! + +local TerminalName = { + -- we could add a condition to check that buftype == 'terminal' + -- or we could do that later (see #conditional-statuslines below) + provider = function() + local tname, _ = vim.api.nvim_buf_get_name(0):gsub(".*:", "") + return " " .. tname + end, + hl = { bold = true, bg = colors.bg }, +} + +-- Snippets Indicator +-- This requires ultisnips +--local Snippets = { +-- -- check that we are in insert or select mode +-- condition = function() +-- return vim.tbl_contains({'s', 'i'}, vim.fn.mode()) +-- end, +-- provider = function() +-- local forward = (vim.fn["UltiSnips#CanJumpForwards"]() == 1) and "" or "" +-- local backward = (vim.fn["UltiSnips#CanJumpBackwards"]() == 1) and " " or "" +-- return backward .. forward +-- end, +-- hl = { fg = "red", bold = true }, +--} + +-- let's add the children to our FileNameBlock component +--FileNameBlock = utils.insert( +-- FileNameBlock, +--FileEncoding, +--Space, +--FileIcon, +--FileType, +--FileLastModified, +--FileSize, +--FileFormat, +--FileNameModifer, +-- unpack(FileFlags), +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) +-- let's add the children to our FileNameBlock component +FileNameBlock = utils.insert( + FileNameBlock, + FileIcon, + utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier + unpack(FileFlags), -- A small optimisation, since their parent does nothing + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) + +local FileInfoBlock = { + -- let's first set up some attributes needed by this component and it's children + init = function(self) + self.filename = vim.api.nvim_buf_get_name(0) + end, +} + +FileInfoBlock = utils.insert( + FileInfoBlock, + Space, + FileIcon, + FileType, + { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +) +--FileNameBlock = utils.insert( +-- FileNameBlock, +-- FileIcon, +-- utils.insert(FileNameModifer, FileName), -- a new table where FileName is a child of FileNameModifier +-- unpack(FileFlags), -- A small optimisation, since their parent does nothing +-- { provider = "%<" } -- this means that the statusline is cut here when there's not enough space +--) + +local Surrr = { + utils.surround({ "", "" }, "red", { + utils.surround({ "", "" }, "green", utils.surround({ "", "" }, "blue", { provider = "heyya" })), + { provider = "Normal" }, + }), +} +--ViMode = utils.surround({ "", "" }, "bright_bg", { ViMode, Snippets }) +--ViMode = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +--ViMode = utils.surround({ "◥", "" }, function(self) return self:mode_color() end, { +-- utils.surround({ "█", "" }, function(self) return self:mode_color() end, utils.surround({ "", "" }, function(self) return self:mode_color() end, { {provider = "normal" }, ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } } )), +-- { provider = "heyya" }, +-- }) +-- Statusline +--BackgroundStatusline = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { BackgroundStatusline, hl = { bg = utils.get_highlight("statusline").bg, force = true } }) +-- +local Surrr = { + utils.surround({ "", "" }, "gray", { + FileInfoBlock, + hl = { bg = colors.gray }, + utils.surround({ "", "" }, "gray", { + Percentage, + utils.surround({ "", "" }, function(self) + return self:mode_color() + end, { Space, Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }), + }), + }), +} + +ViMode = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) + +LeftSpace = utils.surround({ "", " " }, function(self) + return self:mode_color() +end, { LeftSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +-- +RightSpace = utils.surround( + { "", "" }, + colors.red, + { RightSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } } +) + +RightSpace2 = utils.surround({ "", "" }, colors.orange, { RightSpace2, hl = { bg = colors.red, force = true } }) +--RightSpace = utils.surround({ "", "" }, function(self) +-- return self:mode_color() +--end, { RightSpace, hl = { fg = utils.get_highlight("statusline").bg, force = true } }) +---- +-- +--Percentage = utils.surround({ "", " " }, "red", { Percentage, hl = { bg = colors.red, force = true } }) +-- + +LSPActive = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { Space, LSPActive, hl = { bg = colors.orange, force = true } }) + +FileInfoBlock = utils.surround({ "", "" }, function(self) + return self:mode_color() +end, { FileInfoBlock, Space, hl = { bg = colors.red, force = true } }) + +Ruler = utils.surround({ "", "" }, colors.red, { Space, Ruler, hl = { fg = colors.red, force = true } }) + +local align = { provider = "%=" } +local left = { + { ViMode, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, + { LeftSpace, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileNameBlock, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Git, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local middle = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Navic, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { DAPMessages, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, +} +local right = { + { Align, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { Diagnostics, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { LSPActive, hl = { bg = colors.orange, force = true } }, + --{ FileEncoding, hl = { bg = colors.orange, force = true } }, + { RightSpace2, hl = { fg = colors.orange, bg = colors.red, force = true } }, + --{ Space, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { FileInfoBlock, hl = { bg = colors.red, force = true } }, + --{ Space, hl = { bg = colors.red, force = true } }, + --{ FileType, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + --{ WordCount, hl = { bg = utils.get_highlight("statusline").bg, force = true } }, + { RightSpace, hl = { fg = colors.red, force = true } }, + { Ruler, hl = { fg = utils.get_highlight("statusline").bg, force = true } }, +} + +local sections = { left, align, middle, align, right } +local DefaultStatusline = { sections } + +--local NewSpace = { provider = "", hl = { bg = utils.get_highlight("statusline").bg } } +--local statusline = { +--Space, +--Space, +--Git, +--Space, +--Diagnostics, +--Align, +--Navic, +--DAPMessages, +--Align, +--Space, +--FileInfoBlock, +--Space, +--WordCount, +--Ruler, +--LSPActive, Space, LSPMessages, Space, UltTest, Space, FileType, Space, Ruler, Space, ScrollBar +--} + +--local InactiveStatusline = { +-- condition = conditions.is_not_active, +-- FileType, +-- Space, +-- FileName, +-- Align, +--} + +local SpecialStatusline = { + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + + FileType, + Space, + Align, + --FileType, Space, HelpFileName, Align +} + +local TerminalStatusline = { + + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + + hl = { bg = "dark_red" }, + + -- Quickly add a condition to the ViMode to only show it when buffer is active! + { condition = conditions.is_active, ViMode, Space }, + FileType, + Space, + TerminalName, + Align, +} + +local StatusLine = { + + --hl = function() + -- if conditions.is_active() then + -- return "StatusLine" + -- else + -- return "StatusLineNC" + -- end + --end, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + --mode_colors_map = { + -- n = colors.blue, + -- i = colors.green, + -- v = colors.purple, + -- V = colors.violet, + -- [""] = colors.red, + -- c = colors.yellow, + -- s = colors.orange, + -- S = colors.orange, + -- [""] = colors.purple, + -- R = colors.orange, + -- r = colors.orange, + -- ["!"] = colors.red, + -- t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + hl = function(self) + local color = self:mode_color() -- here! + return { bg = color } + end, + }, + fallthrough = false, + + SpecialStatusline, + TerminalStatusline, + --InactiveStatusline, + DefaultStatusline, +} + +-- WinBar + +vim.api.nvim_create_autocmd("User", { + pattern = "HeirlineInitWinbar", + callback = function(args) + local buf = args.buf + local buftype = vim.tbl_contains({ "prompt", "nofile", "help", "quickfix" }, vim.bo[buf].buftype) + local filetype = vim.tbl_contains({ "gitcommit", "fugitive" }, vim.bo[buf].filetype) + if buftype or filetype then + vim.opt_local.winbar = nil + end + end, +}) + +on_click = { + -- get the window id of the window in which the component was evaluated + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + -- winid is the window id of the window the component was clicked from + local winid = minwid + -- do something with the window id, e.g.: + local buf = vim.api.nvim_win_get_buf(winid) + -- ... + end, +} + +local CloseButton = { + condition = function(self) + return not vim.bo.modified + end, + -- a small performance improvement: + -- re register the component callback only on layout/buffer changes. + update = { "WinNew", "WinClosed", "BufEnter" }, + { provider = " " }, + { + provider = "", + hl = { fg = "gray" }, + on_click = { + minwid = function() + return vim.api.nvim_get_current_win() + end, + callback = function(_, minwid) + vim.api.nvim_win_close(minwid, true) + end, + name = "heirline_winbar_close_button", + }, + }, +} + +local active_middle_segment = { --{{{ + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + static = { + mode_colors_map = { + n = colors.blue, + i = colors.green, + v = colors.purple, + V = colors.purple, + [""] = colors.purple, + c = colors.red, + s = colors.purple, + S = colors.purple, + [""] = colors.purple, + R = colors.orange, + r = colors.orange, + ["!"] = colors.red, + t = colors.red, + }, + mode_color = function(self) + local mode = conditions.is_active() and vim.fn.mode() or "n" + return self.mode_colors_map[mode] + end, + provider = "%f", + hl = function(self) + local color = self:mode_color() -- here! + return { fg = color } + end, + -- self.filename will be defined later, just keep looking at the example! + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, "dark_red", { + FileType, + Space, + TerminalName, + }), + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), + }, +} + +--local WinBar = { +-- Fill, +-- active_middle_segment, +-- Fill, +--} +local WinBar = { + fallthrough = false, + { -- Hide the winbar for special buffers + condition = function() + return conditions.buffer_matches({ + buftype = { "nofile", "prompt", "help", "quickfix" }, + filetype = { "^git.*", "fugitive" }, + }) + end, + init = function() + vim.opt_local.winbar = nil + end, + }, + { -- A special winbar for terminals + condition = function() + return conditions.buffer_matches({ buftype = { "terminal" } }) + end, + utils.surround({ "", "" }, "dark_red", { + FileType, + Space, + TerminalName, + }), + }, + { -- An inactive winbar for regular files + condition = function() + return not conditions.is_active() + end, + utils.surround({ "", "" }, "bright_bg", { hl = { fg = "gray", force = true }, FileNameBlock }), + }, + -- A winbar for regular files + utils.surround({ "", "" }, "bright_bg", FileNameBlock), +} + +-- TabLine +-- + +local TablineBufnr = { + provider = function(self) + return tostring(self.bufnr) .. "." + end, + --hl = "Comment", + --hl = { fg = utils.get_highlight("Statusline").fg, bold = true, bg = colors.bg }, + hl = { fg = utils.get_highlight("Statusline").fg, bold = true }, +} + +-- we redefine the filename component, as we probably only want the tail and not the relative path +local TablineFileName = { + provider = function(self) + -- self.filename will be defined later, just keep looking at the example! + local filename = self.filename + filename = filename == "" and "No Name" or vim.fn.fnamemodify(filename, ":t") + return filename + end, + hl = function(self) + return { bold = self.is_active or self.is_visible, italic = true } + end, +} + +local TablineFileFlags = { + { + provider = function(self) + if vim.bo[self.bufnr].modified then + return " [+] " + end + end, + hl = { fg = colors.green }, + }, + --+ + { + provider = function(self) + if not vim.bo[self.bufnr].modifiable or vim.bo[self.bufnr].readonly then + return " " + end + end, + hl = { fg = "orange" }, + }, +} + +local TablineFileIcon = { + init = function(self) + local filename = self.filename + local extension = vim.fn.fnamemodify(filename, ":e") + self.icon, self.icon_color = + require("nvim-web-devicons").get_icon_color(filename, extension, { default = true }) + end, + provider = function(self) + return self.icon and (" " .. self.icon .. " ") + end, + hl = function(self) + return { fg = self.icon_color } + end, +} + +-- Here the filename block finally comes together +local TablineFileNameBlock = { + init = function(self) + self.filename = vim.api.nvim_buf_get_name(self.bufnr) + end, + hl = function(self) + if self.is_active then + return "TabLineSel" + -- why not? + --elseif not vim.api.nvim_buf_is_loaded(self.bufnr) then + --return { fg = "gray", bg = colors.bg } + else + return "TabLineFill" + end + end, + on_click = { + callback = function(_, minwid, _, button) + if button == "m" then -- close on mouse middle click + vim.api.nvim_buf_delete(minwid, { force = false }) + else + vim.api.nvim_win_set_buf(0, minwid) + end + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_buffer_callback", + }, + TablineBufnr, + --FileIcon, -- turns out the version defined in #crash-course-part-ii-filename-and-friends can be reutilized as is here! + TablineFileIcon, + TablineFileName, + TablineFileFlags, +} + +-- a nice "x" button to close the buffer +local TablineCloseButton = { + condition = function(self) + return not vim.api.nvim_buf_get_option(self.bufnr, "modified") + end, + { provider = " " }, + { + provider = " ", + --hl = { fg = "red", bg = colors.bg }, + hl = { fg = "red" }, + on_click = { + callback = function(_, minwid) + vim.api.nvim_buf_delete(minwid, { force = false }) + end, + minwid = function(self) + return self.bufnr + end, + name = "heirline_tabline_close_buffer_callback", + }, + }, +} + +-- The final touch! +local TablineBufferBlock = utils.surround({ "", "" }, function(self) + --local TablineBufferBlock = utils.surround({ "█", "█" }, function(self) + if self.is_active then + return utils.get_highlight("TabLineSel").bg + else + return utils.get_highlight("TabLineFill").bg + end +end, { Tab, TablineFileNameBlock, TablineCloseButton }) + +local BufferLine = utils.make_buflist( + TablineBufferBlock, + --{ provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + --{ provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + { provider = "", hl = { fg = "gray" } }, -- left truncation, optional (defaults to "<") + { provider = "", hl = { fg = "gray" } } -- right trunctation, also optional (defaults to ...... yep, ">") + -- by the way, open a lot of buffers and try clicking them ;) +) + +-- TabList +local Tabpage = { + provider = function(self) + return "%" .. self.tabnr .. "T " .. self.tabnr .. " %T" + end, + hl = function(self) + if not self.is_active then + return "TabLine" + else + return "TabLineSel" + end + end, +} + +local TabpageClose = { + provider = "%999X %X", + --hl = "TabLine", + hl = { fg = colors.red, bg = colors.bg }, +} + +local TabPages = { + -- only show this component if there's 2 or more tabpages + condition = function() + return #vim.api.nvim_list_tabpages() >= 2 + end, + { provider = "%=" }, + utils.make_tablist(Tabpage), + TabpageClose, +} + +-- TabLineOffset +local TabLineOffset = { + condition = function(self) + local win = vim.api.nvim_tabpage_list_wins(0)[1] + local bufnr = vim.api.nvim_win_get_buf(win) + self.winid = win + + if vim.bo[bufnr].filetype == "NvimTree" then + self.title = "NvimTree" + return true + -- elseif vim.bo[bufnr].filetype == "TagBar" then + -- ... + end + end, + + provider = function(self) + local title = self.title + local width = vim.api.nvim_win_get_width(self.winid) + local pad = math.ceil((width - #title) / 2) + return string.rep(" ", pad) .. title .. string.rep(" ", pad) + end, + + hl = function(self) + if vim.api.nvim_get_current_win() == self.winid then + return "TablineSel" + else + return "Tabline" + end + end, +} + +local TabLine = { + --hl = { bg = colors.bg }, + fallthrough = false, + TabLineOffset, + BufferLine, + TabPages, +} + +require("heirline").setup(StatusLine, WinBar, TabLine) +--require("heirline").setup(StatusLine, TabLine) + +-- Yep, with heirline we're driving manual! +vim.cmd([[au FileType * if index(['wipe', 'delete', 'unload'], &bufhidden) >= 0 | set nobuflisted | endif]]) + +--local function get_bufs() +-- return vim.tbl_filter(function(bufnr) +-- return vim.api.nvim_buf_is_loaded(bufnr) and vim.bo[bufnr].buflisted +-- end, vim.api.nvim_list_bufs()) +--end +-- +--local function goto_buf(index) +-- local bufs = get_bufs() +-- if index > #bufs then +-- index = #bufs +-- end +-- vim.api.nvim_win_set_buf(0, bufs[index]) +--end +-- +--local function addKey(key, index) +-- vim.keymap.set("", "<A-" .. key .. ">", function() +-- goto_buf(index) +-- end, { noremap = true, silent = true }) +--end +-- +--for i = 1, 9 do +-- addKey(i, i) +--end +--addKey("0", 10) diff --git a/lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua b/lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua new file mode 100644 index 0000000..dd25d9a --- /dev/null +++ b/lua/plugins/lsp-22.10.12-21:29-bak-22.10.12-23:45-bak.lua @@ -0,0 +1,301 @@ +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({ + single_file_support = true, + on_attach = function(client, bufnr) + print('hello') + lspconfig.util.default_config.on_attach(client, bufnr) + end +}) + +vim.api.nvim_create_autocmd('User', { + pattern = 'LspAttached', + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + local opts = {buffer = true} + vim.keymap.set(mode, lhs, rhs, opts) + end + + -- Displays hover information about the symbol under the cursor + bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>') + + -- Jump to the definition + bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>') + + -- Jump to declaration + bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>') + + -- Lists all the implementations for the symbol under the cursor + bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>') + + -- Jumps to the definition of the type symbol + bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>') + + -- Lists all the references + bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>') + + -- Displays a function's signature information + bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>') + + -- Renames all references to the symbol under the cursor + bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>') + + -- Selects a code action available at the current cursor position + bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>') + bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>') + + -- Show diagnostics in a floating window + bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>') + + -- Move to the previous diagnostic + bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>') + + -- Move to the next diagnostic + bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>') + end +}) + +-- +---Snippets +-- +require('luasnip.loaders.from_vscode').lazy_load() + +-- +--- Autocompletion/nvim-cmp +-- +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} -- Suggested values for completeopt +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + +}) + +snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end +}, + +sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, +}, + +window = { + documentation = cmp.config.window.bordered() +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'} +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, +}, + +mapping = { + ['<CR>'] = cmp.mapping.confirm({select = true}), +} +['<Up>'] = cmp.mapping.select_prev_item(select_opts), +['<Down>'] = cmp.mapping.select_next_item(select_opts), + +['<C-p>'] = cmp.mapping.select_prev_item(select_opts), +['<C-n>'] = cmp.mapping.select_next_item(select_opts), +['<C-u>'] = cmp.mapping.scroll_docs(-4), +['<C-f>'] = cmp.mapping.scroll_docs(4), +['<C-e>'] = cmp.mapping.abort(), +['<CR>'] = cmp.mapping.confirm({select = true}), +['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end +end, {'i', 's'}), +['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end +end, {'i', 's'}), + +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} + +require('luasnip.loaders.from_vscode').lazy_load() + +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, + mapping = { + ['<Up>'] = cmp.mapping.select_prev_item(select_opts), + ['<Down>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-p>'] = cmp.mapping.select_prev_item(select_opts), + ['<C-n>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-u>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + + ['<C-e>'] = cmp.mapping.abort(), + ['<CR>'] = cmp.mapping.confirm({select = true}), + + ['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, {'i', 's'}), + + ['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {'i', 's'}), + + ['<Tab>'] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, {'i', 's'}), + + ['<S-Tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, {'i', 's'}), + }, +}) + + +vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + {border = 'rounded'} +) + +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + {border = 'rounded'} +) + +require('mason').setup() +require('mason-lspconfig').setup() + + +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({}) + + + + + + + + diff --git a/lua/plugins/lsp-22.10.12-21:29-bak.lua b/lua/plugins/lsp-22.10.12-21:29-bak.lua new file mode 100644 index 0000000..dd25d9a --- /dev/null +++ b/lua/plugins/lsp-22.10.12-21:29-bak.lua @@ -0,0 +1,301 @@ +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({ + single_file_support = true, + on_attach = function(client, bufnr) + print('hello') + lspconfig.util.default_config.on_attach(client, bufnr) + end +}) + +vim.api.nvim_create_autocmd('User', { + pattern = 'LspAttached', + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + local opts = {buffer = true} + vim.keymap.set(mode, lhs, rhs, opts) + end + + -- Displays hover information about the symbol under the cursor + bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>') + + -- Jump to the definition + bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>') + + -- Jump to declaration + bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>') + + -- Lists all the implementations for the symbol under the cursor + bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>') + + -- Jumps to the definition of the type symbol + bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>') + + -- Lists all the references + bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>') + + -- Displays a function's signature information + bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>') + + -- Renames all references to the symbol under the cursor + bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>') + + -- Selects a code action available at the current cursor position + bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>') + bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>') + + -- Show diagnostics in a floating window + bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>') + + -- Move to the previous diagnostic + bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>') + + -- Move to the next diagnostic + bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>') + end +}) + +-- +---Snippets +-- +require('luasnip.loaders.from_vscode').lazy_load() + +-- +--- Autocompletion/nvim-cmp +-- +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} -- Suggested values for completeopt +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + +}) + +snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end +}, + +sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, +}, + +window = { + documentation = cmp.config.window.bordered() +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'} +}, + +formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, +}, + +mapping = { + ['<CR>'] = cmp.mapping.confirm({select = true}), +} +['<Up>'] = cmp.mapping.select_prev_item(select_opts), +['<Down>'] = cmp.mapping.select_next_item(select_opts), + +['<C-p>'] = cmp.mapping.select_prev_item(select_opts), +['<C-n>'] = cmp.mapping.select_next_item(select_opts), +['<C-u>'] = cmp.mapping.scroll_docs(-4), +['<C-f>'] = cmp.mapping.scroll_docs(4), +['<C-e>'] = cmp.mapping.abort(), +['<CR>'] = cmp.mapping.confirm({select = true}), +['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end +end, {'i', 's'}), +['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end +end, {'i', 's'}), + +vim.opt.completeopt = {'menu', 'menuone', 'noselect'} + +require('luasnip.loaders.from_vscode').lazy_load() + +local cmp = require('cmp') +local luasnip = require('luasnip') + +local select_opts = {behavior = cmp.SelectBehavior.Select} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 3}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, + mapping = { + ['<Up>'] = cmp.mapping.select_prev_item(select_opts), + ['<Down>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-p>'] = cmp.mapping.select_prev_item(select_opts), + ['<C-n>'] = cmp.mapping.select_next_item(select_opts), + + ['<C-u>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + + ['<C-e>'] = cmp.mapping.abort(), + ['<CR>'] = cmp.mapping.confirm({select = true}), + + ['<C-d>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, {'i', 's'}), + + ['<C-b>'] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, {'i', 's'}), + + ['<Tab>'] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, {'i', 's'}), + + ['<S-Tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, {'i', 's'}), + }, +}) + + +vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + {border = 'rounded'} +) + +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + {border = 'rounded'} +) + +require('mason').setup() +require('mason-lspconfig').setup() + + +local lsp_defaults = { + flags = { + debounce_text_changes = 150, + }, + capabilities = require('cmp_nvim_lsp').update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + end +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +lspconfig.sumneko_lua.setup({}) + + + + + + + + diff --git a/lua/plugins/lsp-22.10.14-23:39-bak.lua b/lua/plugins/lsp-22.10.14-23:39-bak.lua new file mode 100644 index 0000000..9c8e943 --- /dev/null +++ b/lua/plugins/lsp-22.10.14-23:39-bak.lua @@ -0,0 +1,422 @@ + +local fn = vim.fn +local keymap = vim.keymap + +local utils = require("utils") + +local custom_attach = function(client, bufnr) + -- Enable completion triggered by <c-x><c-o> + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.noremap = true + opts.buffer = bufnr + keymap.set(mode, l, r, opts) + end +--map("n", "gd", "<Cmd>Lspsaga lsp_finder<CR>") -- Press "o" to open the reference location +--map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>") +-- --map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) +-- map("n", "<C-]>", vim.lsp.buf.definition) +-- map("n", "K", vim.lsp.buf.hover) +-- map("n", "<C-k>", vim.lsp.buf.signature_help) +-- map("n", "<leader>rn", vim.lsp.buf.rename, { desc = "varialble rename" }) +-- map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) +-- map("n", "[d", vim.diagnostic.goto_prev, { desc = "previous diagnostic" }) +-- map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic" }) +-- map("n", "<leader>q", function() +-- vim.diagnostic.setqflist({ open = true }) +-- end, { desc = "put diagnostic to qf" }) +-- --map.('n', '<space>q', vim.diagnostic.setloclist) +-- map("n", "ga", vim.lsp.buf.code_action, { desc = "LSP code action" }) +-- map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) +-- map("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) +-- map("n", "<leader>wl", function() +-- print(vim.inspect(vim.lsp.buf.list_workspace_folders())) +-- end, { desc = "list workspace folder" }) +-- map("n", "gs", "vim.lsp.buf.document_symbol()<cr>") +-- map("n", "gw", "vim.lsp.buf.workspace_symbol()<cr>", { desc = "list workspace folder" }) +-- --map("n", "gs", ":lua vim.lsp.buf.document_symbol()<cr>") +-- map("n", "gt", ":lua vim.lsp.buf.type_definition()<cr>") +-- map("n", "gD", ":lua vim.lsp.buf.declaration()<cr>") -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. +-- map("n", "gi", ":lua vim.lsp.buf.implementation()<cr>") +-- map("n", "go", ":lua vim.diagnostic.open_float()<cr>") +-- map("n", "gk", "<Cmd>Lspsaga diagnostic_jump_prev<CR>") +-- map("n", "gj", "<Cmd>Lspsaga diagnostic_jump_next<CR>") + + -- Set some key bindings conditional on server capabilities + if client.server_capabilities.documentFormattingProvider then + map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" }) + end + + -- add rust specific keymappings + if client.name == "rust_analyzer" then + map("n", "<leader>rr", "<cmd>RustRunnables<CR>") + map("n", "<leader>ra", "<cmd>RustHoverAction<CR>") + end + + -- Diagnostic position + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local float_opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = "rounded", + source = "always", -- show source in diagnostic popup window + prefix = " ", + } + + if not vim.b.diagnostics_pos then + vim.b.diagnostics_pos = { nil, nil } + end + + local cursor_pos = vim.api.nvim_win_get_cursor(0) + if + (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) + and #vim.diagnostic.get() > 0 + then + vim.diagnostic.open_float(nil, float_opts) + end + + vim.b.diagnostics_pos = cursor_pos + end, + }) + + -- The below command will highlight the current variable and its usages in the buffer. + if client.server_capabilities.documentHighlightProvider then + vim.cmd([[ + hi! link LspReferenceRead Visual + hi! link LspReferenceText Visual + hi! link LspReferenceWrite Visual + augroup lsp_document_highlight + autocmd! * <buffer> + autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() + augroup END + ]]) + end + + if vim.g.logging_level == "debug" then + local msg = string.format("Language server %s started!", client.name) + vim.notify(msg, vim.log.levels.DEBUG, { title = "Server?" }) + end +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) +capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.offsetEncoding = { "utf-16" } + +local lspconfig = require("lspconfig") + +if utils.executable("pylsp") then + lspconfig.pylsp.setup({ + settings = { + pylsp = { + plugins = { + pylint = { enabled = true, executable = "pylint" }, + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + jedi_completion = { fuzzy = true }, + pyls_isort = { enabled = true }, + pylsp_mypy = { enabled = true }, + }, + }, + }, + flags = { + debounce_text_changes = 200, + }, + capabilities = capabilities, + }) +else + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Server?" }) +end + +-- if utils.executable('pyright') then +-- lspconfig.pyright.setup{ +-- on_attach = custom_attach, +-- capabilities = capabilities +-- } +-- else +-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Server?'}) +-- end + +if utils.executable("clangd") then + lspconfig.clangd.setup({ + on_attach = custom_attach, + capabilities = capabilities, + filetypes = { "c", "cpp", "cc" }, + flags = { + debounce_text_changes = 500, + }, + }) +else + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Server?" }) +end + +-- set up vim-language-server +if utils.executable("vim-language-server") then + lspconfig.vimls.setup({ + on_attach = custom_attach, + flags = { + debounce_text_changes = 500, + }, + capabilities = capabilities, + }) +else + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Server?" }) +end + +-- set up bash-language-server +if utils.executable("bash-language-server") then + lspconfig.bashls.setup({ + on_attach = custom_attach, + capabilities = capabilities, + }) +end + +if utils.executable("lua-language-server") then + lspconfig.sumneko_lua.setup({ + on_attach = custom_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files, + library = { + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), + }, + maxPreload = 2000, + preloadFileSize = 50000, + }, + }, + }, + capabilities = capabilities, + }) +end + + +if utils.executable("rust-language-server") then +require("lspconfig").rust_analyzer.setup{ + cmd = { "rustup", "run", "nightly", "rust-analyzer" }, + on_attach = custom_attach, + flags = { + debounce_text_changes = 500, + }, + --[[ + settings = { + rust = { + unstable_features = true, + build_on_save = false, + all_features = true, + }, + } + --]] +} +end + + +-- Setup nvim-cmp. +vim.opt.completeopt = "menu,menuone,noselect" + +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + + +local opts = { + -- whether to highlight the currently hovered symbol + -- disable if your cpu usage is higher than you want it + -- or you just hate the highlight + -- default: true + highlight_hovered_item = true, + + -- whether to show outline guides + -- default: true + show_guides = true, +} +require("symbols-outline").setup(opts) + +local snippets_paths = function() + local plugins = { "friendly-snippets" } + local paths = {} + local path + local root_path = vim.env.HOME .. "/.vim/plugged/" + for _, plug in ipairs(plugins) do + path = root_path .. plug + if vim.fn.isdirectory(path) ~= 0 then + table.insert(paths, path) + end + end + return paths +end + +require("luasnip.loaders.from_vscode").lazy_load({ + paths = snippets_paths(), + include = nil, -- Load all languages + exclude = {}, +}) + +local lspkind = require("lspkind") + +--local kind_icons = { +-- Text = "", +-- Method = "", +-- Function = "", +-- Constructor = "⚙️", +-- Field = "", +-- Variable = "", +-- Class = "ﴯ", +-- Interface = "", +-- Module = "", +-- Property = "ﰠ", +-- Unit = "", +-- Value = "", +-- Enum = "", +-- Keyword = "", +-- Snippet = "", +-- Color = "", +-- File = "", +-- Reference = "", +-- Folder = "", +-- EnumMember = "", +-- Constant = "", +-- Struct = "", +-- Event = "", +-- Operator = "", +-- TypeParameter = "", +--} + +cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ +-- ["<CR>"] = cmp.mapping.confirm({ +-- behavior = cmp.ConfirmBehavior.Replace, +-- select = true, +-- }), + ['<C-y>'] = cmp.mapping.confirm({ select = true }), + ["<C-e>"] = cmp.mapping.close(), + ["<C-u>"] = cmp.mapping.scroll_docs(-4), + ["<C-d>"] = cmp.mapping.scroll_docs(4), + ["<C-Space>"] = cmp.mapping.complete(), + }), + + formatting = { + fields = { "abbr", "kind", "menu" }, + format = function(entry, vim_item) + -- Kind icons + --vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + vim_item.kind = lspkind.presets.default[vim_item.kind] + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "LSP", + luasnip = "Snip", + buffer = "Buf", + path = "Path", + cmdline = "Cmd", + })[entry.source.name] + return vim_item + end, + }, + sources = cmp.config.sources({ + { name = "path" }, + { name = "nvim_lsp", keyword_length = 3 }, + { name = "luasnip", keyword_length = 4 }, + { name = "buffer", keyword_length = 3 }, + --{ name = 'treesitter' }, + { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, + --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this + --{name = 'luasnip', keyword_length = 2}, + }), + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + --documentation = { + -- border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + --}, + }, + experimental = { + ghost_text = true, + native_menu = true, + --native_menu = false, + --view = { + -- entries = "native" + --}, + }, +}) + +cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) + +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), +}) + + + +-- Global config for diagnostic +vim.diagnostic.config({ + underline = false, + virtual_text = true, + signs = true, + severity_sort = true, + float = { + focusable = true, -- + style = "minimal", -- + --border = "rounded", + border = "shadow", + source = "always", + header = "", + prefix = "", + }, +}) + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = false, + virtual_text = false, + signs = true, + update_in_insert = false, +}) +--vim.lsp.buf.definition +--vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) + +vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) + +vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) + +--local signs = { Error = " ", Warn = " ", Info = " ", Hint = " " } +--local signs = { Error = "✘", Warn = "▲", Info = "🛈 ", Hint = "⚑" } +local signs = { Error = "✘", Warn = "▲", Info = "", Hint = "⚑" } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 3570a98..bf9f771 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -8,11 +8,6 @@ local custom_attach = function(client, bufnr) -- Enable completion triggered by <c-x><c-o> vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -local status, saga = pcall(require, "lspsaga") -if not status then - return -end - -- Mappings. local map = function(mode, l, r, opts) opts = opts or {} @@ -211,24 +206,28 @@ if utils.executable("lua-language-server") then }) end ---lspconfig.sumneko_lua.setup({ --- single_file_support = true, --- on_attach = function(client, bufnr) --- print('hello') --- lspconfig.util.default_config.on_attach(client, bufnr) --- end ---}) -require('lspconfig')['rust_analyzer'].setup{ + +if utils.executable("rust-language-server") then +require("lspconfig").rust_analyzer.setup{ + cmd = { "rustup", "run", "nightly", "rust-analyzer" }, on_attach = custom_attach, flags = { debounce_text_changes = 500, }, - - -- Server-specific settings... + --[[ settings = { - ["rust-analyzer"] = {} + rust = { + unstable_features = true, + build_on_save = false, + all_features = true, + }, } + --]] } +end + + + -- Global config for diagnostic vim.diagnostic.config({ underline = false, diff --git a/lua/plugins/lspOld.lsp b/lua/plugins/lspOld.lsp new file mode 100644 index 0000000..206ea57 --- /dev/null +++ b/lua/plugins/lspOld.lsp @@ -0,0 +1,531 @@ +-- lspconfig + nvim-cmp + lspsaga +-- Dependencies +-- nvim-lspconfig +-- nvim-cmp +-- cmp-buffer +-- cmp-path +-- cmp_luasnip +-- cmp-nvim-lsp +-- LuaSnip +-- friendly-snippets +local fn = vim.fn +local api = vim.api +local keymap = vim.keymap +local lsp = vim.lsp + +local utils = require("utils") + +local custom_attach = function(client, bufnr) + -- Mappings. + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.buffer = bufnr + keymap.set(mode, l, r, opts) + end + + +local lsp_defaults = { + flags = { + debounce_text_changes = 150, -- Amount of miliseconds neovim will wait to send the next document update notification. + }, + + -- The data on this option is send to the server, to announce what features the editor can support. + capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()), + on_attach = function(client, bufnr) + vim.api.nvim_exec_autocmds("User", { pattern = "LspAttached" }) + end, +} + +local lspconfig = require('lspconfig') + +lspconfig.util.default_config = vim.tbl_deep_extend( + 'force', + lspconfig.util.default_config, + lsp_defaults +) + +--- +-- LSP Servers +--- + +if utils.executable("pylsp") then + lspconfig.pylsp.setup { + on_attach = custom_attach, + settings = { + pylsp = { + plugins = { + pylint = { enabled = true, executable = "pylint" }, + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + jedi_completion = { fuzzy = true }, + pyls_isort = { enabled = true }, + pylsp_mypy = { enabled = true }, + }, + }, + }, + flags = { + debounce_text_changes = 200, + }, + capabilities = capabilities, + } +else + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) +end + +-- if utils.executable('pyright') then +-- lspconfig.pyright.setup{ +-- on_attach = custom_attach, +-- capabilities = capabilities +-- } +-- else +-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) +-- end + +if utils.executable("clangd") then + lspconfig.clangd.setup { + on_attach = custom_attach, + capabilities = capabilities, + filetypes = { "c", "cpp", "cc" }, + flags = { + debounce_text_changes = 500, + }, + } +else + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" }) +end + +-- set up vim-language-server +if utils.executable("vim-language-server") then + lspconfig.vimls.setup { + on_attach = custom_attach, + flags = { + debounce_text_changes = 500, + }, + capabilities = capabilities, + } +else + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) +end + +-- set up bash-language-server +if utils.executable("bash-language-server") then + lspconfig.bashls.setup { + on_attach = custom_attach, + capabilities = capabilities, + } +end + +if utils.executable("lua-language-server") then + -- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings . + lspconfig.sumneko_lua.setup { + on_attach = custom_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files, + -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace . + -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua . + library = { + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), + }, + maxPreload = 2000, + preloadFileSize = 50000, + }, + }, + }, + capabilities = capabilities, + } +end +-- Lua +lspconfig.sumneko_lua.setup({ + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + single_file_support = true, + on_attach = function(client, bufnr) + print('hello') + lspconfig.util.default_config.on_attach(client, bufnr) + end +}) + +lspconfig.sumneko_lua.setup({ +on_attach = custom_attach, +settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, +}, +}) + + lspconfig.sumneko_lua.setup { + on_attach = custom_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files, + -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace . + -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua . + library = { + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), + }, + maxPreload = 2000, + preloadFileSize = 50000, + }, + }, + }, + capabilities = capabilities, + } + +require'lspconfig'.sumneko_lua.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} + + + +require'lspconfig'.sumneko_lua.setup{} + + +**Default values:** + - `cmd` : + { "lua-language-server" } + - `filetypes` : + - `log_level` : + ```lua + 2 + ``` + - `root_dir` : + ```lua + root_pattern(".luarc.json", ".luacheckrc", ".stylua.toml", "stylua.toml", "selene.toml", ".git") + ``` + - `settings` : + ```lua + { + Lua = { + telemetry = { + enable = false + } + } + } + - `single_file_support` : + true + + + + + + + + + + + + + + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.ccls.setup{} +``` + + +**Default values:** + - `cmd` : + ```lua + { "ccls" } + ``` + - `filetypes` : + ```lua + { "c", "cpp", "objc", "objcpp" } + ``` + - `offset_encoding` : + ```lua + "utf-32" + ``` + - `root_dir` : + ```lua + root_pattern('compile_commands.json', '.ccls', '.git') + ``` + - `single_file_support` : + ```lua + false + ``` + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.clangd.setup{} +``` +**Commands:** +- ClangdSwitchSourceHeader: Switch between source/header + +**Default values:** + - `capabilities` : + ```lua + default capabilities, with offsetEncoding utf-8 + ``` + - `cmd` : + ```lua + { "clangd" } + ``` + - `filetypes` : + ```lua + { "c", "cpp", "objc", "objcpp", "cuda", "proto" } + ``` + - `root_dir` : + ```lua + root_pattern( + '.clangd', + '.clang-tidy', + '.clang-format', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac', + '.git' + ) + + ``` + - `single_file_support` : + ```lua + true + ``` + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.pyright.setup{} +``` +**Commands:** +- PyrightOrganizeImports: Organize Imports + +**Default values:** + - `cmd` : + ```lua + { "pyright-langserver", "--stdio" } + ``` + - `filetypes` : + ```lua + { "python" } + ``` + - `root_dir` : + ```lua + see source file + ``` + - `settings` : + ```lua + { + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "workspace", + useLibraryCodeForTypes = true + } + } + } + ``` + - `single_file_support` : + ```lua + true + ``` + +## rls + +https://github.com/rust-lang/rls + +rls, a language server for Rust + +See https://github.com/rust-lang/rls#setup to setup rls itself. +See https://github.com/rust-lang/rls#configuration for rls-specific settings. +All settings listed on the rls configuration section of the readme +must be set under settings.rust as follows: + +```lua +nvim_lsp.rls.setup { + settings = { + rust = { + unstable_features = true, + build_on_save = false, + all_features = true, + }, + }, +} +``` + +If you want to use rls for a particular build, eg nightly, set cmd as follows: + +```lua +cmd = {"rustup", "run", "nightly", "rls"} +``` + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.rls.setup{} +``` + + +**Default values:** + - `cmd` : + ```lua + { "rls" } + ``` + - `filetypes` : + ```lua + { "rust" } + ``` + - `root_dir` : + ```lua + root_pattern("Cargo.toml") + ``` + + +## rust_analyzer + +https://github.com/rust-analyzer/rust-analyzer + +rust-analyzer (aka rls 2.0), a language server for Rust + +See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings. + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.rust_analyzer.setup{} +``` +**Commands:** +- CargoReload: Reload current cargo workspace + +**Default values:** + - `cmd` : + ```lua + { "rust-analyzer" } + ``` + - `filetypes` : + ```lua + { "rust" } + ``` + - `root_dir` : + ```lua + root_pattern("Cargo.toml", "rust-project.json") + ``` + - `settings` : + ```lua + { + ["rust-analyzer"] = {} + } + ``` + +## rust_analyzer + +https://github.com/rust-analyzer/rust-analyzer + +rust-analyzer (aka rls 2.0), a language server for Rust + +See [docs](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#settings) for extra settings. + + + +**Snippet to enable the language server:** +```lua +require'lspconfig'.rust_analyzer.setup{} +``` +**Commands:** +- CargoReload: Reload current cargo workspace + +**Default values:** + - `cmd` : + ```lua + { "rust-analyzer" } + ``` + - `filetypes` : + ```lua + { "rust" } + ``` + - `root_dir` : + ```lua + root_pattern("Cargo.toml", "rust-project.json") + ``` + - `settings` : + ```lua + { + ["rust-analyzer"] = {} + } + ``` + + diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..a130dcd --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,148 @@ +--vim.lsp.set_log_level("debug") + +local status, nvim_lsp = pcall(require, "lspconfig") +if not status then + return +end + +local protocol = require("vim.lsp.protocol") + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + local function buf_set_option(...) + vim.api.nvim_buf_set_option(bufnr, ...) + end + + --Enable completion triggered by <c-x><c-o> + buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + + -- Mappings. + local opts = { noremap = true, silent = true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- most of the lsp server don't implement textDocument/Declaration, so gD is useless for now. + --buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) + buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) + --buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) + + -- add rust specific keymappings + if client.name == "rust_analyzer" then + buf_set_keymap("n", "<leader>rr", "<cmd>RustRunnables<CR>", opts) + buf_set_keymap("n", "<leader>ra", "<cmd>RustHoverAction<CR>", opts) + end + + -- formatting + if client.server_capabilities.documentFormattingProvider then + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("Format", { clear = true }), + buffer = bufnr, + callback = function() + vim.lsp.buf.format() + end, + }) + end +end + +protocol.CompletionItemKind = { + -- "", -- Text + -- "", -- Method + -- "", -- Function + -- "", -- Constructor + -- "", -- Field + -- "", -- Variable + -- "", -- Class + -- "ﰮ", -- Interface + -- "", -- Module + -- "", -- Property + -- "", -- Unit + -- "", -- Value + -- "", -- Enum + -- "", -- Keyword + -- "", -- Snippet + -- "", -- Color + -- "", -- File + -- "", -- Reference + -- "", -- Folder + -- "", -- EnumMember + -- "", -- Constant + -- "", -- Struct + -- "", -- Event + -- "ﬦ", -- Operator + -- "", -- TypeParameter + File = { icon = "", hl = "TSURI" }, + Module = { icon = "", hl = "TSNamespace" }, + Namespace = { icon = "", hl = "TSNamespace" }, + Package = { icon = "", hl = "TSNamespace" }, + Class = { icon = "ﴯ", hl = "TSType" }, + Method = { icon = "", hl = "TSMethod" }, + Property = { icon = "", hl = "TSMethod" }, + Field = { icon = "", hl = "TSField" }, + Constructor = { icon = "", hl = "TSConstructor" }, + Enum = { icon = "", hl = "TSType" }, + Interface = { icon = "", hl = "TSType" }, + Function = { icon = "", hl = "TSFunction" }, + Variable = { icon = "", hl = "TSConstant" }, + Constant = { icon = "", hl = "TSConstant" }, + String = { icon = "ﮜ", hl = "TSString" }, + Number = { icon = "", hl = "TSNumber" }, + Boolean = { icon = "ﮒ", hl = "TSBoolean" }, + Array = { icon = "", hl = "TSConstant" }, + Object = { icon = "⦿", hl = "TSType" }, + Key = { icon = "", hl = "TSType" }, + Null = { icon = "ﳠ", hl = "TSType" }, + EnumMember = { icon = "", hl = "TSField" }, + Struct = { icon = "ﴯ", hl = "TSType" }, + Event = { icon = "🗲", hl = "TSType" }, + Operator = { icon = "+", hl = "TSOperator" }, + TypeParameter = { icon = "𝙏", hl = "TSParameter" }, +} + +-- Set up completion using nvim_cmp with LSP source +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +nvim_lsp.flow.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +nvim_lsp.sumneko_lua.setup({ + on_attach = on_attach, + settings = { + Lua = { + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + }, + }, +}) + +-- Diagnostic symbols in the sign column (gutter) +--local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +--local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end +-- +vim.diagnostic.config({ + virtual_text = { + prefix = "●", + }, + update_in_insert = true, + float = { + source = "always", -- Or "if_many" + }, +}) diff --git a/lua/plugins/lspsaga-22.10.13-22:51-bak.lua b/lua/plugins/lspsaga-22.10.13-22:51-bak.lua new file mode 100644 index 0000000..ceb1099 --- /dev/null +++ b/lua/plugins/lspsaga-22.10.13-22:51-bak.lua @@ -0,0 +1,61 @@ +local status, saga = pcall(require, "lspsaga") +if not status then + return +end + +saga.init_lsp_saga({ + -- when cursor in saga window you config these to move + move_in_saga = { prev = "k", next = "j" }, + diagnostic_header = { " ", " ", " ", " " }, + scroll_in_preview = { + scroll_down = "<C-d>", + scroll_up = "<C-u>", + }, + code_action_icon = "ﯦ ", + -- Same as nvim-lightbulb but async + code_action_lightbulb = { + sign = false, + virtual_text = true, + }, + finder_icons = { + def = " ", + ref = " ", + link = " ", + }, + finder_action_keys = { + open = "<CR>", + "o", + vsplit = "gv", + split = "gs", + tabe = "t", + quit = "gq", + scroll_down = "<C-f>", + scroll_up = "<C-b>", + }, + + -- Show symbols in winbar must be neovim 0.8.0, + -- Close it until neovim 0.8.0 become stable + symbol_in_winbar = { + in_custom = false, + --enable = enable_winbar, + separator = " ", + show_file = true, + click_support = false, + }, +}) + + -- Mappings. +local map = vim.api.nvim_set_keymap +local opts = { noremap = true, silent = true } + +map("n", "gd", "<Cmd>Lspsaga lsp_finder<CR>", opts) -- Press "o" to open the reference location +map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>", opts) +map("n", "K", "<Cmd>Lspsaga hover_doc<CR>", opts) +map("n", "gk", "<Cmd>Lspsaga diagnostic_jump_prev<CR>", opts) +map("n", "gj", "<Cmd>Lspsaga diagnostic_jump_next<CR>", opts) +map("n", "gs", "<Cmd>Lspsaga signature_help<CR>", opts) -- Default is <C-k> +map("n", "go", "<Cmd>Lspsaga show_line_diagnostics<CR>", opts) +map("n", "gr", "<Cmd>Lspsaga rename<CR>", opts) +map("n", "ga", "<Cmd>Lspsaga code_action<CR>", opts) +map("n", "[d", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) +map("n", "]d", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) diff --git a/lua/plugins/lspsaga.lua b/lua/plugins/lspsaga.lua index 1d03666..aeff464 100644 --- a/lua/plugins/lspsaga.lua +++ b/lua/plugins/lspsaga.lua @@ -1,10 +1,8 @@ require "lspsaga".init_lsp_saga { + -- "single" | "double" | "rounded" | "bold" | "plus" + border_style = "rounded", --border_style = "single", - saga_winblend = 20, - -- float_term = { - -- winblend = 25, - -- shadow_background = false, - -- }, + saga_winblend = 30, move_in_saga = { next = '<C-n>', prev = '<C-p>' }, --move_in_saga = { prev = "k", next = "j" }, scroll_in_preview = { @@ -42,7 +40,7 @@ require "lspsaga".init_lsp_saga { -- definition_preview_quit = '<ESC>', -- finder_preview_hl_ns = 8, finder_action_keys = { - open = "o", + open = { 'o', '<CR>' }, vsplit = "v", split = "s", tabe = "t", @@ -52,32 +50,33 @@ require "lspsaga".init_lsp_saga { }, code_action_keys = { quit = "<ESC>", - exec = "l", + exec = "<CR>", }, rename_action_quit = "<ESC>", rename_in_select = true, symbol_in_winbar = { enable = true, - in_custom = false, - --in_custom = true, + --in_custom = false, + in_custom = true, separator = ' ', --show_file = false, show_file = true, click_support = false, + --click_support = false, }, - show_outline = { - win_position = 'right', - --set special filetype win that outline window split.like NvimTree neotree - -- defx, db_ui - min_with = '', - win_width = 40, - auto_enter = false, - auto_preview = true, - virt_text = 'x', - jump_key = 'l', - -- auto refresh when change buffer - auto_refresh = true, - }, + --show_outline = { + -- win_position = 'right', + -- --set special filetype win that outline window split.like NvimTree neotree + -- -- defx, db_ui + -- min_with = '', + -- win_width = 40, + -- auto_enter = false, + -- auto_preview = true, + -- virt_text = 'x', + -- jump_key = 'l', + -- -- auto refresh when change buffer + -- auto_refresh = true, + --}, custom_kind = { File = { " " }, Module = { " " }, @@ -133,107 +132,8 @@ map("n", "[d", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) map("n", "]d", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) map("t", "<ESC>", "<CMD>Lspsaga close_floaterm<CR>", opts) - - - --- vim.keymap.set("n", "<C-f>", function() require "lspsaga.action".smart_scroll_with_saga(1) end, opts) --- vim.keymap.set("n", "<C-b>", function() require "lspsaga.action".smart_scroll_with_saga(-1) end, opts) - - - -vim.api.nvim_set_hl(0, "LspSagaHoverBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaTermBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspFloatWinBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaAutoPrew", { bg = "NONE", fg = "#BBE73D", }) -vim.api.nvim_set_hl(0, "LspSagaAutoPreview", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaBorderTitle", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaCodeActionBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaCodeActionContent", { bg = "NONE", fg = "#000000", }) -vim.api.nvim_set_hl(0, "LspSagaCodeActionTitle", { bg = "NONE", fg = "#000000", }) -vim.api.nvim_set_hl(0, "LspSagaCodeActionTrunCateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "DefinitionBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "DefinitionArror", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "DefinitionSearch", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "DefinitionFile", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticSource", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticQuickFix", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticMap", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticLineCol", { bg = "NONE", fg = "#929292", }) - -vim.api.nvim_set_hl(0, "LspSagaDiagnosticBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticHeader", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticError", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticWarn", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticInfo", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticHint", { bg = "NONE", fg = "#929292", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticSource", { bg = "NONE", fg = "#C53B82", }) -vim.api.nvim_set_hl(0, "LspSagaDiagnosticTruncateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaErrorTrunCateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaFinderSelection", { bg = "NONE", fg = "#888888", }) -vim.api.nvim_set_hl(0, "LspSagaHintTrunCateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaHoverTrunCateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaInfoTrunCateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaLightBulb", { bg = "NONE", fg = "#BBE73D", }) -vim.api.nvim_set_hl(0, "LspSagaLspFinderBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaRenameBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaRenameMatch", { bg = "NONE", fg = "#C53B82", }) -vim.api.nvim_set_hl(0, "LspSagaShTrunCateLine", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaSignatureHelpBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "LspSagaTrunCatgeLine", { bg = "NONE", fg = "#353535", }) - -vim.api.nvim_set_hl(0, "TargetFileName", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "FinderParam", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "FinderVirtText", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "DefinitionsIcon", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "Definitions", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "ReferencesIcon", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "References", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "DefinitionCount", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "ReferencesCount", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "FinderPreviewSearch", { bg = "NONE", fg = "#888888", }) -vim.api.nvim_set_hl(0, "FinderSpinnerBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "FinderSpinnerTitle", { bg = "NONE", fg = "#C53B82", }) -vim.api.nvim_set_hl(0, "FinderSpinner", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "DefinitionPreviewTitle", { bg = "NONE", fg = "#666666", }) -vim.api.nvim_set_hl(0, "SagaShadow", { bg = "NONE", fg = "#000000", }) --- ----- Outline -vim.api.nvim_set_hl(0, "LSOutlinePreviewBorder", { bg = "NONE", fg = "#353535", }) -vim.api.nvim_set_hl(0, "OutlineIndentEvn", { bg = "NONE", fg = "#ffffff", }) -vim.api.nvim_set_hl(0, "OutlineIndentOdd", { bg = "NONE", fg = "#ffffff", }) -vim.api.nvim_set_hl(0, "OutlineFoldPrefix", { bg = "NONE", fg = "#000000", }) -vim.api.nvim_set_hl(0, "OutlineDetail", { bg = "NONE", fg = "#383838", }) --- -vim.api.nvim_set_hl(0, "LSOutLineFile", { bg = "NONE", fg = "#AF87D7" }) -vim.api.nvim_set_hl(0, "LSOutLineModule", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineNamespace", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLinePackage", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineClass", { bg = "NONE", fg = "#BBE73D", bold = true, italic = true }) -vim.api.nvim_set_hl(0, "LSOutLineMethod", { bg = "NONE", fg = "#C53B82", italic = true }) -vim.api.nvim_set_hl(0, "LSOutLineProperty", { bg = "NONE", fg = "#6A5A9D" }) -vim.api.nvim_set_hl(0, "LSOutLineField", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineConstructor", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineEnum", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineInterface", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineFunction", { bg = "NONE", fg = "#C53B82", bold = true, italic = true }) -vim.api.nvim_set_hl(0, "LSOutLineVariable", { bg = "NONE", fg = "#696969" }) -vim.api.nvim_set_hl(0, "LSOutLineConstant", { bg = "NONE", fg = "#C53B82" }) -vim.api.nvim_set_hl(0, "LSOutLineString", { bg = "NONE", fg = "#444444" }) -vim.api.nvim_set_hl(0, "LSOutLineNumber", { bg = "NONE", fg = "#AFC460" }) -vim.api.nvim_set_hl(0, "LSOutLineBoolean", { bg = "NONE", fg = "#C53B82" }) -vim.api.nvim_set_hl(0, "LSOutLineArray", { bg = "NONE", fg = "#614F97" }) -vim.api.nvim_set_hl(0, "LSOutLineObject", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineKey", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineNull", { bg = "NONE", fg = "#C53B82" }) -vim.api.nvim_set_hl(0, "LSOutLineEnummember", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineStruct", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineEvent", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineOperator", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineTypeparameter", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineTypealias", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineParameter", { bg = "NONE", fg = "#8567A3" }) -vim.api.nvim_set_hl(0, "LSOutLineStaticmethod", { bg = "NONE", fg = "#666666" }) -vim.api.nvim_set_hl(0, "LSOutLineMacro", { bg = "NONE", fg = "#666666" }) +--vim.api.nvim_command("highlight LspFloatWinNormal guibg=none ") +--hi LspFloatWinNormal guibg=none -- vim.api.nvim_create_autocmd("BufEnter", { diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua index f362659..74030cb 100644 --- a/lua/plugins/nvim-tree.lua +++ b/lua/plugins/nvim-tree.lua @@ -56,7 +56,7 @@ nvim_tree.setup({ view = { width = 30, --height = 30, - side = "right", + side = "left", mappings = { list = { { key = { "l", "<CR>", "o" }, cb = tree_cb("edit") }, diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 261e262..b081ca3 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -11,26 +11,21 @@ treesitter.setup { disable = {}, --disable = { "python", "css" } }, - --ensure_installed = { - -- "c", - -- "zsh", - -- "lua" - -- --"rust", - -- --"php", - -- --"json", - -- --"yaml", - -- --"swift", - -- --"css", - -- --"html", - -- --"toml", - -- --"tsx", - --}, - ensure_installed = "all", -- one of "all" or a list of languages + ensure_installed = { + "c", + "bash", + "lua", + "rust", + }, + --ensure_installed = "all", -- one of "all" or a list of languages --ignore_install = { "" }, -- List of parsers to ignore installing - autotag = { enable = true, }, + efactor = { + highlight_definitions = { enable = true }, + highlight_current_scope = { enable = true } + } } --vim.opt.foldmethod = "expr" --vim.opt.foldexpr = "nvim_treesitter#foldexpr()" diff --git a/lua/scripts/lsp-ext.lua b/lua/scripts/lsp-ext.lua new file mode 100644 index 0000000..c4378c6 --- /dev/null +++ b/lua/scripts/lsp-ext.lua @@ -0,0 +1,48 @@ +-- +-- lsp-ext.lua + + +M = {} + +function M.preview_location(location, context, before_context) + -- location may be LocationLink or Location (more useful for the former) + context = context or 15 + before_context = before_context or 0 + local uri = location.targetUri or location.uri + if uri == nil then + return + end + local bufnr = vim.uri_to_bufnr(uri) + if not vim.api.nvim_buf_is_loaded(bufnr) then + vim.fn.bufload(bufnr) + end + local range = location.targetRange or location.range + local contents = + vim.api.nvim_buf_get_lines(bufnr, range.start.line - before_context, range["end"].line + 1 + context, false) + local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") + return vim.lsp.util.open_floating_preview(contents, filetype) +end + +function M.preview_location_callback(_, method, result) + local context = 15 + if result == nil or vim.tbl_isempty(result) then + print("No location found: " .. method) + return nil + end + if vim.tbl_islist(result) then + M.floating_buf, M.floating_win = M.preview_location(result[1], context) + else + M.floating_buf, M.floating_win = M.preview_location(result, context) + end +end + +function M.peek_definition() + if vim.tbl_contains(vim.api.nvim_list_wins(), M.floating_win) then + vim.api.nvim_set_current_win(M.floating_win) + else + local params = vim.lsp.util.make_position_params() + return vim.lsp.buf_request(0, "textDocument/definition", params, M.preview_location_callback) + end +end + +return M diff --git a/lua/scripts/toggleLsp.lua b/lua/scripts/toggleLsp.lua new file mode 100644 index 0000000..28af698 --- /dev/null +++ b/lua/scripts/toggleLsp.lua @@ -0,0 +1,40 @@ +local M = {} + +local check_function = function(bufnr, _) + local ok, result = pcall(vim.api.nvim_buf_get_var, bufnr, 'lsp_enabled') + -- No buffer local variable set, so just enable by default + if not ok then + return true + end + + return result +end + +vim.lsp.handlers["textDocument/publishDiagnostics"] = + vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = check_function, + virtual_text = check_function, + signs = check_function + }) + +function M.Enable() + vim.b.lsp_enabled = true +end + +function M.Disable() + vim.b.lsp_enabled = false +end + +function M.Toggle() + if vim.b.lsp_enabled == false then + M.Enable() + else + M.Disable() + end +end + +vim.cmd [[ + command! -nargs=* ToggleLsp lua require'lsp.toggle'.Toggle() +]] + +return M |
