Skip to content

Commit

Permalink
updated deprecated vim function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Iraq Jaber authored and Iraq Jaber committed Jan 8, 2025
1 parent a984d27 commit a6a0763
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 4 additions & 5 deletions lua/project_nvim/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vim.api.nvim_create_autocmd("BufDelete", {
end,
})

---@param client lsp.Client
---@param client vim.lsp.Client
---@param buf_name buf_name
function M._lsp_get_buf_root(client, buf_name)
local buf_file_path = buf_name_to_file_path_map[buf_name]
Expand All @@ -40,7 +40,6 @@ function M._lsp_get_buf_root(client, buf_name)
if client.workspace_folders then
for _, workspace_folder in pairs(client.workspace_folders) do
local folder_name = vim.uri_to_fname(workspace_folder.uri)
-- buf_file_path = buf_file_path .. "/file"
if folder_name and vim.startswith(buf_file_path, folder_name) then
if #folder_name == #buf_file_path then
return folder_name
Expand All @@ -65,9 +64,9 @@ end
function M.find_lsp_root()
-- Get lsp client for current buffer
-- Returns nil or string
local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = 0 })
local buf_name = vim.api.nvim_buf_get_name(0)
local clients = vim.lsp.buf_get_clients()
local clients = vim.lsp.get_clients({ bufnr = 0 })
if next(clients) == nil then
return nil
end
Expand Down Expand Up @@ -269,7 +268,7 @@ function M.get_project_root()
end

function M.is_file()
local buf_type = vim.api.nvim_buf_get_option(0, "buftype")
local buf_type = vim.api.nvim_get_option_value('buftype', { buf = 0 })

local whitelisted_buf_type = { "", "acwrite" }
local is_in_whitelist = false
Expand Down
11 changes: 5 additions & 6 deletions lua/tests/project_lsp_get_buf_root_spec.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- nvim --headless --noplugin -u lua/tests/minimal.vim -c "PlenaryBustedDirectory lua/tests/go_buildtargets_spec.lua {minimal_init = 'lua/tests/minimal.vim'}"
local eq = assert.are.same
local busted = require('plenary/busted')

local lsp_get_buff_root = require("project_nvim.project")._lsp_get_buf_root
local lsp_get_buf_root = require("project_nvim.project")._lsp_get_buf_root

describe('M._get_buf_root()):', function()
it("testing M._get_buf_root() returns correct buf_root for embedded projects", function()
Expand All @@ -14,22 +13,22 @@ describe('M._get_buf_root()):', function()

-- file in project root
local buf_name = outter_project .. "/main.file"
local res = lsp_get_buff_root(client, buf_name)
local res = lsp_get_buf_root(client, buf_name)
eq(res, outter_project)

-- file in project root
buf_name = inner_project .. "/main.file"
res = lsp_get_buff_root(client, buf_name)
res = lsp_get_buf_root(client, buf_name)
eq(res, inner_project)

-- file deep inside the project
buf_name = outter_project .. "/folder/folder/helper.file"
res = lsp_get_buff_root(client, buf_name)
res = lsp_get_buf_root(client, buf_name)
eq(res, outter_project)

-- file deep inside the project
buf_name = inner_project .. "/folder/folder/helper.file"
res = lsp_get_buff_root(client, buf_name)
res = lsp_get_buf_root(client, buf_name)
eq(res, inner_project)
end)
end)

0 comments on commit a6a0763

Please sign in to comment.