Prechádzať zdrojové kódy

Merge branch 'rolling'

kylo252 3 rokov pred
rodič
commit
17648e5a07

+ 21 - 11
README.md

@@ -79,19 +79,30 @@ lvim.builtin.treesitter.ignore_install = { "haskell" }
 -- Disable virtual text
 lvim.lsp.diagnostics.virtual_text = false
 
--- set a formatter if you want to override the default lsp one (if it exists)
-lvim.lang.python.formatters = {
+-- Select which servers should be configured manually. Requires `:LvimCacheRest` to take effect.
+-- See the full default list `:lua print(vim.inspect(lvim.lsp.override))`
+vim.list_extend(lvim.lsp.override, { "pyright" })
+
+-- set a formatter, this will override the language server formatting capabilities (if it exists)
+local formatters = require "lvim.lsp.null-ls.formatters"
+formatters.setup {
+  { exe = "black" },
   {
-    exe = "black",
-    args = {}
-  }
+    exe = "prettier",
+    ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
+    filetypes = { "typescript", "typescriptreact" },
+  },
 }
--- set an additional linter
-lvim.lang.python.linters = {
+
+-- set additional linters
+local linters = require "lvim.lsp.null-ls.linters"
+linters.setup {
+  { exe = "black" },
   {
-    exe = "flake8",
-    args = {}
-  }
+    exe = "eslint_d",
+    ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
+    filetypes = { "javascript", "javascriptreact" },
+  },
 }
 
 
@@ -118,7 +129,6 @@ lvim.plugins = {
 ## Breaking changes
 
 - `lvim.lang.FOO.lsp` is no longer supported after #1584.
-  You can either use `:NlspConfig` for most of the settings you might need, or override the setup by adding an entry to `lvim.lsp.override = { "FOO" }`.
 
 ## Resources
 

+ 2 - 3
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()

+ 1 - 0
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

+ 6 - 10
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 } }

+ 52 - 14
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

+ 8 - 4
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,
       },

+ 1 - 1
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 = {

+ 2 - 0
lua/lvim/lsp/config.lua

@@ -46,6 +46,8 @@ return {
     "ansiblels",
     "denols",
     "ember",
+    "eslint",
+    "eslintls",
     "jedi_language_server",
     "pylsp",
     "rome",

+ 7 - 3
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
 

+ 2 - 1
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
 

+ 14 - 0
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

+ 1 - 1
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,

+ 14 - 4
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

+ 1 - 1
lua/onedarker/highlights.lua

@@ -18,7 +18,7 @@ local highlights = {
   FoldColumn = { fg = C.accent, bg = C.alt_bg },
   LineNr = { fg = C.context },
   FloatBorder = { fg = C.gray, bg = C.alt_bg },
-  Whitespace = { fg = C.bg },
+  Whitespace = { fg = C.gray },
   VertSplit = { fg = C.bg, bg = C.fg },
   CursorLine = { bg = C.dark },
   CursorColumn = { bg = C.dark },

+ 0 - 112
utils/installer/config.example-no-ts.lua

@@ -1,112 +0,0 @@
--- THESE ARE EXAMPLE CONFIGS FEEL FREE TO CHANGE TO WHATEVER YOU WANT
-
--- general
-lvim.format_on_save = true
-lvim.lint_on_save = true
-lvim.colorscheme = "onedarker"
-
--- keymappings [view all the defaults by pressing <leader>Lk]
-lvim.leader = "space"
--- add your own keymapping
-lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
--- unmap a default keymapping
--- lvim.keys.normal_mode["<C-Up>"] = ""
--- edit a default keymapping
--- lvim.keys.normal_mode["<C-q>"] = ":q<cr>"
-
--- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode.
--- we use protected-mode (pcall) just in case the plugin wasn't loaded yet.
--- local _, actions = pcall(require, "telescope.actions")
--- lvim.builtin.telescope.defaults.mappings = {
---   -- for input mode
---   i = {
---     ["<C-j>"] = actions.move_selection_next,
---     ["<C-k>"] = actions.move_selection_previous,
---     ["<C-n>"] = actions.cycle_history_next,
---     ["<C-p>"] = actions.cycle_history_prev,
---   },
---   -- for normal mode
---   n = {
---     ["<C-j>"] = actions.move_selection_next,
---     ["<C-k>"] = actions.move_selection_previous,
---   },
--- }
-
--- Use which-key to add extra bindings with the leader-key prefix
--- lvim.builtin.which_key.mappings["P"] = { "<cmd>Telescope projects<CR>", "Projects" }
--- lvim.builtin.which_key.mappings["t"] = {
---   name = "+Trouble",
---   r = { "<cmd>Trouble lsp_references<cr>", "References" },
---   f = { "<cmd>Trouble lsp_definitions<cr>", "Definitions" },
---   d = { "<cmd>Trouble lsp_document_diagnostics<cr>", "Diagnosticss" },
---   q = { "<cmd>Trouble quickfix<cr>", "QuickFix" },
---   l = { "<cmd>Trouble loclist<cr>", "LocationList" },
---   w = { "<cmd>Trouble lsp_workspace_diagnostics<cr>", "Diagnosticss" },
--- }
-
--- TODO: User Config for predefined plugins
--- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
-lvim.builtin.dashboard.active = true
-lvim.builtin.terminal.active = true
-lvim.builtin.nvimtree.setup.view.side = "left"
-lvim.builtin.nvimtree.show_icons.git = 0
-
--- if you don't want all the parsers change this to a table of the ones you want
-lvim.builtin.treesitter.ensure_installed = {}
-lvim.builtin.treesitter.ignore_install = { "haskell" }
-lvim.builtin.treesitter.highlight.enabled = true
-
--- generic LSP settings
--- you can set a custom on_attach function that will be used for all the language servers
--- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
--- lvim.lsp.on_attach_callback = function(client, bufnr)
---   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")
--- end
--- you can overwrite the null_ls setup table (useful for setting the root_dir function)
--- lvim.lsp.null_ls.setup = {
---   root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"),
--- }
--- or if you need something more advanced
--- lvim.lsp.null_ls.setup.root_dir = function(fname)
---   if vim.bo.filetype == "javascript" then
---     return require("lspconfig/util").root_pattern("Makefile", ".git", "node_modules")(fname)
---       or require("lspconfig/util").path.dirname(fname)
---   elseif vim.bo.filetype == "php" then
---     return require("lspconfig/util").root_pattern("Makefile", ".git", "composer.json")(fname) or vim.fn.getcwd()
---   else
---     return require("lspconfig/util").root_pattern("Makefile", ".git")(fname) or require("lspconfig/util").path.dirname(fname)
---   end
--- end
-
--- set a formatter if you want to override the default lsp one (if it exists)
--- lvim.lang.python.formatters = {
---   {
---     exe = "black",
---     args = {}
---   }
--- }
--- set an additional linter
--- lvim.lang.python.linters = {
---   {
---     exe = "flake8",
---     args = {}
---   }
--- }
-
--- Additional Plugins
--- lvim.plugins = {
---     {"folke/tokyonight.nvim"}, {
---         "ray-x/lsp_signature.nvim",
---         config = function() require"lsp_signature".on_attach() end,
---         event = "InsertEnter"
---     }
--- }
-
--- Autocommands (https://neovim.io/doc/user/autocmd.html)
--- lvim.autocommands.custom_groups = {
---   { "BufWinEnter", "*.lua", "setlocal ts=8 sw=8" },
--- }

+ 29 - 8
utils/installer/config.example.lua

@@ -78,6 +78,18 @@ lvim.builtin.treesitter.ignore_install = { "haskell" }
 lvim.builtin.treesitter.highlight.enabled = true
 
 -- generic LSP settings
+
+-- ---@usage disable automatic installation of servers
+-- lvim.lsp.automatic_servers_installation = false
+
+-- ---@usage Select which servers should be configured manually. Requires `:LvimCacheRest` to take effect.
+-- See the full default list `:lua print(vim.inspect(lvim.lsp.override))`
+-- vim.list_extend(lvim.lsp.override, { "pyright" })
+
+-- ---@usage setup a server -- see: https://www.lunarvim.org/languages/#overriding-the-default-configuration
+-- local opts = {} -- check the lspconfig documentation for a list of all possible options
+-- require("lvim.lsp.manager").setup("pylsp", opts)
+
 -- you can set a custom on_attach function that will be used for all the language servers
 -- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
 -- lvim.lsp.on_attach_callback = function(client, bufnr)
@@ -103,17 +115,26 @@ lvim.builtin.treesitter.highlight.enabled = true
 --   end
 -- end
 
--- set a formatter if you want to override the default lsp one (if it exists)
--- lvim.lang.python.formatters = {
+-- -- set a formatter, this will override the language server formatting capabilities (if it exists)
+-- local formatters = require "lvim.lsp.null-ls.formatters"
+-- formatters.setup {
+--   { exe = "black" },
 --   {
---     exe = "black",
---   }
+--     exe = "prettier",
+--     ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
+--     filetypes = { "typescript", "typescriptreact" },
+--   },
 -- }
--- set an additional linter
--- lvim.lang.python.linters = {
+
+-- -- set additional linters
+-- local linters = require "lvim.lsp.null-ls.linters"
+-- linters.setup {
+--   { exe = "black" },
 --   {
---     exe = "flake8",
---   }
+--     exe = "eslint_d",
+--     ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
+--     filetypes = { "javascript", "javascriptreact" },
+--   },
 -- }
 
 -- Additional Plugins

+ 5 - 2
utils/installer/install.ps1

@@ -222,8 +222,11 @@ function setup_lvim() {
         New-Item "$env:LUNARVIM_CONFIG_DIR" -ItemType Directory
     }
 
-    Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\installer\config.example-no-ts.lua" `
-        "$env:LUNARVIM_CONFIG_DIR\config.lua"
+    if (Test-Path "$env:LUNARVIM_CONFIG_DIR\config.lua") {
+        Remove-Item -Force "$env:LUNARVIM_CONFIG_DIR\config.lua"
+    }
+
+    Out-File -FilePath "$env:LUNARVIM_CONFIG_DIR\config.lua"
   
 	Write-Output "Packer setup complete"
 	

+ 2 - 2
utils/installer/install.sh

@@ -353,8 +353,8 @@ function setup_lvim() {
 
   echo "Preparing Packer setup"
 
-  cp "$LUNARVIM_RUNTIME_DIR/lvim/utils/installer/config.example-no-ts.lua" \
-    "$LUNARVIM_CONFIG_DIR/config.lua"
+  rm -f "$LUNARVIM_CONFIG_DIR/config.lua"
+  touch "$LUNARVIM_CONFIG_DIR/config.lua"
 
   "$INSTALL_PREFIX/bin/lvim" --headless \
     -c 'autocmd User PackerComplete quitall' \