Sfoglia il codice sorgente

refactor: replace deprecated API calls (#4568)

* chore: bump plugins version

* refactor: replace deprecated API calls

* chore(lsp): update skipped servers list

* ci: update workflows

* ci: update release names in installer script

* ci: use action-setup-vim
kylo252 1 anno fa
parent
commit
3715ae645d

+ 1 - 1
.github/workflows/commitlint.yml

@@ -17,7 +17,7 @@ jobs:
       PR_NUMBER: ${{ github.event.pull_request.number }}
       PR_TITLE: ${{ github.event.pull_request.title }}
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - name: install commitlint
         run: |
           npm install --save-dev @commitlint/cli

+ 7 - 7
.github/workflows/format.yaml

@@ -13,9 +13,9 @@ on:
 jobs:
   stylua-check:
     name: "Formatting check with Stylua"
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Lint with stylua
         uses: JohnnyMorganz/stylua-action@v2
@@ -27,18 +27,18 @@ jobs:
 
   shfmt-check:
     name: "Formatting check with shfmt"
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Setup Go
-        uses: actions/setup-go@v3
+        uses: actions/setup-go@v5
         with:
-          go-version: "1.18"
+          go-version: '^1.21'
 
       - name: Use shfmt
         run: |
-          go install mvdan.cc/sh/v3/cmd/shfmt@v3.6
+          go install mvdan.cc/sh/v3/cmd/shfmt@latest
 
       # https://google.github.io/styleguide/shellguide.html
       - name: Check formatting

+ 10 - 11
.github/workflows/install.yaml

@@ -21,10 +21,10 @@ jobs:
         include:
           - runner: ubuntu-latest
             os: linux
-            neovim: v0.9.5
+            neovim: v0.10.0
           - runner: macos-latest
             os: osx
-            neovim: v0.9.5
+            neovim: v0.10.0
           - runner: ubuntu-22.04
             os: linux
             neovim: nightly
@@ -33,14 +33,13 @@ jobs:
             neovim: nightly
     runs-on: ${{ matrix.runner }}
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
-      - name: Install neovim binary from release
-        env:
-          RELEASE_VER: ${{ matrix.neovim }}
-        run: |
-          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
-          bash ./utils/installer/install-neovim-from-release
+      - name: Install neovim binary
+        uses: rhysd/action-setup-vim@v1
+        with:
+          neovim: true
+          version: ${{ matrix.neovim }}
 
       - name: Install LunarVim
         timeout-minutes: 4
@@ -72,13 +71,13 @@ jobs:
         shell: pwsh
     steps:
       # it's not currently possbile to run tests on windows, see nvim-lua/plenary.nvim#255
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Install neovim binary
         uses: rhysd/action-setup-vim@v1
         with:
           neovim: true
-          version: v0.9.1
+          version: v0.10.0
 
       - name: Install LunarVim
         timeout-minutes: 4

+ 3 - 3
.github/workflows/lint.yaml

@@ -13,9 +13,9 @@ on:
 jobs:
   lua-linter:
     name: "Linting with luacheck"
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - uses: leafo/gh-actions-lua@v8
       - uses: leafo/gh-actions-luarocks@v4
@@ -30,7 +30,7 @@ jobs:
     name: Shellcheck
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - name: Run ShellCheck
         uses: ludeeus/action-shellcheck@master
         with:

+ 1 - 1
.github/workflows/plugins.yml

@@ -26,7 +26,7 @@ jobs:
       contents: write
       pull-requests: write
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Install neovim binary
         uses: rhysd/action-setup-vim@v1

+ 2 - 2
lua/lvim/bootstrap.lua

@@ -1,7 +1,7 @@
 local M = {}
 
-if vim.fn.has "nvim-0.9" ~= 1 then
-  vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.9+", vim.log.levels.WARN)
+if vim.fn.has "nvim-0.10" ~= 1 then
+  vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.10+", vim.log.levels.WARN)
   vim.wait(5000, function()
     ---@diagnostic disable-next-line: redundant-return-value
     return false

+ 1 - 1
lua/lvim/core/alpha/dashboard.lua

@@ -89,7 +89,7 @@ function M.get_sections()
     val = function()
       local alpha_wins = vim.tbl_filter(function(win)
         local buf = vim.api.nvim_win_get_buf(win)
-        return vim.api.nvim_buf_get_option(buf, "filetype") == "alpha"
+        return vim.api.nvim_get_option_value("filetype", { buf = buf }) == "alpha"
       end, vim.api.nvim_list_wins())
 
       if vim.api.nvim_win_get_height(alpha_wins[#alpha_wins]) < 36 then

+ 7 - 7
lua/lvim/core/autocmds.lua

@@ -105,17 +105,17 @@ function M.load_defaults()
           if lvim.builtin.breadcrumbs.active then
             require("lvim.core.breadcrumbs").get_winbar()
           end
-          local statusline_hl = vim.api.nvim_get_hl_by_name("StatusLine", true)
-          local cursorline_hl = vim.api.nvim_get_hl_by_name("CursorLine", true)
-          local normal_hl = vim.api.nvim_get_hl_by_name("Normal", true)
+          local statusline_hl = vim.api.nvim_get_hl(0, { name = "StatusLine" })
+          local cursorline_hl = vim.api.nvim_get_hl(0, { name = "CursorLine" })
+          local normal_hl = vim.api.nvim_get_hl(0, { name = "Normal" })
           vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
           vim.api.nvim_set_hl(0, "CmpItemKindTabnine", { fg = "#CA42F0" })
           vim.api.nvim_set_hl(0, "CmpItemKindCrate", { fg = "#F64D00" })
           vim.api.nvim_set_hl(0, "CmpItemKindEmoji", { fg = "#FDE030" })
-          vim.api.nvim_set_hl(0, "SLCopilot", { fg = "#6CC644", bg = statusline_hl.background })
-          vim.api.nvim_set_hl(0, "SLGitIcon", { fg = "#E8AB53", bg = cursorline_hl.background })
-          vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.foreground, bg = cursorline_hl.background })
-          vim.api.nvim_set_hl(0, "SLSeparator", { fg = cursorline_hl.background, bg = statusline_hl.background })
+          vim.api.nvim_set_hl(0, "SLCopilot", { fg = "#6CC644", bg = statusline_hl.bg })
+          vim.api.nvim_set_hl(0, "SLGitIcon", { fg = "#E8AB53", bg = cursorline_hl.bg })
+          vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.fg, bg = cursorline_hl.bg })
+          vim.api.nvim_set_hl(0, "SLSeparator", { fg = cursorline_hl.fg, bg = statusline_hl.bg })
         end,
       },
     },

+ 13 - 12
lua/lvim/core/breadcrumbs.lua

@@ -1,7 +1,6 @@
 local M = {}
 
 -- local Log = require "lvim.core.log"
-
 local icons = lvim.icons.kind
 
 M.config = function()
@@ -94,18 +93,21 @@ M.setup = function()
   end
 end
 
+local function isempty(s)
+  return s == nil or s == ""
+end
+
 M.get_filename = function()
   local filename = vim.fn.expand "%:t"
   local extension = vim.fn.expand "%:e"
-  local f = require "lvim.utils.functions"
 
-  if not f.isempty(filename) then
+  if not isempty(filename) then
     local file_icon, hl_group
     local devicons_ok, devicons = pcall(require, "nvim-web-devicons")
     if lvim.use_icons and devicons_ok then
       file_icon, hl_group = devicons.get_icon(filename, extension, { default = true })
 
-      if f.isempty(file_icon) then
+      if isempty(file_icon) then
         file_icon = lvim.icons.kind.File
       end
     else
@@ -135,8 +137,8 @@ M.get_filename = function()
     --   file_icon = lvim.icons.ui.DebugConsole
     -- end
 
-    local navic_text = vim.api.nvim_get_hl_by_name("Normal", true)
-    vim.api.nvim_set_hl(0, "Winbar", { fg = navic_text.foreground })
+    local navic_text_hl = vim.api.nvim_get_hl(0, { name = "Normal" })
+    vim.api.nvim_set_hl(0, "Winbar", { fg = navic_text_hl.fg })
 
     return " " .. "%#" .. hl_group .. "#" .. file_icon .. "%*" .. " " .. "%#Winbar#" .. filename .. "%*"
   end
@@ -157,7 +159,7 @@ local get_gps = function()
     return ""
   end
 
-  if not require("lvim.utils.functions").isempty(gps_location) then
+  if not isempty(gps_location) then
     return "%#NavicSeparator#" .. lvim.icons.ui.ChevronRight .. "%* " .. gps_location
   else
     return ""
@@ -172,19 +174,18 @@ M.get_winbar = function()
   if excludes() then
     return
   end
-  local f = require "lvim.utils.functions"
   local value = M.get_filename()
 
   local gps_added = false
-  if not f.isempty(value) then
+  if not isempty(value) then
     local gps_value = get_gps()
     value = value .. " " .. gps_value
-    if not f.isempty(gps_value) then
+    if not isempty(gps_value) then
       gps_added = true
     end
   end
 
-  if not f.isempty(value) and f.get_buf_option "mod" then
+  if not isempty(value) and vim.api.nvim_get_option_value("mod", { buf = 0 }) then
     -- TODO: replace with circle
     local mod = "%#LspCodeLens#" .. lvim.icons.ui.Circle .. "%*"
     if gps_added then
@@ -196,7 +197,7 @@ M.get_winbar = function()
 
   local num_tabs = #vim.api.nvim_list_tabpages()
 
-  if num_tabs > 1 and not f.isempty(value) then
+  if num_tabs > 1 and not isempty(value) then
     local tabpage_number = tostring(vim.api.nvim_tabpage_get_number(0))
     value = value .. "%=" .. tabpage_number .. "/" .. tostring(num_tabs)
   end

+ 1 - 1
lua/lvim/core/bufferline.lua

@@ -207,7 +207,7 @@ function M.buf_kill(kill_command, bufnr, force)
         force = true
       else return
       end
-    elseif api.nvim_buf_get_option(bufnr, "buftype") == "terminal" then
+    elseif api.nvim_get_option_value("buftype", { buf = 0 }) == "terminal" then
       choice = fn.confirm(fmt([[Close "%s"?]], bufname), "&Yes\n&No\n&Cancel")
       if choice == 1 then
         force = true

+ 1 - 1
lua/lvim/core/cmp.lua

@@ -134,7 +134,7 @@ M.config = function()
     active = true,
     on_config_done = nil,
     enabled = function()
-      local buftype = vim.api.nvim_buf_get_option(0, "buftype")
+      local buftype = vim.api.nvim_get_option_value("buftype", { buf = 0 })
       if buftype == "prompt" then
         return false
       end

+ 1 - 1
lua/lvim/core/dap.lua

@@ -148,7 +148,7 @@ M.setup_ui = function()
       title = "dap-ui",
       icon = "",
       on_open = function(win)
-        vim.api.nvim_buf_set_option(vim.api.nvim_win_get_buf(win), "filetype", "markdown")
+        vim.api.nvim_set_option_value("filetype", "markdown", { buf = vim.api.nvim_win_get_buf(win) })
       end,
     })
 

+ 1 - 1
lua/lvim/core/info.lua

@@ -126,7 +126,7 @@ local function make_auto_lsp_info(ft)
 end
 
 function M.toggle_popup(ft)
-  local clients = vim.lsp.get_active_clients()
+  local clients = vim.lsp.get_clients()
   local client_names = {}
   local bufnr = vim.api.nvim_get_current_buf()
   local ts_active_buffers = vim.tbl_keys(vim.treesitter.highlighter.active)

+ 4 - 4
lua/lvim/core/lir.lua

@@ -81,19 +81,19 @@ function M.icon_setup()
   end
 
   local function get_hl_by_name(name)
-    local ret = vim.api.nvim_get_hl_by_name(name.group, true)
+    local ret = vim.api.nvim_get_hl(0, { name = name.group })
     return string.format("#%06x", ret[name.property])
   end
 
-  local found, icon_hl = pcall(get_hl_by_name, { group = "NvimTreeFolderIcon", property = "foreground" })
+  local found, icon_color = pcall(get_hl_by_name, { group = "NvimTreeFolderIcon", property = "fg" })
   if not found then
-    icon_hl = "#42A5F5"
+    icon_color = "#42A5F5"
   end
 
   devicons.set_icon {
     lir_folder_icon = {
       icon = lvim.builtin.lir.icon,
-      color = icon_hl,
+      color = icon_color,
       name = "LirFolderNode",
     },
   }

+ 2 - 2
lua/lvim/core/lualine/components.lua

@@ -93,7 +93,7 @@ return {
   },
   lsp = {
     function()
-      local buf_clients = vim.lsp.get_active_clients { bufnr = 0 }
+      local buf_clients = vim.lsp.get_clients { bufnr = 0 }
       if #buf_clients == 0 then
         return "LSP Inactive"
       end
@@ -146,7 +146,7 @@ return {
 
   spaces = {
     function()
-      local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
+      local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { buf = 0 })
       return lvim.icons.ui.Tab .. " " .. shiftwidth
     end,
     padding = 1,

+ 2 - 2
lua/lvim/interface/popup.lua

@@ -52,12 +52,12 @@ function Popup:display(content_provider)
 
   -- window options
   for key, value in pairs(self.win_opts) do
-    vim.api.nvim_win_set_option(self.win_id or 0, key, value)
+    vim.api.nvim_set_option_value(key, value, { win = self.win_id or 0, scope = "local" })
   end
 
   -- buffer options
   for key, value in pairs(self.buf_opts) do
-    vim.api.nvim_buf_set_option(self.buffer, key, value)
+    vim.api.nvim_set_option_value(key, value, { buf = self.buffer })
   end
 end
 

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

@@ -6,7 +6,9 @@ local skipped_servers = {
   "azure_pipelines_ls",
   "basedpyright",
   "biome",
+  "bzl",
   "ccls",
+  "css_variables",
   "cssmodules_ls",
   "custom_elements_ls",
   "denols",
@@ -25,6 +27,7 @@ local skipped_servers = {
   "golangci_lint_ls",
   "gradle_ls",
   "graphql",
+  "harper_ls",
   "hdl_checker",
   "hydra_lsp",
   "htmx",
@@ -71,7 +74,9 @@ local skipped_servers = {
   "swift_mesonls",
   "templ",
   "tflint",
+  "tinymist",
   "unocss",
+  "vale_ls",
   "vacuum",
   "verible",
   "v_analyzer",

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

@@ -5,7 +5,7 @@ local autocmds = require "lvim.core.autocmds"
 
 local function add_lsp_buffer_options(bufnr)
   for k, v in pairs(lvim.lsp.buffer_options) do
-    vim.api.nvim_buf_set_option(bufnr, k, v)
+    vim.api.nvim_set_option_value(k, v, { buf = bufnr })
   end
 end
 

+ 2 - 2
lua/lvim/lsp/utils.lua

@@ -4,7 +4,7 @@ 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()
+  local clients = vim.lsp.get_clients()
   return tbl.find_first(clients, function(client)
     return client.name == name
   end)
@@ -12,7 +12,7 @@ end
 
 function M.get_active_clients_by_ft(filetype)
   local matches = {}
-  local clients = vim.lsp.get_active_clients()
+  local clients = vim.lsp.get_clients()
   for _, client in pairs(clients) do
     local supported_filetypes = client.config.filetypes or {}
     if client.name ~= "null-ls" and vim.tbl_contains(supported_filetypes, filetype) then

+ 0 - 16
lua/lvim/utils/functions.lua

@@ -1,16 +0,0 @@
-local M = {}
-
-function M.isempty(s)
-  return s == nil or s == ""
-end
-
-function M.get_buf_option(opt)
-  local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt)
-  if not status_ok then
-    return nil
-  else
-    return buf_option
-  end
-end
-
-return M

+ 21 - 21
snapshots/default.json

@@ -12,7 +12,7 @@
     "commit": "33eb067"
   },
   "bufferline.nvim": {
-    "commit": "73540cb"
+    "commit": "73edc1f"
   },
   "cmp-buffer": {
     "commit": "3022dbc"
@@ -21,7 +21,7 @@
     "commit": "d250c63"
   },
   "cmp-nvim-lsp": {
-    "commit": "5af77f5"
+    "commit": "39e2eda"
   },
   "cmp-path": {
     "commit": "91ff86c"
@@ -30,7 +30,7 @@
     "commit": "05a9ab2"
   },
   "friendly-snippets": {
-    "commit": "3e9a3f5"
+    "commit": "dd2fd12"
   },
   "gitsigns.nvim": {
     "commit": "805610a"
@@ -39,7 +39,7 @@
     "commit": "9637670"
   },
   "lazy.nvim": {
-    "commit": "bef521a"
+    "commit": "8f19915"
   },
   "lir.nvim": {
     "commit": "7a9d45d"
@@ -51,61 +51,61 @@
     "commit": "08bbc93"
   },
   "mason-lspconfig.nvim": {
-    "commit": "273fdde"
+    "commit": "a4caa0d"
   },
   "mason.nvim": {
-    "commit": "751b1fc"
+    "commit": "49ff59a"
   },
   "neodev.nvim": {
     "commit": "ce9a2e8"
   },
   "nlsp-settings.nvim": {
-    "commit": "707b431"
+    "commit": "d92035e"
   },
   "none-ls.nvim": {
     "commit": "3a48266"
   },
   "nvim-autopairs": {
-    "commit": "14e9737"
+    "commit": "c15de7e"
   },
   "nvim-cmp": {
-    "commit": "cd2cf0c"
+    "commit": "5260e5e"
   },
   "nvim-dap": {
-    "commit": "13ce59d"
+    "commit": "5a2f712"
   },
   "nvim-dap-ui": {
     "commit": "34160a7"
   },
   "nvim-lspconfig": {
-    "commit": "aa5f4f4"
+    "commit": "eadcee1"
   },
   "nvim-navic": {
     "commit": "8649f69"
   },
   "nvim-tree.lua": {
-    "commit": "64f61e4"
+    "commit": "2bc725a"
   },
   "nvim-treesitter": {
-    "commit": "d5a1c2b"
+    "commit": "30de5e7"
   },
   "nvim-ts-context-commentstring": {
-    "commit": "0bdccb9"
+    "commit": "cb06438"
   },
   "nvim-web-devicons": {
-    "commit": "5b90678"
+    "commit": "e37bb1f"
   },
   "onedarker.nvim": {
     "commit": "b00dd21"
   },
   "plenary.nvim": {
-    "commit": "08e3019"
+    "commit": "a3e3bc8"
   },
   "project.nvim": {
     "commit": "8c6bad7"
   },
   "schemastore.nvim": {
-    "commit": "8c46453"
+    "commit": "9a5992a"
   },
   "structlog.nvim": {
     "commit": "45b26a2"
@@ -114,16 +114,16 @@
     "commit": "9ef21b2"
   },
   "telescope.nvim": {
-    "commit": "6312868"
+    "commit": "d829aa6"
   },
   "toggleterm.nvim": {
-    "commit": "066cccf"
+    "commit": "fee58a0"
   },
   "tokyonight.nvim": {
-    "commit": "67afeaf"
+    "commit": "b9b494f"
   },
   "vim-illuminate": {
-    "commit": "e522e0d"
+    "commit": "5eeb795"
   },
   "which-key.nvim": {
     "commit": "4433e5e"

+ 2 - 2
tests/minimal_lsp.lua

@@ -41,8 +41,8 @@ _G.load_config = function()
   require("vim.lsp.log").set_format_func(vim.inspect)
   local nvim_lsp = require "lspconfig"
   local on_attach = function(_, bufnr)
-    local function buf_set_option(...)
-      vim.api.nvim_buf_set_option(bufnr, ...)
+    local function buf_set_option(k, v)
+      vim.api.nvim_set_option_value(k, v, { buf = bufnr })
     end
 
     buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")

+ 1 - 1
utils/ci/generate_new_lockfile.sh

@@ -11,7 +11,7 @@ mkdir -p "${SNAPSHOT_DIR}"
 export SNAPSHOT_PATH="${REPO_DIR}/snapshots/${SNAPSHOT_NAME}"
 
 time lvim --headless \
-  -c "luafile ./utils/ci/generate_new_lockfile.lua"
+  -c "source ./utils/ci/generate_new_lockfile.lua"
 
 temp=$(mktemp)
 

+ 2 - 15
utils/installer/install-neovim-from-release

@@ -6,23 +6,14 @@ declare -r LV_INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}"
 declare -r RELEASE_VER="${RELEASE_VER:-latest}" # can be set to nightly
 
 declare ARCHIVE_NAME
-declare RELEASE_NAME
 declare OS
 
 OS="$(uname -s)"
 
 if [ "$OS" == "Linux" ]; then
   ARCHIVE_NAME="nvim-linux64"
-  RELEASE_NAME="nvim-linux64"
 elif [ "$OS" == "Darwin" ]; then
-  if [ "$RELEASE_VER" == "nightly" ]; then
-    ARCHIVE_NAME="nvim-macos-x86_64"
-    RELEASE_NAME="nvim-macos-x86_64"
-  else
-    ARCHIVE_NAME="nvim-macos"
-    # for some reason the archive has a different name
-    RELEASE_NAME="nvim-osx64"
-  fi
+  ARCHIVE_NAME="nvim-macos-x86_64"
 else
   echo "$OS platform is not supported currently"
   exit 1
@@ -77,12 +68,8 @@ function install_neovim() {
   pushd "$DOWNLOAD_DIR"
   tar -xzf "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"
   popd
-  if [ ! -d "$DOWNLOAD_DIR/$RELEASE_NAME" ]; then
-    # fallback to archive name
-    RELEASE_NAME="$ARCHIVE_NAME"
-  fi
   # https://dev.to/ackshaey/macos-vs-linux-the-cp-command-will-trip-you-up-2p00
-  cp -r "$DOWNLOAD_DIR/$RELEASE_NAME/." "$LV_INSTALL_PREFIX"
+  cp -r "$DOWNLOAD_DIR/$ARCHIVE_NAME/." "$LV_INSTALL_PREFIX"
   echo "Installation complete!"
   echo "Now you can run $LV_INSTALL_PREFIX/bin/nvim"
 }