Skip to content

Commit

Permalink
fix: deprecated and warnings
Browse files Browse the repository at this point in the history
remove: init mode setup
  • Loading branch information
zongben committed Dec 26, 2024
1 parent 0158111 commit 3589a2e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion lua/project_nvim/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ M.defaults = {
}

---@type ProjectOptions
M.options = {}
M.options = nil or {}

M.setup = function(options)
M.options = vim.tbl_deep_extend("force", M.defaults, options or {})
Expand Down
46 changes: 24 additions & 22 deletions lua/project_nvim/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ M.last_project = nil
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 clients = vim.lsp.buf_get_clients()
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
local clients = vim.lsp.get_clients({ bufnr = 0 })
if next(clients) == nil then
return nil
end
Expand All @@ -39,12 +39,12 @@ function M.find_pattern_root()
local last_dir_cache = ""
local curr_dir_cache = {}

local function get_parent(path)
path = path:match("^(.*)/")
if path == "" then
path = "/"
local function get_parent(p)
p = p:match("^(.*)/")
if p == "" then
p = "/"
end
return path
return p
end

local function get_files(file_dir)
Expand Down Expand Up @@ -72,22 +72,22 @@ function M.find_pattern_root()
end

local function sub(dir, identifier)
local path = get_parent(dir)
local p = get_parent(dir)
while true do
if is(path, identifier) then
if is(p, identifier) then
return true
end
local current = path
path = get_parent(path)
if current == path then
local current = p
p = get_parent(p)
if current == p then
return false
end
end
end

local function child(dir, identifier)
local path = get_parent(dir)
return is(path, identifier)
local p = get_parent(dir)
return is(p, identifier)
end

local function has(dir, identifier)
Expand Down Expand Up @@ -160,7 +160,9 @@ function M.attach_to_lsp()
local _on_attach = lsp_config.on_attach
lsp_config.on_attach = function(client, bufnr)
on_attach_lsp(client, bufnr)
_on_attach(client, bufnr)
if _on_attach ~= nil then
_on_attach(client, bufnr)
end
end
end
return _start_client(lsp_config)
Expand All @@ -176,12 +178,12 @@ function M.set_pwd(dir, method)

if vim.fn.getcwd() ~= dir then
local scope_chdir = config.options.scope_chdir
if scope_chdir == 'global' then
if scope_chdir == "global" then
vim.api.nvim_set_current_dir(dir)
elseif scope_chdir == 'tab' then
vim.cmd('tcd ' .. dir)
elseif scope_chdir == 'win' then
vim.cmd('lcd ' .. dir)
elseif scope_chdir == "tab" then
vim.cmd("tcd " .. dir)
elseif scope_chdir == "win" then
vim.cmd("lcd " .. dir)
else
return
end
Expand Down Expand Up @@ -214,7 +216,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("filetype", { buf = 0 })

local whitelisted_buf_type = { "", "acwrite" }
local is_in_whitelist = false
Expand Down Expand Up @@ -251,7 +253,7 @@ end

function M.add_project_manually()
local current_dir = vim.fn.expand("%:p:h", true)
M.set_pwd(current_dir, 'manual')
M.set_pwd(current_dir, "manual")
end

function M.init()
Expand Down
4 changes: 2 additions & 2 deletions lua/project_nvim/utils/globtopattern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function M.globtopattern(g)
end

-- escape pattern char
local function escape(c)
return c:match("^%w$") and c or "%" .. c
local function escape(char)
return char:match("^%w$") and char or "%" .. char
end

-- Convert tokens at end of charset.
Expand Down
76 changes: 37 additions & 39 deletions lua/telescope/_extensions/projects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ local function delete_buffers()
end
end

local function change_working_directory(prompt_bufnr, prompt)
local selected_entry = state.get_selected_entry(prompt_bufnr)
local function change_working_directory(prompt_bufnr)
local selected_entry = state.get_selected_entry()
if selected_entry == nil then
actions.close(prompt_bufnr)
return
end
local project_path = selected_entry.value
if prompt == true then
actions._close(prompt_bufnr, true)
else
actions.close(prompt_bufnr)
end
actions.close(prompt_bufnr)
local cd_successful = project.set_pwd(project_path, "telescope")
if cd_successful then
delete_buffers()
Expand All @@ -87,7 +83,7 @@ local function change_working_directory(prompt_bufnr, prompt)
end

local function find_project_files(prompt_bufnr)
local project_path, cd_successful = change_working_directory(prompt_bufnr, true)
local project_path, cd_successful = change_working_directory(prompt_bufnr)
local opt = {
cwd = project_path,
hidden = config.options.show_hidden,
Expand All @@ -99,7 +95,7 @@ local function find_project_files(prompt_bufnr)
end

local function browse_project_files(prompt_bufnr)
local project_path, cd_successful = change_working_directory(prompt_bufnr, true)
local project_path, cd_successful = change_working_directory(prompt_bufnr)
local opt = {
cwd = project_path,
hidden = config.options.show_hidden,
Expand All @@ -110,7 +106,7 @@ local function browse_project_files(prompt_bufnr)
end

local function search_in_project_files(prompt_bufnr)
local project_path, cd_successful = change_working_directory(prompt_bufnr, true)
local project_path, cd_successful = change_working_directory(prompt_bufnr)
local opt = {
cwd = project_path,
hidden = config.options.show_hidden,
Expand All @@ -122,7 +118,7 @@ local function search_in_project_files(prompt_bufnr)
end

local function recent_project_files(prompt_bufnr)
local _, cd_successful = change_working_directory(prompt_bufnr, true)
local _, cd_successful = change_working_directory(prompt_bufnr)
local opt = {
cwd_only = true,
hidden = config.options.show_hidden,
Expand All @@ -133,7 +129,7 @@ local function recent_project_files(prompt_bufnr)
end

local function delete_project(prompt_bufnr)
local selectedEntry = state.get_selected_entry(prompt_bufnr)
local selectedEntry = state.get_selected_entry()
if selectedEntry == nil then
actions.close(prompt_bufnr)
return
Expand All @@ -155,33 +151,35 @@ end
local function projects(opts)
opts = opts or {}

pickers.new(opts, {
prompt_title = "Recent Projects",
finder = create_finder(),
previewer = false,
sorter = telescope_config.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
map("n", "f", find_project_files)
map("n", "b", browse_project_files)
map("n", "d", delete_project)
map("n", "s", search_in_project_files)
map("n", "r", recent_project_files)
map("n", "w", change_working_directory)

map("i", "<c-f>", find_project_files)
map("i", "<c-b>", browse_project_files)
map("i", "<c-d>", delete_project)
map("i", "<c-s>", search_in_project_files)
map("i", "<c-r>", recent_project_files)
map("i", "<c-w>", change_working_directory)

local on_project_selected = function()
find_project_files(prompt_bufnr)
end
actions.select_default:replace(on_project_selected)
return true
end,
}):find()
pickers
.new(opts, {
prompt_title = "Recent Projects",
finder = create_finder(),
previewer = false,
sorter = telescope_config.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
map("n", "f", find_project_files)
map("n", "b", browse_project_files)
map("n", "d", delete_project)
map("n", "s", search_in_project_files)
map("n", "r", recent_project_files)
map("n", "w", change_working_directory)

map("i", "<c-f>", find_project_files)
map("i", "<c-b>", browse_project_files)
map("i", "<c-d>", delete_project)
map("i", "<c-s>", search_in_project_files)
map("i", "<c-r>", recent_project_files)
map("i", "<c-w>", change_working_directory)

local on_project_selected = function()
find_project_files(prompt_bufnr)
end
actions.select_default:replace(on_project_selected)
return true
end,
})
:find()
end

return telescope.register_extension({
Expand Down

0 comments on commit 3589a2e

Please sign in to comment.