Kaynağa Gözat

refactor: replace deprecated API calls

kylo252 1 yıl önce
ebeveyn
işleme
b7ce160939

+ 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 - 0
lua/lvim/core/autocmds.lua

@@ -105,6 +105,7 @@ function M.load_defaults()
           if lvim.builtin.breadcrumbs.active then
             require("lvim.core.breadcrumbs").get_winbar()
           end
+          -- FIXME
           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)

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

@@ -94,18 +94,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,7 +138,8 @@ M.get_filename = function()
     --   file_icon = lvim.icons.ui.DebugConsole
     -- end
 
-    local navic_text = vim.api.nvim_get_hl_by_name("Normal", true)
+    local navic_text = vim.api.nvim_get_hl_by_name("Normal", true) -- FIXME
+    -- local navic_text = vim.api.nvim_get_hl(0, { name = "Normal", create = false })
     vim.api.nvim_set_hl(0, "Winbar", { fg = navic_text.foreground })
 
     return " " .. "%#" .. hl_group .. "#" .. file_icon .. "%*" .. " " .. "%#Winbar#" .. filename .. "%*"
@@ -172,19 +176,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 +199,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)

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

@@ -81,7 +81,7 @@ 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_by_name(name.group, true) -- FIXME
     return string.format("#%06x", ret[name.property])
   end
 

+ 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 })
   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
 

+ 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

+ 1 - 1
tests/minimal_lsp.lua

@@ -42,7 +42,7 @@ _G.load_config = function()
   local nvim_lsp = require "lspconfig"
   local on_attach = function(_, bufnr)
     local function buf_set_option(...)
-      vim.api.nvim_buf_set_option(bufnr, ...)
+      vim.api.nvim_set_option_value(..., { 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)