ソースを参照

Merge remote-tracking branch 'origin/rolling'

kylo252 3 年 前
コミット
1f2167df0e

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

@@ -28,7 +28,7 @@ return {
         float_opts = {},
       },
     },
-    ---@usage set to false to restore the default behavior of vim.notify
-    override_notify = true,
+    -- currently disabled due to instabilities
+    override_notify = false,
   },
 }

+ 19 - 108
lua/lvim/config/init.lua

@@ -33,120 +33,31 @@ function M:init()
   local lvim_lsp_config = require "lvim.lsp.config"
   lvim.lsp = vim.deepcopy(lvim_lsp_config)
 
-  local supported_languages = {
-    "asm",
-    "bash",
-    "beancount",
-    "bibtex",
-    "bicep",
-    "c",
-    "c_sharp",
-    "clojure",
-    "cmake",
-    "comment",
-    "commonlisp",
-    "cpp",
-    "crystal",
-    "cs",
-    "css",
-    "cuda",
-    "d",
-    "dart",
-    "dockerfile",
-    "dot",
-    "elixir",
-    "elm",
-    "emmet",
-    "erlang",
-    "fennel",
-    "fish",
-    "fortran",
-    "gdscript",
-    "glimmer",
-    "go",
-    "gomod",
-    "graphql",
-    "haskell",
-    "hcl",
-    "heex",
-    "html",
-    "java",
-    "javascript",
-    "javascriptreact",
-    "jsdoc",
-    "json",
-    "json5",
-    "jsonc",
-    "julia",
-    "kotlin",
-    "latex",
-    "ledger",
-    "less",
-    "lua",
-    "markdown",
-    "nginx",
-    "nix",
-    "ocaml",
-    "ocaml_interface",
-    "perl",
-    "php",
-    "pioasm",
-    "ps1",
-    "puppet",
-    "python",
-    "ql",
-    "query",
-    "r",
-    "regex",
-    "rst",
-    "ruby",
-    "rust",
-    "scala",
-    "scss",
-    "sh",
-    "solidity",
-    "sparql",
-    "sql",
-    "supercollider",
-    "surface",
-    "svelte",
-    "swift",
-    "tailwindcss",
-    "terraform",
-    "tex",
-    "tlaplus",
-    "toml",
-    "tsx",
-    "turtle",
-    "typescript",
-    "typescriptreact",
-    "verilog",
-    "vim",
-    "vue",
-    "yaml",
-    "yang",
-    "zig",
-  }
-
+  local supported_languages = require "lvim.config.supported_languages"
   require("lvim.lsp.manager").init_defaults(supported_languages)
 end
 
-local function deprecation_notice()
-  local in_headless = #vim.api.nvim_list_uis() == 0
-  if in_headless then
-    return
+local function handle_deprecated_settings()
+  local function deprecation_notice(setting)
+    local in_headless = #vim.api.nvim_list_uis() == 0
+    if in_headless then
+      return
+    end
+
+    local msg = string.format(
+      "Deprecation notice: [%s] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
+      setting
+    )
+    vim.schedule(function()
+      vim.notify(msg, vim.log.levels.WARN)
+    end)
   end
 
+  ---lvim.lang.FOO.lsp
   for lang, entry in pairs(lvim.lang) do
-    local deprecated_config = entry["lvim.lsp"] or {}
+    local deprecated_config = entry["lsp"] or {}
     if not vim.tbl_isempty(deprecated_config) then
-      local msg = string.format(
-        "Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
-        lang
-      )
-      vim.schedule(function()
-        vim.notify(msg, vim.log.levels.WARN)
-      end)
+      deprecation_notice(string.format("lvim.lang.%s.lsp", lang))
     end
   end
 end
@@ -165,7 +76,7 @@ function M:load(config_path)
     end
   end
 
-  deprecation_notice()
+  handle_deprecated_settings()
 
   autocmds.define_augroups(lvim.autocommands)
 

+ 94 - 0
lua/lvim/config/supported_languages.lua

@@ -0,0 +1,94 @@
+return {
+  "asm",
+  "bash",
+  "beancount",
+  "bibtex",
+  "bicep",
+  "c",
+  "c_sharp",
+  "clojure",
+  "cmake",
+  "comment",
+  "commonlisp",
+  "cpp",
+  "crystal",
+  "cs",
+  "css",
+  "cuda",
+  "d",
+  "dart",
+  "dockerfile",
+  "dot",
+  "elixir",
+  "elm",
+  "emmet",
+  "erlang",
+  "fennel",
+  "fish",
+  "fortran",
+  "gdscript",
+  "glimmer",
+  "go",
+  "gomod",
+  "graphql",
+  "haskell",
+  "hcl",
+  "heex",
+  "html",
+  "java",
+  "javascript",
+  "javascriptreact",
+  "jsdoc",
+  "json",
+  "json5",
+  "jsonc",
+  "julia",
+  "kotlin",
+  "latex",
+  "ledger",
+  "less",
+  "lua",
+  "markdown",
+  "nginx",
+  "nix",
+  "ocaml",
+  "ocaml_interface",
+  "perl",
+  "php",
+  "pioasm",
+  "ps1",
+  "puppet",
+  "python",
+  "ql",
+  "query",
+  "r",
+  "regex",
+  "rst",
+  "ruby",
+  "rust",
+  "scala",
+  "scss",
+  "sh",
+  "solidity",
+  "sparql",
+  "sql",
+  "supercollider",
+  "surface",
+  "svelte",
+  "swift",
+  "tailwindcss",
+  "terraform",
+  "tex",
+  "tlaplus",
+  "toml",
+  "tsx",
+  "turtle",
+  "typescript",
+  "typescriptreact",
+  "verilog",
+  "vim",
+  "vue",
+  "yaml",
+  "yang",
+  "zig",
+}

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

@@ -15,6 +15,7 @@ local builtins = {
   "lvim.core.bufferline",
   "lvim.core.autopairs",
   "lvim.core.comment",
+  "lvim.core.notify",
   "lvim.core.lualine",
 }
 

+ 42 - 39
lua/lvim/core/log.lua

@@ -18,22 +18,22 @@ function Log:init()
     return nil
   end
 
-  local nvim_notify_params = {}
-  local nvim_notify_params_injecter = function(_, entry)
-    for key, value in pairs(nvim_notify_params) do
-      entry[key] = value
+  local notify_handler = require "lvim.core.notify"
+
+  ---Check if notify is available
+  ---@return boolean
+  local is_notify_available = function()
+    local in_headless = #vim.api.nvim_list_uis() == 0
+    --We can't rely on lvim.builtin.notify.active since this can be used before the config loader
+    local has_notify_plugin = pcall(require, "notify")
+    if not in_headless and has_notify_plugin then
+      return true
     end
-    return entry
+    return false
   end
 
-  local nvim_notify_default_namer = function(logger, entry)
-    entry["title"] = logger.name
-    return entry
-  end
-
-  nvim_notify_params_injecter(nil, {})
   local log_level = Log.levels[(lvim.log.level):upper() or "WARN"]
-  structlog.configure {
+  local lvim_log = {
     lvim = {
       sinks = {
         structlog.sinks.Console(log_level, {
@@ -49,25 +49,6 @@ function Log:init()
             { level = structlog.formatters.FormatColorizer.color_level() }
           ),
         }),
-        structlog.sinks.NvimNotify(Log.levels.INFO, {
-          processors = {
-            nvim_notify_default_namer,
-            nvim_notify_params_injecter,
-          },
-          formatter = structlog.formatters.Format( --
-            "%s",
-            { "msg" },
-            { blacklist_all = true }
-          ),
-          params_map = {
-            icon = "icon",
-            keep = "keep",
-            on_open = "on_open",
-            on_close = "on_close",
-            timeout = "timeout",
-            title = "title",
-          },
-        }),
         structlog.sinks.File(Log.levels.TRACE, logfile, {
           processors = {
             structlog.processors.Namer(),
@@ -83,15 +64,37 @@ function Log:init()
     },
   }
 
+  if is_notify_available() then
+    table.insert(
+      lvim_log.lvim.sinks,
+      structlog.sinks.NvimNotify(Log.levels.INFO, {
+        processors = {
+          notify_handler.default_namer,
+          notify_handler.params_injecter,
+        },
+        formatter = structlog.formatters.Format( --
+          "%s",
+          { "msg" },
+          { blacklist_all = true }
+        ),
+        params_map = {
+          icon = "icon",
+          keep = "keep",
+          on_open = "on_open",
+          on_close = "on_close",
+          timeout = "timeout",
+          title = "title",
+        },
+      })
+    )
+  end
+
+  structlog.configure(lvim_log)
+
   local logger = structlog.get_logger "lvim"
 
   if lvim.log.override_notify then
-    -- Overwrite vim.notify to use the logger
-    vim.notify = function(msg, vim_log_level, opts)
-      nvim_notify_params = opts or {}
-      -- https://github.com/neovim/neovim/blob/685cf398130c61c158401b992a1893c2405cd7d2/runtime/lua/vim/lsp/log.lua#L5
-      logger:log(vim_log_level + 1, msg)
-    end
+    logger:log(Log.levels.INFO, "Ignoring request to override vim.notify with structlog due to instabilities")
   end
 
   return logger
@@ -102,7 +105,7 @@ end
 ---@param level string [same as vim.log.log_levels]
 function Log:add_entry(level, msg, event)
   if self.__handle then
-    self.__handle:log(level, msg, event)
+    self.__handle:log(level, vim.inspect(msg), event)
     return
   end
 
@@ -112,7 +115,7 @@ function Log:add_entry(level, msg, event)
   end
 
   self.__handle = logger
-  self.__handle:log(level, msg, event)
+  self.__handle:log(level, vim.inspect(msg), event)
 end
 
 ---Retrieves the path of the logfile

+ 6 - 3
lua/lvim/core/lualine/components.lua

@@ -122,11 +122,14 @@ return {
   progress = { "progress", cond = conditions.hide_in_width, color = {} },
   spaces = {
     function()
-      local label = "Spaces: "
       if not vim.api.nvim_buf_get_option(0, "expandtab") then
-        label = "Tab size: "
+        return "Tab size: " .. vim.api.nvim_buf_get_option(0, "tabstop") .. " "
       end
-      return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
+      local size = vim.api.nvim_buf_get_option(0, "shiftwidth")
+      if size == 0 then
+        size = vim.api.nvim_buf_get_option(0, "tabstop")
+      end
+      return "Spaces: " .. size .. " "
     end,
     cond = conditions.hide_in_width,
     color = {},

+ 45 - 0
lua/lvim/core/notify.lua

@@ -0,0 +1,45 @@
+local M = {}
+
+function M.config()
+  local pallete = require "onedarker.palette"
+
+  lvim.builtin.notify = {
+    active = false,
+    on_config_done = nil,
+    -- TODO: update after https://github.com/rcarriga/nvim-notify/pull/24
+    opts = {
+      ---@usage Animation style one of { "fade", "slide", "fade_in_slide_out", "static" }
+      stages = "slide",
+
+      ---@usage timeout for notifications in ms, default 5000
+      timeout = 5000,
+
+      ---@usage highlight behind the window for stages that change opacity
+      background_colour = pallete.fg,
+
+      ---@usage Icons for the different levels
+      icons = {
+        ERROR = "",
+        WARN = "",
+        INFO = "",
+        DEBUG = "",
+        TRACE = "✎",
+      },
+    },
+  }
+end
+
+M.params_injecter = function(_, entry)
+  -- FIXME: this is currently getting ignored or is not passed correctly
+  for key, value in pairs(lvim.builtin.notify.opts) do
+    entry[key] = value
+  end
+  return entry
+end
+
+M.default_namer = function(logger, entry)
+  entry["title"] = logger.name
+  return entry
+end
+
+return M

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

@@ -15,7 +15,6 @@ return {
     underline = true,
     severity_sort = true,
   },
-  override = {},
   document_highlight = true,
   code_lens_refresh = true,
   popup_border = "single",
@@ -42,4 +41,18 @@ return {
   null_ls = {
     setup = {},
   },
+  override = {
+    "angularls",
+    "ansiblels",
+    "denols",
+    "ember",
+    "jedi_language_server",
+    "pylsp",
+    "rome",
+    "sqlls",
+    "sqls",
+    "stylelint_lsp",
+    "tailwindcss",
+    "volar",
+  },
 }

+ 2 - 11
lua/lvim/lsp/manager.lua

@@ -1,7 +1,7 @@
 local M = {}
 
 local Log = require "lvim.core.log"
-local lsp_utils = require "lvim.lsp.utils"
+local lvim_lsp_utils = require "lvim.lsp.utils"
 
 function M.init_defaults(languages)
   for _, entry in ipairs(languages) do
@@ -15,15 +15,6 @@ function M.init_defaults(languages)
   end
 end
 
-local function is_overridden(server)
-  local overrides = lvim.lsp.override
-  if type(overrides) == "table" then
-    if vim.tbl_contains(overrides, server) then
-      return true
-    end
-  end
-end
-
 ---Resolve the configuration for a server based on both common and user configuration
 ---@param name string
 ---@param user_config table [optional]
@@ -54,7 +45,7 @@ end
 function M.setup(server_name, user_config)
   vim.validate { name = { server_name, "string" } }
 
-  if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then
+  if lvim_lsp_utils.is_client_active(server_name) then
     return
   end
 

+ 5 - 33
lua/lvim/lsp/templates.lua

@@ -2,7 +2,7 @@ local M = {}
 
 local Log = require "lvim.core.log"
 local utils = require "lvim.utils"
-local get_supported_filetypes = require("lvim.lsp.utils").get_supported_filetypes
+local lvim_lsp_utils = require "lvim.lsp.utils"
 
 local ftplugin_dir = lvim.lsp.templates_dir
 
@@ -15,48 +15,20 @@ function M.remove_template_files()
   end
 end
 
----Checks if a server is ignored by default because of a conflict
----Only TSServer is enabled by default for the javascript-family
----@param server_name string
-function M.is_ignored(server_name, filetypes)
-  --TODO: this is easy to be made configurable once stable
-  filetypes = filetypes or get_supported_filetypes(server_name)
-
-  if vim.tbl_contains(filetypes, "javascript") then
-    if server_name == "tsserver" then
-      return false
-    else
-      return true
-    end
-  end
-
-  local blacklist = {
-    "jedi_language_server",
-    "pylsp",
-    "sqlls",
-    "sqls",
-    "angularls",
-    "ansiblels",
-  }
-  return vim.tbl_contains(blacklist, server_name)
-end
-
 ---Generates an ftplugin file based on the server_name in the selected directory
 ---@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)
-  -- we need to go through lspconfig to get the corresponding filetypes currently
-  local filetypes = get_supported_filetypes(server_name) or {}
-  if not filetypes then
+  if vim.tbl_contains(lvim.lsp.override, server_name) then
     return
   end
 
-  if M.is_ignored(server_name, filetypes) then
+  -- we need to go through lspconfig to get the corresponding filetypes currently
+  local filetypes = lvim_lsp_utils.get_supported_filetypes(server_name) or {}
+  if not filetypes then
     return
   end
 
-  -- print("got associated filetypes: " .. vim.inspect(filetypes))
-
   for _, filetype in ipairs(filetypes) do
     local filename = join_paths(dir, filetype .. ".lua")
     local setup_cmd = string.format([[require("lvim.lsp.manager").setup(%q)]], server_name)

+ 6 - 5
lua/lvim/plugins.lua

@@ -8,7 +8,10 @@ return {
   {
     "williamboman/nvim-lsp-installer",
   },
-  { "rcarriga/nvim-notify" },
+  {
+    "rcarriga/nvim-notify",
+    disable = not lvim.builtin.notify.active,
+  },
   { "Tastyep/structlog.nvim" },
 
   { "nvim-lua/popup.nvim" },
@@ -96,10 +99,8 @@ return {
   },
 
   -- Whichkey
-  -- TODO: change back to folke/which-key.nvim after folke got back
   {
-    "abzcoding/which-key.nvim",
-    branch = "fix/neovim-6-position",
+    "folke/which-key.nvim",
     config = function()
       require("lvim.core.which-key").setup()
     end,
@@ -132,7 +133,7 @@ return {
   -- Status Line and Bufferline
   {
     -- "hoob3rt/lualine.nvim",
-    "shadmansaleh/lualine.nvim",
+    "nvim-lualine/lualine.nvim",
     -- "Lunarvim/lualine.nvim",
     config = function()
       require("lvim.core.lualine").setup()

+ 24 - 0
lua/onedarker/Notify.lua

@@ -0,0 +1,24 @@
+local Notify = {
+  NotifyERRORBorder = { fg = C.error_red },
+  NotifyWARNBorder = { fg = C.warning_orange },
+  NotifyINFOBorder = { fg = C.green },
+  NotifyDEBUGBorder = { fg = C.purple_test },
+  NotifyTRACEBorder = { fg = C.purple },
+  NotifyERRORIcon = { fg = C.error_red },
+  NotifyWARNIcon = { fg = C.warning_orange },
+  NotifyINFOIcon = { fg = C.green },
+  NotifyDEBUGIcon = { fg = C.purple_test },
+  NotifyTRACEIcon = { fg = C.purple },
+  NotifyERRORTitle = { fg = C.error_red },
+  NotifyWARNTitle = { fg = C.warning_orange },
+  NotifyINFOTitle = { fg = C.green },
+  NotifyDEBUGTitle = { fg = C.purple_test },
+  NotifyTRACETitle = { fg = C.purple },
+  NotifyERRORBody = { fg = C.fg },
+  NotifyWARNBody = { fg = C.fg },
+  NotifyINFOBody = { fg = C.fg },
+  NotifyDEBUGBody = { fg = C.fg },
+  NotifyTRACEBody = { fg = C.fg },
+}
+
+return Notify

+ 1 - 1
lua/onedarker/highlights.lua

@@ -42,7 +42,7 @@ local highlights = {
   CursorIM = { fg = C.cursor_fg, bg = C.cursor_bg },
   TermCursor = { fg = C.cursor_fg, bg = C.cursor_bg },
   TermCursorNC = { fg = C.cursor_fg, bg = C.cursor_bg },
-  Conceal = { fg = C.accent },
+  Conceal = { fg = C.accent, bg = Config.transparent_background and "NONE" or C.bg },
   Directory = { fg = C.blue },
   SpecialKey = { fg = C.blue, style = "bold" },
   Title = { fg = C.blue, style = "bold" },

+ 2 - 0
lua/onedarker/init.lua

@@ -13,6 +13,7 @@ local highlights = require "onedarker.highlights"
 local Treesitter = require "onedarker.Treesitter"
 local markdown = require "onedarker.markdown"
 local Whichkey = require "onedarker.Whichkey"
+local Notify = require "onedarker.Notify"
 local Git = require "onedarker.Git"
 local LSP = require "onedarker.LSP"
 local diff = require "onedarker.diff"
@@ -22,6 +23,7 @@ local skeletons = {
   Treesitter,
   markdown,
   Whichkey,
+  Notify,
   Git,
   LSP,
   diff,

+ 1 - 18
tests/lsp_spec.lua

@@ -67,29 +67,12 @@ a.describe("lsp workflow", function()
     assert.True(vim.deep_equal(tsserver.filetypes, tsserver_fts))
   end)
 
-  a.it("shoud ignore all javascript servers except tsserver and tailwindcss when generating templates", function()
-    local test_server = { name = "denols", filetypes = {} }
-    test_server.filetypes = require("lvim.lsp.utils").get_supported_filetypes(test_server.name)
-
-    assert.True(vim.tbl_contains(test_server.filetypes, "javascript"))
-
-    local is_ignored = require("lvim.lsp.templates").is_ignored(test_server.name)
-    assert.True(is_ignored)
-
-    local ts_template = utils.join_paths(lvim.lsp.templates_dir, "typescript.lua")
-
-    assert.True(utils.file_contains(ts_template, "tsserver"))
-    assert.False(utils.file_contains(ts_template, test_server.name))
-  end)
-
   a.it("shoud not include blacklisted servers in the generated templates", function()
     assert.True(utils.is_directory(lvim.lsp.templates_dir))
     require("lvim.lsp").setup()
 
-    local blacklisted = { "jedi_language_server", "pylsp", "sqlls", "sqls", "angularls", "ansiblels" }
-
     for _, file in ipairs(vim.fn.glob(lvim.lsp.templates_dir .. "/*.lua", 1, 1)) do
-      for _, server in ipairs(blacklisted) do
+      for _, server in ipairs(lvim.lsp.override) do
         assert.False(utils.file_contains(file, server))
       end
     end