diff options
Diffstat (limited to 'lua/lvim')
| -rw-r--r-- | lua/lvim/bootstrap.lua | 5 | ||||
| -rw-r--r-- | lua/lvim/config/settings.lua | 1 | ||||
| -rw-r--r-- | lua/lvim/core/autopairs.lua | 16 | ||||
| -rw-r--r-- | lua/lvim/core/cmp.lua | 66 | ||||
| -rw-r--r-- | lua/lvim/core/dashboard.lua | 12 | ||||
| -rw-r--r-- | lua/lvim/core/which-key.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/lsp/config.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/lsp/manager.lua | 10 | ||||
| -rw-r--r-- | lua/lvim/lsp/templates.lua | 3 | ||||
| -rw-r--r-- | lua/lvim/plugin-loader.lua | 14 | ||||
| -rw-r--r-- | lua/lvim/plugins.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/utils/hooks.lua | 18 | 
12 files changed, 110 insertions, 41 deletions
| diff --git a/lua/lvim/bootstrap.lua b/lua/lvim/bootstrap.lua index fbb362ce..e17c79db 100644 --- a/lua/lvim/bootstrap.lua +++ b/lua/lvim/bootstrap.lua @@ -1,8 +1,5 @@  local M = {} -package.loaded["lvim.utils.hooks"] = nil -local _, hooks = pcall(require, "lvim.utils.hooks") -  local uv = vim.loop  local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" @@ -101,6 +98,8 @@ end  ---Update LunarVim  ---pulls the latest changes from github and, resets the startup cache  function M:update() +  package.loaded["lvim.utils.hooks"] = nil +  local _, hooks = pcall(require, "lvim.utils.hooks")    hooks.run_pre_update()    M:update_repo()    hooks.run_post_update() diff --git a/lua/lvim/config/settings.lua b/lua/lvim/config/settings.lua index b86e1a18..8db43904 100644 --- a/lua/lvim/config/settings.lua +++ b/lua/lvim/config/settings.lua @@ -69,6 +69,7 @@ M.load_commands = function()      cmd "au ColorScheme * hi MsgArea ctermbg=none guibg=none"      cmd "au ColorScheme * hi TelescopeBorder ctermbg=none guibg=none"      cmd "au ColorScheme * hi NvimTreeNormal ctermbg=none guibg=none" +    cmd "au ColorScheme * hi EndOfBuffer ctermbg=none guibg=none"      cmd "let &fcs='eob: '"    end  end diff --git a/lua/lvim/core/autopairs.lua b/lua/lvim/core/autopairs.lua index eb080fb1..51649790 100644 --- a/lua/lvim/core/autopairs.lua +++ b/lua/lvim/core/autopairs.lua @@ -4,8 +4,6 @@ function M.config()    lvim.builtin.autopairs = {      active = true,      on_config_done = nil, -    ---@usage auto insert after select function or method item -    map_complete = true,      ---@usage  -- modifies the function or method delimiter by filetypes      map_char = {        all = "(", @@ -52,14 +50,12 @@ M.setup = function()      end),    } -  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 }) +  local cmp_status_ok, cmp = pcall(require, "cmp") +  if cmp_status_ok then +    -- If you want insert `(` after select function or method item +    local cmp_autopairs = require "nvim-autopairs.completion.cmp" +    local map_char = lvim.builtin.autopairs.map_char +    cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = map_char })    end    require("nvim-treesitter.configs").setup { autopairs = { enable = true } } diff --git a/lua/lvim/core/cmp.lua b/lua/lvim/core/cmp.lua index b1cb1431..68c695cb 100644 --- a/lua/lvim/core/cmp.lua +++ b/lua/lvim/core/cmp.lua @@ -1,14 +1,29 @@  local M = {} +M.methods = {} +---checks if the character preceding the cursor is a space character +---@return boolean true if it is a space character, false otherwise  local check_backspace = function()    local col = vim.fn.col "." - 1    return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"  end +M.methods.check_backspace = check_backspace  local function T(str)    return vim.api.nvim_replace_termcodes(str, true, true, true)  end +---wraps vim.fn.feedkeys while replacing key codes with escape codes +---Ex: feedkeys("<CR>", "n") becomes feedkeys("^M", "n") +---@param key string +---@param mode string +local function feedkeys(key, mode) +  vim.fn.feedkeys(T(key), mode) +end +M.methods.feedkeys = feedkeys + +---checks if emmet_ls is available and active in the buffer +---@return boolean true if available, false otherwise  local is_emmet_active = function()    local clients = vim.lsp.buf_get_clients() @@ -19,16 +34,17 @@ local is_emmet_active = function()    end    return false  end +M.methods.is_emmet_active = is_emmet_active -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 +---when inside a snippet, seeks to the nearest luasnip field if possible, and checks if it is jumpable +---@param dir number 1 for forward, -1 for backward; defaults to 1 +---@return boolean true if a jumpable luasnip field is found while inside a snippet +local function jumpable(dir) +  local luasnip_ok, luasnip = pcall(require, "luasnip") +  if not 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 @@ -121,11 +137,33 @@ M.config = function()      return false    end +  if dir == -1 then +    return inside_snippet() and luasnip.jumpable(-1) +  else +    return inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() +  end +end +M.methods.jumpable = jumpable + +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 +    lvim.builtin.cmp = {      confirm_opts = {        behavior = cmp.ConfirmBehavior.Replace,        select = false,      }, +    completion = { +      ---@usage The minimum length of a word to complete on. +      keyword_length = 1, +    },      experimental = {        ghost_text = true,        native_menu = false, @@ -209,19 +247,19 @@ M.config = function()        ["<C-d>"] = cmp.mapping.scroll_docs(-4),        ["<C-f>"] = cmp.mapping.scroll_docs(4),        -- TODO: potentially fix emmet nonsense -      ["<Tab>"] = cmp.mapping(function() +      ["<Tab>"] = cmp.mapping(function(fallback)          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 +        elseif jumpable() then            luasnip.jump(1)          elseif check_backspace() then -          vim.fn.feedkeys(T "<Tab>", "n") +          fallback()          elseif is_emmet_active() then            return vim.fn["cmp#complete"]()          else -          vim.fn.feedkeys(T "<Tab>", "n") +          fallback()          end        end, {          "i", @@ -230,7 +268,7 @@ M.config = function()        ["<S-Tab>"] = cmp.mapping(function(fallback)          if cmp.visible() then            cmp.select_prev_item() -        elseif inside_snippet() and luasnip.jumpable(-1) then +        elseif jumpable(-1) then            luasnip.jump(-1)          else            fallback() @@ -241,13 +279,13 @@ M.config = function()        }),        ["<C-Space>"] = cmp.mapping.complete(), -      ["<C-e>"] = cmp.mapping.close(), +      ["<C-e>"] = cmp.mapping.abort(),        ["<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 jumpable() then            if not luasnip.jump(1) then              fallback()            end diff --git a/lua/lvim/core/dashboard.lua b/lua/lvim/core/dashboard.lua index 108ed0d2..11053796 100644 --- a/lua/lvim/core/dashboard.lua +++ b/lua/lvim/core/dashboard.lua @@ -31,22 +31,26 @@ M.config = function(config)      custom_section = {        a = { -        description = { "  Find File          " }, +        description = { "  Find File          " },          command = "Telescope find_files",        },        b = { +        description = { "  New File           " }, +        command = ":ene!", +      }, +      c = {          description = { "  Recent Projects    " },          command = "Telescope projects",        }, -      c = { +      d = {          description = { "  Recently Used Files" },          command = "Telescope oldfiles",        }, -      d = { +      e = {          description = { "  Find Word          " },          command = "Telescope live_grep",        }, -      e = { +      f = {          description = { "  Configuration      " },          command = ":e " .. config.user_config_file,        }, diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index fcaeacf5..42e37456 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -177,7 +177,7 @@ M.config = function()        L = {          name = "+LunarVim",          c = { -          "<cmd>edit" .. get_config_dir() .. "/config.lua<cr>", +          "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",            "Edit config.lua",          },          f = { diff --git a/lua/lvim/lsp/config.lua b/lua/lvim/lsp/config.lua index 96430631..2d9104ea 100644 --- a/lua/lvim/lsp/config.lua +++ b/lua/lvim/lsp/config.lua @@ -46,6 +46,8 @@ return {      "ansiblels",      "denols",      "ember", +    "eslint", +    "eslintls",      "jedi_language_server",      "pylsp",      "rome", diff --git a/lua/lvim/lsp/manager.lua b/lua/lvim/lsp/manager.lua index 0b11c175..a8544803 100644 --- a/lua/lvim/lsp/manager.lua +++ b/lua/lvim/lsp/manager.lua @@ -26,8 +26,8 @@ local function resolve_config(name, user_config)      capabilities = require("lvim.lsp").common_capabilities(),    } -  local status_ok, custom_config = pcall(require, "lvim.lsp/providers/" .. name) -  if status_ok then +  local has_custom_provider, custom_config = pcall(require, "lvim/lsp/providers/" .. name) +  if has_custom_provider then      Log:debug("Using custom configuration for requested server: " .. name)      config = vim.tbl_deep_extend("force", config, custom_config)    end @@ -70,7 +70,11 @@ function M.setup(server_name, user_config)    if server_available and ensure_installed(requested_server) then      requested_server:setup(config)    else -    require("lspconfig")[server_name].setup(config) +    -- since it may not be installed, don't attempt to configure the LSP unless there is a custom provider +    local has_custom_provider, _ = pcall(require, "lvim/lsp/providers/" .. server_name) +    if has_custom_provider then +      require("lspconfig")[server_name].setup(config) +    end    end  end diff --git a/lua/lvim/lsp/templates.lua b/lua/lvim/lsp/templates.lua index 3478f4fb..33c75a6e 100644 --- a/lua/lvim/lsp/templates.lua +++ b/lua/lvim/lsp/templates.lua @@ -19,7 +19,8 @@ end  ---@param server_name string name of a valid language server, e.g. pyright, gopls, tsserver, etc.  ---@param dir string the full path to the desired directory  function M.generate_ftplugin(server_name, dir) -  if vim.tbl_contains(lvim.lsp.override, server_name) then +  local has_custom_provider, _ = pcall(require, "lvim/lsp/providers/" .. server_name) +  if vim.tbl_contains(lvim.lsp.override, server_name) and not has_custom_provider then      return    end diff --git a/lua/lvim/plugin-loader.lua b/lua/lvim/plugin-loader.lua index feef7ea7..e1ede7bc 100644 --- a/lua/lvim/plugin-loader.lua +++ b/lua/lvim/plugin-loader.lua @@ -60,4 +60,18 @@ function plugin_loader:load(configurations)    end)  end +function plugin_loader:get_core_plugins() +  local list = {} +  local plugins = require "lvim.plugins" +  for _, item in pairs(plugins) do +    table.insert(list, item[1]:match "/(%S*)") +  end +  return list +end + +function plugin_loader:sync_core_plugins() +  local core_plugins = plugin_loader.get_core_plugins() +  vim.cmd("PackerSync " .. unpack(core_plugins)) +end +  return plugin_loader diff --git a/lua/lvim/plugins.lua b/lua/lvim/plugins.lua index c50e74d8..4c3a0f67 100644 --- a/lua/lvim/plugins.lua +++ b/lua/lvim/plugins.lua @@ -81,7 +81,7 @@ return {      "kyazdani42/nvim-tree.lua",      -- event = "BufWinOpen",      -- cmd = "NvimTreeToggle", -    commit = "edc74ee6c4aebdcbaea092557db372b93929f9d0", +    commit = "f92b7e7627c5a36f4af6814c408211539882c4f3",      config = function()        require("lvim.core.nvimtree").setup()      end, diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua index d536bc76..cc884523 100644 --- a/lua/lvim/utils/hooks.lua +++ b/lua/lvim/utils/hooks.lua @@ -1,11 +1,13 @@  local M = {} +local plugin_loader = require "lvim.plugin-loader"  local Log = require "lvim.core.log"  local in_headless = #vim.api.nvim_list_uis() == 0  function M.run_pre_update()    Log:debug "Starting pre-update hook"    _G.__luacache.clear_cache() +  vim.cmd "LspStop"  end  ---Reset any startup cache files used by Packer and Impatient @@ -13,21 +15,29 @@ end  ---Tip: Useful for clearing any outdated settings  function M.reset_cache()    _G.__luacache.clear_cache() -  require("lvim.plugin-loader"):cache_reset() + +  plugin_loader:cache_reset()    package.loaded["lvim.lsp.templates"] = nil + +  Log:debug "Re-generatring ftplugin template files"    require("lvim.lsp.templates").generate_templates()  end  function M.run_post_update()    Log:debug "Starting post-update hook" -  M.reset_cache() + +  Log:debug "Re-generatring ftplugin template files" +  package.loaded["lvim.lsp.templates"] = nil +  require("lvim.lsp.templates").generate_templates() + +  Log:debug "Updating core plugins" +  plugin_loader:sync_core_plugins()    if not in_headless then      vim.schedule(function() -      require("packer").install()        -- TODO: add a changelog        vim.notify("Update complete", vim.log.levels.INFO) -      vim.cmd "LspStart" +      vim.cmd "LspRestart"      end)    end  end | 
