Procházet zdrojové kódy

Fix: make sure latest plugins are customizable (#3044)

* fix: make navim-navic configurable

* fix: make sure vim-illuminate is configurable

* fix: make sure theme is configurable

* fix(ci): don't verify uninstalled plugins

* refactor(lsp): add setup_document_symbols util

* revert: keep onedarker on freeze branch

* refactor(lsp): avoid duplicate hl autocmds

Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com>
Abouzar Parvan před 2 roky
rodič
revize
518b1d4167

+ 2 - 2
README.md

@@ -70,7 +70,7 @@ Example:
 ```lua
 -- general
 lvim.format_on_save = true
-lvim.colorscheme = "onedarker"
+lvim.colorscheme = "tokyonight"
 
 lvim.leader = "space"
 -- add your own keymapping
@@ -125,7 +125,7 @@ linters.setup {
 -- Additional Plugins
 lvim.plugins = {
     {"lunarvim/colorschemes"},
-    {"folke/tokyonight.nvim"}, {
+    {
         "ray-x/lsp_signature.nvim",
         config = function() require"lsp_signature".on_attach() end,
         event = "BufRead"

+ 1 - 1
lua/lvim/config/defaults.lua

@@ -1,6 +1,6 @@
 return {
   leader = "space",
-  colorscheme = "onedarker",
+  colorscheme = "tokyonight",
   transparent_window = false,
   format_on_save = {
     ---@usage pattern string pattern used for the autocommand (Default: '*')

+ 55 - 51
lua/lvim/core/breadcrumbs.lua

@@ -3,60 +3,66 @@ local M = {}
 -- local Log = require "lvim.core.log"
 
 M.config = function()
+  lvim.builtin.breadcrumbs = {
+    active = false,
+    on_config_done = nil,
+    options = {
+      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 = " ",
+        Array = " ",
+        Number = " ",
+        String = " ",
+        Boolean = "蘒",
+        Object = " ",
+        Package = " ",
+        Namespace = "",
+        Key = "",
+        Null = "ﳠ",
+      },
+      highlight = true,
+      separator = " " .. ">" .. " ",
+      depth_limit = 0,
+      depth_limit_indicator = "..",
+    },
+  }
+end
+
+M.setup = function()
   local status_ok, navic = pcall(require, "nvim-navic")
   if not status_ok then
     return
   end
 
-  navic.setup {
-    icons = {
-      Text = " ",
-      -- Method = "m",
-      -- Function = "",
-      -- Constructor = "",
-      Method = " ",
-      Function = " ",
-      Constructor = " ",
-      Field = " ",
-      -- Variable = "",
-      Variable = " ",
-      Class = " ",
-      Interface = " ",
-      -- Module = "",
-      Module = " ",
-      Property = " ",
-      Unit = " ",
-      Value = " ",
-      Enum = " ",
-      -- Keyword = "",
-      Keyword = " ",
-      -- Snippet = "",
-      Snippet = " ",
-      Color = " ",
-      File = " ",
-      Reference = " ",
-      Folder = " ",
-      EnumMember = " ",
-      Constant = " ",
-      Struct = " ",
-      Event = " ",
-      Operator = " ",
-      TypeParameter = " ",
-      Array = " ",
-      Number = " ",
-      String = " ",
-      Boolean = "蘒",
-      Object = " ",
-      Package = " ",
-      Namespace = "",
-      Key = "",
-      Null = "ﳠ",
-    },
-    highlight = true,
-    separator = " " .. ">" .. " ",
-    depth_limit = 0,
-    depth_limit_indicator = "..",
-  }
+  M.create_winbar()
+  navic.setup(lvim.builtin.breadcrumbs.options)
+
+  if lvim.builtin.breadcrumbs.on_config_done then
+    lvim.builtin.breadcrumbs.on_config_done()
+  end
 end
 
 M.winbar_filetype_exclude = {
@@ -199,6 +205,4 @@ M.create_winbar = function()
   end
 end
 
-M.create_winbar()
-
 return M

+ 1 - 0
lua/lvim/core/builtins/init.lua

@@ -1,6 +1,7 @@
 local M = {}
 
 local builtins = {
+  "lvim.core.theme",
   "lvim.core.which-key",
   "lvim.core.gitsigns",
   "lvim.core.cmp",

+ 55 - 43
lua/lvim/core/illuminate.lua

@@ -1,53 +1,65 @@
 local M = {}
 
 M.config = function()
+  lvim.builtin.illuminate = {
+    active = true,
+    on_config_done = nil,
+    options = {
+      -- providers: provider used to get references in the buffer, ordered by priority
+      providers = {
+        "lsp",
+        "treesitter",
+        "regex",
+      },
+      -- delay: delay in milliseconds
+      delay = 120,
+      -- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist
+      filetypes_denylist = {
+        "dirvish",
+        "fugitive",
+        "alpha",
+        "NvimTree",
+        "packer",
+        "neogitstatus",
+        "Trouble",
+        "lir",
+        "Outline",
+        "spectre_panel",
+        "toggleterm",
+        "DressingSelect",
+        "TelescopePrompt",
+      },
+      -- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist
+      filetypes_allowlist = {},
+      -- modes_denylist: modes to not illuminate, this overrides modes_allowlist
+      modes_denylist = {},
+      -- modes_allowlist: modes to illuminate, this is overriden by modes_denylist
+      modes_allowlist = {},
+      -- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist
+      -- Only applies to the 'regex' provider
+      -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
+      providers_regex_syntax_denylist = {},
+      -- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist
+      -- Only applies to the 'regex' provider
+      -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
+      providers_regex_syntax_allowlist = {},
+      -- under_cursor: whether or not to illuminate under the cursor
+      under_cursor = true,
+    },
+  }
+end
+
+M.setup = function()
   local status_ok, illuminate = pcall(require, "illuminate")
   if not status_ok then
     return
   end
-  -- default configuration
-  illuminate.configure {
-    -- providers: provider used to get references in the buffer, ordered by priority
-    providers = {
-      "lsp",
-      "treesitter",
-      "regex",
-    },
-    -- delay: delay in milliseconds
-    delay = 120,
-    -- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist
-    filetypes_denylist = {
-      "dirvish",
-      "fugitive",
-      "alpha",
-      "NvimTree",
-      "packer",
-      "neogitstatus",
-      "Trouble",
-      "lir",
-      "Outline",
-      "spectre_panel",
-      "toggleterm",
-      "DressingSelect",
-      "TelescopePrompt",
-    },
-    -- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist
-    filetypes_allowlist = {},
-    -- modes_denylist: modes to not illuminate, this overrides modes_allowlist
-    modes_denylist = {},
-    -- modes_allowlist: modes to illuminate, this is overriden by modes_denylist
-    modes_allowlist = {},
-    -- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist
-    -- Only applies to the 'regex' provider
-    -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
-    providers_regex_syntax_denylist = {},
-    -- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist
-    -- Only applies to the 'regex' provider
-    -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')
-    providers_regex_syntax_allowlist = {},
-    -- under_cursor: whether or not to illuminate under the cursor
-    under_cursor = true,
-  }
+
+  illuminate.configure(lvim.builtin.illuminate.options)
+
+  if lvim.builtin.illuminate.on_config_done then
+    lvim.builtin.illuminate.on_config_done()
+  end
 end
 
 return M

+ 50 - 0
lua/lvim/core/theme.lua

@@ -0,0 +1,50 @@
+local M = {}
+
+M.config = function()
+  lvim.builtin.theme = {
+    name = "tokyonight",
+    options = {
+      style = "night", -- The theme comes in three styles, `storm`, a darker variant `night` and `day`
+      transparent = lvim.transparent_window, -- Enable this to disable setting the background color
+      terminal_colors = true, -- Configure the colors used when opening a `:terminal` in Neovim
+      styles = {
+        -- Style to be applied to different syntax groups
+        -- Value is any valid attr-list value for `:help nvim_set_hl`
+        comments = { italic = true },
+        keywords = { italic = true },
+        functions = {},
+        variables = {},
+        -- Background styles. Can be "dark", "transparent" or "normal"
+        sidebars = "dark", -- style for sidebars, see below
+        floats = "dark", -- style for floating windows
+      },
+      -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]`
+      sidebars = {
+        "qf",
+        "vista_kind",
+        "terminal",
+        "packer",
+        "spectre_panel",
+        "NeogitStatus",
+        "help",
+      },
+      day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors
+      hide_inactive_statusline = false, -- Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**.
+      dim_inactive = false, -- dims inactive windows
+      lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold
+      use_background = true, -- can be light/dark/auto. When auto, background will be set to vim.o.background
+    },
+  }
+end
+
+M.setup = function()
+  local status_ok, theme = pcall(require, "tokyonight")
+  if not status_ok then
+    return
+  end
+
+  theme.setup(lvim.builtin.theme.options)
+  lvim.builtin.lualine.options.theme = "tokyonight"
+end
+
+return M

+ 1 - 1
lua/lvim/lsp/config.lua

@@ -72,7 +72,7 @@ return {
       end,
     },
   },
-  document_highlight = true,
+  document_highlight = false,
   code_lens_refresh = true,
   float = {
     focusable = true,

+ 3 - 0
lua/lvim/lsp/handlers.lua

@@ -12,6 +12,9 @@ function M.setup()
     float = lvim.lsp.diagnostics.float,
   }
   vim.diagnostic.config(config)
+  if not lvim.builtin.illuminate.active then
+    vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lvim.lsp.float)
+  end
   vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lvim.lsp.float)
 end
 

+ 1 - 10
lua/lvim/lsp/init.lua

@@ -60,15 +60,6 @@ function M.common_on_init(client, bufnr)
   end
 end
 
-local function attach_navic(client, bufnr)
-  vim.g.navic_silence = true
-  local status_ok, navic = pcall(require, "nvim-navic")
-  if not status_ok then
-    return
-  end
-  navic.attach(client, bufnr)
-end
-
 function M.common_on_attach(client, bufnr)
   if lvim.lsp.on_attach_callback then
     lvim.lsp.on_attach_callback(client, bufnr)
@@ -83,7 +74,7 @@ function M.common_on_attach(client, bufnr)
   end
   add_lsp_buffer_keybindings(bufnr)
   add_lsp_buffer_options(bufnr)
-  attach_navic(client, bufnr)
+  lu.setup_document_symbols(client, bufnr)
 end
 
 function M.get_common_opts()

+ 18 - 0
lua/lvim/lsp/utils.lua

@@ -1,6 +1,7 @@
 local M = {}
 
 local tbl = require "lvim.utils.table"
+local Log = require "lvim.core.log"
 
 function M.is_client_active(name)
   local clients = vim.lsp.get_active_clients()
@@ -82,6 +83,10 @@ function M.get_all_supported_filetypes()
 end
 
 function M.setup_document_highlight(client, bufnr)
+  if lvim.builtin.illuminate.active then
+    Log:debug "skipping setup for document_highlight, illuminate already active"
+    return
+  end
   local status_ok, highlight_supported = pcall(function()
     return client.supports_method "textDocument/documentHighlight"
   end)
@@ -114,6 +119,19 @@ function M.setup_document_highlight(client, bufnr)
   })
 end
 
+function M.setup_document_symbols(client, bufnr)
+  vim.g.navic_silence = false -- can be set to true to supress error
+  local symbols_supported = client.supports_method "textDocument/documentSymbol"
+  if not symbols_supported then
+    Log:debug("skipping setup for document_symbols, method not supported by " .. client.name)
+    return
+  end
+  local status_ok, navic = pcall(require, "nvim-navic")
+  if status_ok then
+    navic.attach(client, bufnr)
+  end
+end
+
 function M.setup_codelens_refresh(client, bufnr)
   local status_ok, codelens_supported = pcall(function()
     return client.supports_method "textDocument/codeLens"

+ 21 - 9
lua/lvim/plugins.lua

@@ -15,16 +15,11 @@ local core_plugins = {
     end,
   },
   {
-    "lunarvim/tokyonight.nvim",
+    "folke/tokyonight.nvim",
     config = function()
-      pcall(function()
-        if lvim and lvim.colorscheme == "tokyonight-night" then
-          require("tokyonight-night").setup()
-          lvim.builtin.lualine.options.theme = "tokyonight-night"
-        end
-      end)
+      require("lvim.core.theme").setup()
     end,
-    disable = lvim.colorscheme ~= "tokyonight-night",
+    disable = not vim.startswith(lvim.colorscheme, "tokyonight"),
   },
   {
     "rcarriga/nvim-notify",
@@ -208,7 +203,7 @@ local core_plugins = {
     config = function()
       require("lvim.core.breadcrumbs").setup()
     end,
-    -- disable = not lvim.builtin.breadcrumbs.active,
+    disable = not lvim.builtin.breadcrumbs.active,
   },
 
   {
@@ -267,6 +262,23 @@ local core_plugins = {
 
   {
     "RRethy/vim-illuminate",
+    setup = function()
+      require("lvim.core.illuminate").setup()
+    end,
+    disable = not lvim.builtin.illuminate.active,
+  },
+  {
+    "lunarvim/onedarker.nvim",
+    branch = "freeze",
+    config = function()
+      pcall(function()
+        if lvim and lvim.colorscheme == "onedarker" then
+          require("onedarker").setup()
+          lvim.builtin.lualine.options.theme = "onedarker"
+        end
+      end)
+    end,
+    disable = lvim.colorscheme ~= "onedarker",
   },
 }
 

+ 9 - 6
snapshots/default.json

@@ -68,6 +68,9 @@
   "nvim-lspconfig": {
     "commit": "f8b3c24"
   },
+  "nvim-navic": {
+    "commit": "202312e"
+  },
   "nvim-notify": {
     "commit": "7076ce8"
   },
@@ -83,8 +86,8 @@
   "nvim-web-devicons": {
     "commit": "2d02a56"
   },
-  "tokyonight.nvim": {
-    "commit": "4bd6ba8"
+  "onedarker.nvim": {
+    "commit": "b00dd21"
   },
   "packer.nvim": {
     "commit": "6afb674"
@@ -113,13 +116,13 @@
   "toggleterm.nvim": {
     "commit": "5e393e5"
   },
-  "which-key.nvim": {
-    "commit": "d5f0c63"
+  "tokyonight.nvim": {
+    "commit": "e0bdba5"
   },
   "vim-illuminate": {
     "commit": "b545262"
   },
-  "nvim-navic": {
-    "commit": "202312e"
+  "which-key.nvim": {
+    "commit": "d5f0c63"
   }
 }

+ 4 - 4
utils/ci/verify_plugins.lua

@@ -33,8 +33,7 @@ end
 local get_install_path = function(spec)
   local prefix = is_optional(spec) and packer_config.opt_dir or packer_config.start_dir
   local path = join_paths(prefix, get_short_name(spec))
-  assert(is_directory(path))
-  return path
+  return is_directory(path) and path
 end
 
 local function call_proc(process, opts, cb)
@@ -92,11 +91,12 @@ end
 
 local function verify_core_plugins(verbose)
   for _, spec in pairs(core_plugins) do
-    if not spec.disable then
+    local path = get_install_path(spec)
+    if not spec.disable and path then
       table.insert(collection, {
         name = get_short_name(spec),
         commit = get_default_sha1(spec),
-        path = get_install_path(spec),
+        path = path,
       })
     end
   end

+ 5 - 2
utils/installer/config.example.lua

@@ -11,7 +11,7 @@ an executable
 -- general
 lvim.log.level = "warn"
 lvim.format_on_save = true
-lvim.colorscheme = "onedarker"
+lvim.colorscheme = "tokyonight"
 -- to disable icons and use a minimalist setup, uncomment the following
 -- lvim.use_icons = false
 
@@ -44,6 +44,10 @@ lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
 --   },
 -- }
 
+-- Change theme settings
+-- lvim.builtin.theme.options.dim_inactive = true
+-- lvim.builtin.theme.options.style = "storm"
+
 -- 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"] = {
@@ -161,7 +165,6 @@ lvim.builtin.treesitter.highlight.enable = true
 
 -- Additional Plugins
 -- lvim.plugins = {
---     {"folke/tokyonight.nvim"},
 --     {
 --       "folke/trouble.nvim",
 --       cmd = "TroubleToggle",

+ 5 - 2
utils/installer/config_win.example.lua

@@ -28,7 +28,7 @@ vim.g.clipboard = {
 -- general
 lvim.log.level = "warn"
 lvim.format_on_save = true
-lvim.colorscheme = "onedarker"
+lvim.colorscheme = "tokyonight"
 -- to disable icons and use a minimalist setup, uncomment the following
 -- lvim.use_icons = false
 
@@ -61,6 +61,10 @@ lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
 --   },
 -- }
 
+-- Change theme settings
+-- lvim.builtin.theme.options.dim_inactive = true
+-- lvim.builtin.theme.options.style = "storm"
+
 -- 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"] = {
@@ -176,7 +180,6 @@ lvim.builtin.treesitter.highlight.enable = true
 
 -- Additional Plugins
 -- lvim.plugins = {
---     {"folke/tokyonight.nvim"},
 --     {
 --       "folke/trouble.nvim",
 --       cmd = "TroubleToggle",