diff options
author | kylo252 <[email protected]> | 2021-10-09 22:17:30 +0200 |
---|---|---|
committer | kylo252 <[email protected]> | 2021-10-09 22:17:30 +0200 |
commit | caf62bcfed4fc6cfed26164e39d22a568d21f9d0 (patch) | |
tree | 47f7ddcbe7ef10b6cffd8398dbfc215d94fc2fae /lua/core | |
parent | 4126e5765d69840660fab2a05bbc664ad0117b95 (diff) | |
parent | 82b7a35858479223c1e34bea2f64451ecf1e5f66 (diff) |
Merge remote-tracking branch 'origin/rolling'
Diffstat (limited to 'lua/core')
-rw-r--r-- | lua/core/autocmds.lua | 5 | ||||
-rw-r--r-- | lua/core/autopairs.lua | 62 | ||||
-rw-r--r-- | lua/core/builtins/init.lua | 3 | ||||
-rw-r--r-- | lua/core/cmp.lua | 260 | ||||
-rw-r--r-- | lua/core/commands.lua | 4 | ||||
-rw-r--r-- | lua/core/compe.lua | 133 | ||||
-rw-r--r-- | lua/core/dap.lua | 15 | ||||
-rw-r--r-- | lua/core/dashboard.lua | 27 | ||||
-rw-r--r-- | lua/core/gitsigns.lua | 2 | ||||
-rw-r--r-- | lua/core/info.lua | 91 | ||||
-rw-r--r-- | lua/core/log.lua | 1 | ||||
-rw-r--r-- | lua/core/lspinstall.lua | 19 | ||||
-rw-r--r-- | lua/core/lualine/components.lua | 56 | ||||
-rw-r--r-- | lua/core/lualine/styles.lua | 12 | ||||
-rw-r--r-- | lua/core/nvimtree.lua | 41 | ||||
-rw-r--r-- | lua/core/project.lua | 2 | ||||
-rw-r--r-- | lua/core/telescope.lua | 81 | ||||
-rw-r--r-- | lua/core/terminal.lua | 31 | ||||
-rw-r--r-- | lua/core/which-key.lua | 51 |
19 files changed, 555 insertions, 341 deletions
diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 041926e5..662afcfa 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -14,6 +14,11 @@ lvim.autocommands = { "nnoremap <silent> <buffer> q :q<CR>", }, { + "FileType", + "lsp-installer", + "nnoremap <silent> <buffer> q :q<CR>", + }, + { "TextYankPost", "*", "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 24aa1875..eb080fb1 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -4,11 +4,13 @@ function M.config() lvim.builtin.autopairs = { active = true, on_config_done = nil, - ---@usage map <CR> on insert mode - map_cr = true, ---@usage auto insert after select function or method item - -- NOTE: This should be wrapped into a function so that it is re-evaluated when opening new files - map_complete = vim.bo.filetype ~= "tex", + map_complete = true, + ---@usage -- modifies the function or method delimiter by filetypes + map_char = { + all = "(", + tex = "{", + }, ---@usage check treesitter check_ts = true, ts_config = { @@ -20,36 +22,46 @@ function M.config() end M.setup = function() - -- skip it, if you use another global object - _G.MUtils = {} local autopairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" + local cond = require "nvim-autopairs.conds" - vim.g.completion_confirm_key = "" - MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](autopairs.esc "<cr>") - else - return autopairs.esc "<cr>" + autopairs.setup { + check_ts = lvim.builtin.autopairs.check_ts, + ts_config = lvim.builtin.autopairs.ts_config, + } + + -- vim.g.completion_confirm_key = "" + + autopairs.add_rule(Rule("$$", "$$", "tex")) + autopairs.add_rules { + Rule("$", "$", { "tex", "latex" }) -- don't add a pair if the next character is % + :with_pair(cond.not_after_regex_check "%%") -- don't add a pair if the previous character is xxx + :with_pair(cond.not_before_regex_check("xxx", 3)) -- don't move right when repeat character + :with_move(cond.none()) -- don't delete if the next character is xx + :with_del(cond.not_after_regex_check "xx") -- disable add newline when press <cr> + :with_cr(cond.none()), + } + autopairs.add_rules { + Rule("$$", "$$", "tex"):with_pair(function(opts) + print(vim.inspect(opts)) + if opts.line == "aa $$" then + -- don't add pair on that line + return false end - else - return autopairs.autopairs_cr() - end - end + end), + } - if package.loaded["compe"] then - require("nvim-autopairs.completion.compe").setup { - map_cr = lvim.builtin.autopairs.map_cr, + if package.loaded["cmp"] then + require("nvim-autopairs.completion.cmp").setup { + map_cr = false, map_complete = lvim.builtin.autopairs.map_complete, + map_char = lvim.builtin.autopairs.map_char, } + -- we map CR explicitly in cmp.lua but we still need to setup the autopairs CR keymap + vim.api.nvim_set_keymap("i", "<CR>", "v:lua.MPairs.autopairs_cr()", { expr = true, noremap = true }) end - autopairs.setup { - check_ts = lvim.builtin.autopairs.check_ts, - ts_config = lvim.builtin.autopairs.ts_config, - } - require("nvim-treesitter.configs").setup { autopairs = { enable = true } } local ts_conds = require "nvim-autopairs.ts-conds" diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua index 32f96af5..c3b3618f 100644 --- a/lua/core/builtins/init.lua +++ b/lua/core/builtins/init.lua @@ -4,7 +4,7 @@ local builtins = { "keymappings", "core.which-key", "core.gitsigns", - "core.compe", + "core.cmp", "core.dashboard", "core.dap", "core.terminal", @@ -15,7 +15,6 @@ local builtins = { "core.bufferline", "core.autopairs", "core.comment", - "core.lspinstall", "core.lualine", } diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua new file mode 100644 index 00000000..d5d92314 --- /dev/null +++ b/lua/core/cmp.lua @@ -0,0 +1,260 @@ +local M = {} + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +local function T(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false +end + +M.config = function() + local status_cmp_ok, cmp = pcall(require, "cmp") + if not status_cmp_ok then + return + end + local status_luasnip_ok, luasnip = pcall(require, "luasnip") + if not status_luasnip_ok then + return + end + local win_get_cursor = vim.api.nvim_win_get_cursor + local get_current_buf = vim.api.nvim_get_current_buf + + local function inside_snippet() + -- for outdated versions of luasnip + if not luasnip.session.current_nodes then + return false + end + + local node = luasnip.session.current_nodes[get_current_buf()] + if not node then + return false + end + + local snip_begin_pos, snip_end_pos = node.parent.snippet.mark:pos_begin_end() + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 -- LuaSnip is 0-based not 1-based like nvim for rows + return pos[1] >= snip_begin_pos[1] and pos[1] <= snip_end_pos[1] + end + + ---sets the current buffer's luasnip to the one nearest the cursor + ---@return boolean true if a node is found, false otherwise + local function seek_luasnip_cursor_node() + -- for outdated versions of luasnip + if not luasnip.session.current_nodes then + return false + end + + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 + local node = luasnip.session.current_nodes[get_current_buf()] + if not node then + return false + end + + local snippet = node.parent.snippet + local exit_node = snippet.insert_nodes[0] + + -- exit early if we're past the exit node + if exit_node then + local exit_pos_end = exit_node.mark:pos_end() + if (pos[1] > exit_pos_end[1]) or (pos[1] == exit_pos_end[1] and pos[2] > exit_pos_end[2]) then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + node = snippet.inner_first:jump_into(1, true) + while node ~= nil and node.next ~= nil and node ~= snippet do + local n_next = node.next + local next_pos = n_next and n_next.mark:pos_begin() + local candidate = n_next ~= snippet and next_pos and (pos[1] < next_pos[1]) + or (pos[1] == next_pos[1] and pos[2] < next_pos[2]) + + -- Past unmarked exit node, exit early + if n_next == nil or n_next == snippet.next then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + + if candidate then + luasnip.session.current_nodes[get_current_buf()] = node + return true + end + + local ok + ok, node = pcall(node.jump_from, node, 1, true) -- no_move until last stop + if not ok then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + -- No candidate, but have an exit node + if exit_node then + -- to jump to the exit node, seek to snippet + luasnip.session.current_nodes[get_current_buf()] = snippet + return true + end + + -- No exit node, exit from snippet + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + return false + end + + lvim.builtin.cmp = { + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + experimental = { + ghost_text = true, + native_menu = false, + }, + formatting = { + kind_icons = { + Class = " ", + Color = " ", + Constant = "ﲀ ", + Constructor = " ", + Enum = "練", + EnumMember = " ", + Event = " ", + Field = " ", + File = "", + Folder = " ", + Function = " ", + Interface = "ﰮ ", + Keyword = " ", + Method = " ", + Module = " ", + Operator = "", + Property = " ", + Reference = " ", + Snippet = " ", + Struct = " ", + Text = " ", + TypeParameter = " ", + Unit = "塞", + Value = " ", + Variable = " ", + }, + format = function(entry, vim_item) + vim_item.kind = lvim.builtin.cmp.formatting.kind_icons[vim_item.kind] + vim_item.menu = ({ + nvim_lsp = "(LSP)", + emoji = "(Emoji)", + path = "(Path)", + calc = "(Calc)", + cmp_tabnine = "(Tabnine)", + vsnip = "(Snippet)", + luasnip = "(Snippet)", + buffer = "(Buffer)", + })[entry.source.name] + vim_item.dup = ({ + buffer = 1, + path = 1, + nvim_lsp = 0, + })[entry.source.name] or 0 + return vim_item + end, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + sources = { + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "cmp_tabnine" }, + { name = "nvim_lua" }, + { name = "buffer" }, + { name = "calc" }, + { name = "emoji" }, + { name = "treesitter" }, + { name = "crates" }, + }, + mapping = { + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + -- TODO: potentially fix emmet nonsense + ["<Tab>"] = cmp.mapping(function() + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() then + luasnip.jump(1) + elseif check_backspace() then + vim.fn.feedkeys(T "<Tab>", "n") + elseif is_emmet_active() then + return vim.fn["cmp#complete"]() + else + vim.fn.feedkeys(T "<Tab>", "n") + end + end, { + "i", + "s", + }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif inside_snippet() and luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + + ["<C-Space>"] = cmp.mapping.complete(), + ["<C-e>"] = cmp.mapping.close(), + ["<CR>"] = cmp.mapping(function(fallback) + if cmp.visible() and cmp.confirm(lvim.builtin.cmp.confirm_opts) then + return + end + + if inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() then + if not luasnip.jump(1) then + fallback() + end + else + fallback() + end + end), + }, + } +end + +M.setup = function() + require("luasnip/loaders/from_vscode").lazy_load() + require("cmp").setup(lvim.builtin.cmp) +end + +return M diff --git a/lua/core/commands.lua b/lua/core/commands.lua index 22170c85..6ceeaaff 100644 --- a/lua/core/commands.lua +++ b/lua/core/commands.lua @@ -11,7 +11,9 @@ M.defaults = { endfunction ]], -- :LvimInfo - [[command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype)]], + [[ command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype) ]], + [[ command! LvimCacheReset lua require('utils.hooks').reset_cache() ]], + [[ command! LvimUpdate lua require('bootstrap').update() ]], } M.load = function(commands) diff --git a/lua/core/compe.lua b/lua/core/compe.lua deleted file mode 100644 index 9eb3dcfa..00000000 --- a/lua/core/compe.lua +++ /dev/null @@ -1,133 +0,0 @@ -local M = {} - -M.config = function() - lvim.builtin.compe = { - active = true, - on_config_done = nil, - autocomplete = true, - debug = false, - min_length = 1, - preselect = "enable", - throttle_time = 80, - source_timeout = 200, - incomplete_delay = 400, - max_abbr_width = 100, - max_kind_width = 100, - max_menu_width = 100, - documentation = { - border = "single", - winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", - max_width = 120, - min_width = 60, - max_height = math.floor(vim.o.lines * 0.3), - min_height = 1, - }, - -- documentation = true, - - source = { - path = { kind = " (Path)" }, - buffer = { kind = " (Buffer)" }, - calc = { kind = " (Calc)" }, - vsnip = { kind = " (Snippet)" }, - nvim_lsp = { kind = " (LSP)" }, - nvim_lua = false, - spell = { kind = " (Spell)" }, - tags = false, - vim_dadbod_completion = false, - snippets_nvim = false, - ultisnips = false, - treesitter = false, - emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } }, - -- for emoji press : (idk if that in compe tho) - }, - - keymap = { - values = { - insert_mode = { - -- ["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"', { silent = true, noremap = true, expr = true } }, - -- ["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"', { silent = true, noremap = true, expr = true } }, - ["<C-Space>"] = { "compe#complete()", { silent = true, noremap = true, expr = true } }, - ["<C-e>"] = { "compe#close('<C-e>')", { silent = true, noremap = true, expr = true } }, - ["<C-f>"] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } }, - ["<C-d>"] = { "compe#scroll({ 'delta': -4 })", { silent = true, noremap = true, expr = true } }, - }, - }, - opts = { - insert_mode = { noremap = true, silent = true, expr = true }, - }, - }, - } -end - -M.setup = function() - vim.g.vsnip_snippet_dir = lvim.vsnip_dir - - local compe = require "compe" - - compe.setup(lvim.builtin.compe) - - local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) - end - - local check_back_space = function() - local col = vim.fn.col "." - 1 - if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then - return true - else - return false - end - end - - local is_emmet_active = function() - local clients = vim.lsp.buf_get_clients() - - for _, client in pairs(clients) do - if client.name == "emmet_ls" then - return true - end - end - return false - end - - -- Use (s-)tab to: - --- move to prev/next item in completion menuone - --- jump to prev/next snippet's placeholder - _G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "<C-n>" - elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then - return t "<Plug>(vsnip-jump-next)" - elseif check_back_space() then - return t "<Tab>" - elseif is_emmet_active() then - return vim.fn["compe#complete"]() - else - return t "<Tab>" - end - end - - _G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "<C-p>" - elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then - return t "<Plug>(vsnip-jump-prev)" - else - return t "<S-Tab>" - end - end - - local keymap = require "keymappings" - keymap.load(lvim.builtin.compe.keymap.values, lvim.builtin.compe.keymap.opts) - - vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - - if lvim.builtin.compe.on_config_done then - lvim.builtin.compe.on_config_done(compe) - end -end - -return M diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 5de3b7c4..d9b59641 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -10,6 +10,18 @@ M.config = function() linehl = "", numhl = "", }, + breakpoint_rejected = { + text = "", + texthl = "LspDiagnosticsSignHint", + linehl = "", + numhl = "", + }, + stopped = { + text = "", + texthl = "LspDiagnosticsSignInformation", + linehl = "DiagnosticUnderlineInfo", + numhl = "LspDiagnosticsSignInformation", + }, } end @@ -17,6 +29,9 @@ M.setup = function() local dap = require "dap" vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) + vim.fn.sign_define("DapBreakpointRejected", lvim.builtin.dap.breakpoint_rejected) + vim.fn.sign_define("DapStopped", lvim.builtin.dap.stopped) + dap.defaults.fallback.terminal_win_cmd = "50vsplit new" lvim.builtin.which_key.mappings["d"] = { diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index a613921f..505350cb 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,5 +1,5 @@ local M = {} -local home_dir = vim.loop.os_homedir() +local utils = require "utils" M.config = function(config) lvim.builtin.dashboard = { @@ -7,7 +7,7 @@ M.config = function(config) on_config_done = nil, search_handler = "telescope", disable_at_vim_enter = 0, - session_directory = home_dir .. "/.cache/lvim/sessions", + session_directory = utils.join_paths(get_cache_dir(), "sessions"), custom_header = { "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", @@ -69,14 +69,23 @@ M.setup = function() vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory - vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))" + local lvim_site = "lunarvim.org" + local lvim_version = get_version "short" + local num_plugins_loaded = #vim.fn.globpath(get_runtime_dir() .. "/site/pack/packer/start", "*", 0, 1) - vim.api.nvim_exec( - [[ - let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins '] -]], - false - ) + local footer = { + "LunarVim loaded " .. num_plugins_loaded .. " plugins ", + "", + lvim_site, + } + + if lvim_version then + table.insert(footer, 2, "") + table.insert(footer, 3, "v" .. lvim_version) + end + + local text = require "interface.text" + vim.g.dashboard_custom_footer = text.align_center({ width = 0 }, footer, 0.49) -- Use 0.49 as counts for 2 characters require("core.autocmds").define_augroups { _dashboard = { diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index bb9d088b..cc6387dc 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -44,7 +44,7 @@ M.config = function() noremap = true, buffer = true, }, - watch_index = { interval = 1000 }, + watch_gitdir = { interval = 1000 }, sign_priority = 6, update_debounce = 200, status_formatter = nil, -- Use default diff --git a/lua/core/info.lua b/lua/core/info.lua index 67e45d1c..16001d07 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -10,6 +10,8 @@ local M = { } local fmt = string.format +local text = require "interface.text" +local lsp_utils = require "lsp.utils" local function str_list(list) return fmt("[ %s ]", table.concat(list, ", ")) @@ -65,44 +67,54 @@ local function tbl_set_highlight(terms, highlight_group) end end -function M.toggle_popup(ft) - local lsp_utils = require "lsp.utils" - local client = lsp_utils.get_active_client_by_ft(ft) - local is_client_active = false - local client_enabled_caps = {} - local client_name = "" - local client_id = 0 - local document_formatting = false - if client ~= nil then - is_client_active = not client.is_stopped() - client_enabled_caps = require("lsp").get_ls_capabilities(client.id) - client_name = client.name - client_id = client.id - document_formatting = client.resolved_capabilities.document_formatting +local function make_client_info(client) + local client_enabled_caps = lsp_utils.get_client_capabilities(client.id) + local name = client.name + local id = client.id + local document_formatting = client.resolved_capabilities.document_formatting + local client_info = { + fmt("* Name: %s", name), + fmt("* Id: %s", tostring(id)), + fmt("* Supports formatting: %s", tostring(document_formatting)), + } + if not vim.tbl_isempty(client_enabled_caps) then + local caps_text = "* Capabilities list: " + local caps_text_len = caps_text:len() + local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") + enabled_caps = text.shift_right(enabled_caps, caps_text_len) + enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) + vim.list_extend(client_info, enabled_caps) end + return client_info +end + +function M.toggle_popup(ft) + local clients = lsp_utils.get_active_clients_by_ft(ft) + local client_names = {} + local header = { fmt("Detected filetype: %s", ft), fmt("Treesitter active: %s", tostring(next(vim.treesitter.highlighter.active) ~= nil)), } - local text = require "interface.text" local lsp_info = { "Language Server Protocol (LSP) info", - fmt("* Associated server: %s", client_name), - fmt("* Active: %s (id: %d)", tostring(is_client_active), client_id), - fmt("* Supports formatting: %s", tostring(document_formatting)), + fmt "* Associated server(s):", } - if not vim.tbl_isempty(client_enabled_caps) then - local caps_text = "* Capabilities list: " - local caps_text_len = caps_text:len() - local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") - enabled_caps = text.shift_left(enabled_caps, caps_text_len) - enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) - vim.list_extend(lsp_info, enabled_caps) + + for _, client in pairs(clients) do + vim.list_extend(lsp_info, make_client_info(client)) + table.insert(client_names, client.name) end - local null_ls = require "lsp.null-ls" - local registered_providers = null_ls.list_supported_provider_names(ft) + + local null_formatters = require "lsp.null-ls.formatters" + local null_linters = require "lsp.null-ls.linters" + local registered_formatters = null_formatters.list_supported_names(ft) + local registered_linters = null_linters.list_supported_names(ft) + local registered_providers = {} + vim.list_extend(registered_providers, registered_formatters) + vim.list_extend(registered_providers, registered_linters) local registered_count = vim.tbl_count(registered_providers) local null_ls_info = { "Formatters and linters", @@ -113,24 +125,6 @@ function M.toggle_popup(ft) ), } - local null_formatters = require "lsp.null-ls.formatters" - local missing_formatters = null_formatters.list_unsupported_names(ft) - local missing_formatters_status = {} - if not vim.tbl_isempty(missing_formatters) then - missing_formatters_status = { - fmt("* Missing formatters: %s", table.concat(missing_formatters, " , ") .. " "), - } - end - - local null_linters = require "lsp.null-ls.linters" - local missing_linters = null_linters.list_unsupported_names(ft) - local missing_linters_status = {} - if not vim.tbl_isempty(missing_linters) then - missing_linters_status = { - fmt("* Missing linters: %s", table.concat(missing_linters, " , ") .. " "), - } - end - local content_provider = function(popup) local content = {} @@ -143,8 +137,6 @@ function M.toggle_popup(ft) lsp_info, { "" }, null_ls_info, - missing_formatters_status, - missing_linters_status, { "" }, { "" }, get_formatter_suggestion_msg(ft), @@ -155,7 +147,7 @@ function M.toggle_popup(ft) vim.list_extend(content, section) end - return text.align(popup, content, 0.5) + return text.align_left(popup, content, 0.5) end local function set_syntax_hl() @@ -167,11 +159,8 @@ function M.toggle_popup(ft) vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' tbl_set_highlight(registered_providers, "LvimInfoIdentifier") - tbl_set_highlight(missing_formatters, "LvimInfoIdentifier") - tbl_set_highlight(missing_linters, "LvimInfoIdentifier") -- tbl_set_highlight(require("lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier") -- tbl_set_highlight(require("lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier") - vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end local Popup = require("interface.popup"):new { diff --git a/lua/core/log.lua b/lua/core/log.lua index 1eb786ba..fca1fcb4 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -8,6 +8,7 @@ function Log:add_entry(msg, level) if self.__handle then -- plenary uses lower-case log levels self.__handle[level:lower()](msg) + return end local status_ok, plenary = pcall(require, "plenary") if status_ok then diff --git a/lua/core/lspinstall.lua b/lua/core/lspinstall.lua deleted file mode 100644 index 0bb59e0e..00000000 --- a/lua/core/lspinstall.lua +++ /dev/null @@ -1,19 +0,0 @@ -local M = {} - -M.config = function() - lvim.builtin.lspinstall = { - active = true, - on_config_done = nil, - } -end - -M.setup = function() - local lspinstall = require "lspinstall" - lspinstall.setup() - - if lvim.builtin.lspinstall.on_config_done then - lvim.builtin.lspinstall.on_config_done(lspinstall) - end -end - -return M diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 894d9e9b..3ee2fdf8 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -17,31 +17,32 @@ return { function() return " " end, - left_padding = 0, - right_padding = 0, + padding = { left = 0, right = 0 }, color = {}, - condition = nil, + cond = nil, }, branch = { "b:gitsigns_head", icon = " ", color = { gui = "bold" }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, filename = { "filename", color = {}, - condition = nil, + cond = nil, }, diff = { "diff", source = diff_source, symbols = { added = " ", modified = "柳", removed = " " }, - color_added = { fg = colors.green }, - color_modified = { fg = colors.yellow }, - color_removed = { fg = colors.red }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.yellow }, + removed = { fg = colors.red }, + }, color = {}, - condition = nil, + cond = nil, }, python_env = { function() @@ -60,44 +61,46 @@ return { return "" end, color = { fg = colors.green }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, diagnostics = { "diagnostics", sources = { "nvim_lsp" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, color = {}, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, treesitter = { function() - if next(vim.treesitter.highlighter.active) then + local b = vim.api.nvim_get_current_buf() + if next(vim.treesitter.highlighter.active[b]) then return " " end return "" end, color = { fg = colors.green }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, lsp = { function(msg) - msg = msg or "LSP Inactive" + msg = msg or "LS Inactive" local buf_clients = vim.lsp.buf_get_clients() if next(buf_clients) == nil then + -- TODO: clean up this if statement + 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 - local utils = require "lsp.utils" - local active_client = utils.get_active_client_by_ft(buf_ft) for _, client in pairs(buf_clients) do if client.name ~= "null-ls" then table.insert(buf_client_names, client.name) end end - vim.list_extend(buf_client_names, active_client or {}) -- add formatter local formatters = require "lsp.null-ls.formatters" @@ -113,10 +116,10 @@ return { end, icon = " ", color = { gui = "bold" }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, - location = { "location", condition = conditions.hide_in_width, color = {} }, - progress = { "progress", condition = conditions.hide_in_width, color = {} }, + location = { "location", cond = conditions.hide_in_width, color = {} }, + progress = { "progress", cond = conditions.hide_in_width, color = {} }, spaces = { function() local label = "Spaces: " @@ -125,16 +128,16 @@ return { end return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, color = {}, }, encoding = { "o:encoding", - upper = true, + fmt = string.upper, color = {}, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, - filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, + filetype = { "filetype", cond = conditions.hide_in_width, color = {} }, scrollbar = { function() local current_line = vim.fn.line "." @@ -144,9 +147,8 @@ return { local index = math.ceil(line_ratio * #chars) return chars[index] end, - left_padding = 0, - right_padding = 0, + padding = { left = 0, right = 0 }, color = { fg = colors.yellow, bg = colors.bg }, - condition = nil, + cond = nil, }, } diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 3595e5e3..19097424 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -11,8 +11,8 @@ styles.none = { style = "none", options = { icons_enabled = true, - component_separators = "", - section_separators = "", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, disabled_filetypes = {}, }, sections = { @@ -39,8 +39,8 @@ styles.default = { style = "default", options = { icons_enabled = true, - component_separators = { "", "" }, - section_separators = { "", "" }, + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, disabled_filetypes = {}, }, sections = { @@ -67,8 +67,8 @@ styles.lvim = { style = "lvim", options = { icons_enabled = true, - component_separators = "", - section_separators = "", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, disabled_filetypes = { "dashboard", "NvimTree", "Outline" }, }, sections = { diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 6aa5401d..55cc6175 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -5,8 +5,23 @@ function M.config() lvim.builtin.nvimtree = { active = true, on_config_done = nil, - side = "left", - width = 30, + setup = { + open_on_setup = 0, + auto_close = 1, + open_on_tab = 0, + update_focused_file = { + enable = 1, + }, + lsp_diagnostics = 1, + view = { + width = 30, + side = "left", + auto_resize = false, + mappings = { + custom_only = false, + }, + }, + }, show_icons = { git = 1, folders = 1, @@ -15,16 +30,11 @@ function M.config() tree_width = 30, }, ignore = { ".git", "node_modules", ".cache" }, - auto_open = 0, - auto_close = 1, quit_on_open = 0, - follow = 1, hide_dotfiles = 1, git_hl = 1, root_folder_modifier = ":t", - tab_open = 0, allow_resize = 1, - lsp_diagnostics = 1, auto_ignore_ft = { "startify", "dashboard" }, icons = { default = "", @@ -63,17 +73,17 @@ function M.setup() -- Implicitly update nvim-tree when project module is active if lvim.builtin.project.active then - vim.g.nvim_tree_update_cwd = 1 - vim.g.nvim_tree_respect_buf_cwd = 1 - vim.g.nvim_tree_disable_netrw = 0 - vim.g.nvim_tree_hijack_netrw = 0 + lvim.builtin.nvimtree.respect_buf_cwd = 1 + lvim.builtin.nvimtree.setup.update_cwd = 1 + lvim.builtin.nvimtree.setup.disable_netrw = 0 + lvim.builtin.nvimtree.setup.hijack_netrw = 0 vim.g.netrw_banner = 0 end local tree_cb = nvim_tree_config.nvim_tree_callback - if not g.nvim_tree_bindings then - g.nvim_tree_bindings = { + if not lvim.builtin.nvimtree.setup.view.mappings.list then + lvim.builtin.nvimtree.setup.view.mappings.list = { { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, @@ -96,11 +106,12 @@ function M.setup() if lvim.builtin.nvimtree.on_config_done then lvim.builtin.nvimtree.on_config_done(nvim_tree_config) end + require("nvim-tree").setup(lvim.builtin.nvimtree.setup) end function M.on_open() - if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then - require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") + if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.setup.view.side == "left" then + require("bufferline.state").set_offset(lvim.builtin.nvimtree.setup.view.width + 1, "") end end diff --git a/lua/core/project.lua b/lua/core/project.lua index 7fb04933..e7527440 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -35,7 +35,7 @@ function M.config() ---@type string ---@usage path to store the project history for use in telescope - datapath = CACHE_PATH, + datapath = get_cache_dir(), } end diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 4ae56df0..ba0a9ee1 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,5 +1,7 @@ local M = {} +local utils = require "utils" + function M.config() -- Define this minimal config so that it's available if telescope is not yet available. lvim.builtin.telescope = { @@ -24,7 +26,6 @@ function M.config() layout_strategy = "horizontal", layout_config = { width = 0.75, - prompt_position = "bottom", preview_cutoff = 120, horizontal = { mirror = false }, vertical = { mirror = false }, @@ -87,16 +88,11 @@ function M.find_lunarvim_files(opts) opts = opts or {} local themes = require "telescope.themes" local theme_opts = themes.get_ivy { - previewer = false, sorting_strategy = "ascending", layout_strategy = "bottom_pane", - layout_config = { - height = 5, - width = 0.5, - }, - prompt = ">> ", + prompt_prefix = ">> ", prompt_title = "~ LunarVim files ~", - cwd = CONFIG_PATH, + cwd = utils.join_paths(get_runtime_dir(), "lvim"), find_command = { "git", "ls-files" }, } opts = vim.tbl_deep_extend("force", theme_opts, opts) @@ -109,14 +105,79 @@ function M.grep_lunarvim_files(opts) local theme_opts = themes.get_ivy { sorting_strategy = "ascending", layout_strategy = "bottom_pane", - prompt = ">> ", + prompt_prefix = ">> ", prompt_title = "~ search LunarVim ~", - cwd = CONFIG_PATH, + cwd = utils.join_paths(get_runtime_dir(), "lvim"), } opts = vim.tbl_deep_extend("force", theme_opts, opts) require("telescope.builtin").live_grep(opts) end +function M.view_lunarvim_changelog() + local finders = require "telescope.finders" + local make_entry = require "telescope.make_entry" + local pickers = require "telescope.pickers" + local previewers = require "telescope.previewers" + local actions = require "telescope.actions" + local opts = {} + + local conf = require("telescope.config").values + opts.entry_maker = make_entry.gen_from_git_commits(opts) + + pickers.new(opts, { + prompt_title = "LunarVim changelog", + + finder = finders.new_oneshot_job( + vim.tbl_flatten { + "git", + "log", + "--pretty=oneline", + "--abbrev-commit", + "--", + ".", + }, + opts + ), + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + + --TODO: consider opening a diff view when pressing enter + attach_mappings = function(_, map) + map("i", "<enter>", actions._close) + map("n", "<enter>", actions._close) + map("i", "<esc>", actions._close) + map("n", "<esc>", actions._close) + map("n", "q", actions._close) + return true + end, + sorter = conf.file_sorter(opts), + }):find() +end + +function M.code_actions() + local opts = { + winblend = 15, + layout_config = { + prompt_position = "top", + width = 80, + height = 12, + }, + borderchars = { + prompt = { "─", "│", " ", "│", "╭", "╮", "│", "│" }, + results = { "─", "│", "─", "│", "├", "┤", "╯", "╰" }, + preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + }, + border = {}, + previewer = false, + shorten_path = false, + } + require("telescope.builtin").lsp_code_actions(require("telescope.themes").get_dropdown(opts)) +end + function M.setup() local telescope = require "telescope" diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index f9be8734..3a0c6e46 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,5 +1,5 @@ local M = {} -local utils = require "utils" +local Log = require "core.log" M.config = function() lvim.builtin["terminal"] = { @@ -81,7 +81,6 @@ end M._exec_toggle = function(exec) local binary = M._split(exec)[1] if vim.fn.executable(binary) ~= 1 then - local Log = require "core.log" Log:error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end @@ -90,29 +89,16 @@ M._exec_toggle = function(exec) exec_term:toggle() end -local function get_log_path(name) - --handle custom paths not managed by Plenary.log - local logger = require "core.log" - local file - if name == "nvim" then - file = CACHE_PATH .. "/log" - else - file = logger:new({ plugin = name }):get_path() - end - if utils.is_file(file) then - return file - end -end - ---Toggles a log viewer according to log.viewer.layout_config ----@param name can be the name of any of the managed logs, e,g. "lunarvim" or the default ones {"nvim", "lsp", "packer.nvim"} -M.toggle_log_view = function(name) - local logfile = get_log_path(name) - if not logfile then - return +---@param logfile string the fullpath to the logfile +M.toggle_log_view = function(logfile) + local log_viewer = lvim.log.viewer.cmd + if vim.fn.executable(log_viewer) ~= 1 then + log_viewer = "less +F" end + log_viewer = log_viewer .. " " .. logfile local term_opts = vim.tbl_deep_extend("force", lvim.builtin.terminal, { - cmd = lvim.log.viewer.cmd .. " " .. logfile, + cmd = log_viewer, open_mapping = lvim.log.viewer.layout_config.open_mapping, direction = lvim.log.viewer.layout_config.direction, -- TODO: this might not be working as expected @@ -122,7 +108,6 @@ M.toggle_log_view = function(name) local Terminal = require("toggleterm.terminal").Terminal local log_view = Terminal:new(term_opts) - -- require("core.log"):debug("term", vim.inspect(term_opts)) log_view:toggle() end diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 71c0b695..c9e9b2f4 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -72,25 +72,26 @@ M.config = function() ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" }, b = { name = "Buffers", - j = { "<cmd>BufferPick<cr>", "jump to buffer" }, - f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, - w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, + j = { "<cmd>BufferPick<cr>", "Jump" }, + f = { "<cmd>Telescope buffers<cr>", "Find" }, + b = { "<cmd>b#<cr>", "Previous" }, + w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, e = { "<cmd>BufferCloseAllButCurrent<cr>", - "close all but current buffer", + "Close all but current", }, - h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, + h = { "<cmd>BufferCloseBuffersLeft<cr>", "Close all to the left" }, l = { "<cmd>BufferCloseBuffersRight<cr>", - "close all BufferLines to the right", + "Close all to the right", }, D = { "<cmd>BufferOrderByDirectory<cr>", - "sort BufferLines automatically by directory", + "Sort by directory", }, L = { "<cmd>BufferOrderByLanguage<cr>", - "sort BufferLines automatically by language", + "Sort by language", }, }, p = { @@ -130,11 +131,15 @@ M.config = function() "<cmd>Telescope git_bcommits<cr>", "Checkout commit(for current file)", }, + d = { + "<cmd>Gitsigns diffthis HEAD<cr>", + "Git Diff", + }, }, l = { name = "LSP", - a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" }, + a = { "<cmd>lua require('core.telescope').code_actions()<cr>", "Code Action" }, d = { "<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics", @@ -143,9 +148,9 @@ M.config = function() "<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics", }, - -- f = { "<cmd>silent FormatWrite<cr>", "Format" }, f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" }, i = { "<cmd>LspInfo<cr>", "Info" }, + I = { "<cmd>LspInstallInfo<cr>", "Installer Info" }, j = { "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "Next Diagnostic", @@ -154,6 +159,7 @@ M.config = function() "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "Prev Diagnostic", }, + l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" }, p = { name = "Peek", d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" }, @@ -171,7 +177,7 @@ M.config = function() L = { name = "+LunarVim", c = { - "<cmd>edit ~/.config/lvim/config.lua<cr>", + "<cmd>edit" .. get_config_dir() .. "/config.lua<cr>", "Edit config.lua", }, f = { @@ -187,23 +193,32 @@ M.config = function() "<cmd>lua require('core.info').toggle_popup(vim.bo.filetype)<cr>", "Toggle LunarVim Info", }, + I = { + "<cmd>lua require('core.telescope').view_lunarvim_changelog()<cr>", + "View LunarVim's changelog", + }, l = { name = "+logs", d = { - "<cmd>lua require('core.terminal').toggle_log_view('lunarvim')<cr>", + "<cmd>lua require('core.terminal').toggle_log_view(require('core.log').get_path())<cr>", "view default log", }, - D = { "<cmd>edit ~/.cache/nvim/lunarvim.log<cr>", "Open the default logfile" }, - n = { "<cmd>lua require('core.terminal').toggle_log_view('lsp')<cr>", "view lsp log" }, - N = { "<cmd>edit ~/.cache/nvim/log<cr>", "Open the Neovim logfile" }, - l = { "<cmd>lua require('core.terminal').toggle_log_view('nvim')<cr>", "view neovim log" }, - L = { "<cmd>edit ~/.cache/nvim/lsp.log<cr>", "Open the LSP logfile" }, + D = { "<cmd>lua vim.fn.execute('edit ' .. require('core.log').get_path())<cr>", "Open the default logfile" }, + l = { "<cmd>lua require('core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>", "view lsp log" }, + L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" }, + n = { + "<cmd>lua require('core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>", + "view neovim log", + }, + N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" }, p = { "<cmd>lua require('core.terminal').toggle_log_view('packer.nvim')<cr>", "view packer log", }, - P = { "<cmd>edit ~/.cache/nvim/packer.nvim.log<cr>", "Open the Packer logfile" }, + P = { "<cmd>exe 'edit '.stdpath('cache').'/packer.nvim.log'<cr>", "Open the Packer logfile" }, }, + r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload configurations" }, + u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" }, }, s = { name = "Search", |