Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exclude-from-chdir) Add exclude_chdir #131

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
break!: Removed deprecated nvim 0.9 functions. Use nvim 0.10 instead.
Zeioth committed May 24, 2024
commit 83cbf401e1aeef64e4d57749b5409d0db0d3b441
9 changes: 4 additions & 5 deletions lua/project_nvim/project.lua
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ local config = require("project_nvim.config")
local history = require("project_nvim.utils.history")
local glob = require("project_nvim.utils.globtopattern")
local path = require("project_nvim.utils.path")
local uv = vim.loop
local M = {}

-- Internal states
@@ -12,8 +11,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.bo.filetype
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return nil
end
@@ -51,13 +50,13 @@ function M.find_pattern_root()
last_dir_cache = file_dir
curr_dir_cache = {}

local dir = uv.fs_scandir(file_dir)
local dir = vim.uv.fs_scandir(file_dir)
if dir == nil then
return
end

while true do
local file = uv.fs_scandir_next(dir)
local file = vim.uv.fs_scandir_next(dir)
if file == nil then
return
end
19 changes: 9 additions & 10 deletions lua/project_nvim/utils/history.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local path = require("project_nvim.utils.path")
local uv = vim.loop
local M = {}
local is_windows = vim.fn.has('win32') or vim.fn.has('wsl')

@@ -10,16 +9,16 @@ M.has_watch_setup = false
local function open_history(mode, callback)
if callback ~= nil then -- async
path.create_scaffolding(function(_, _)
uv.fs_open(path.historyfile, mode, 438, callback)
vim.uv.fs_open(path.historyfile, mode, 438, callback)
end)
else -- sync
path.create_scaffolding()
return uv.fs_open(path.historyfile, mode, 438)
return vim.uv.fs_open(path.historyfile, mode, 438)
end
end

local function dir_exists(dir)
local stat = uv.fs_stat(dir)
local stat = vim.uv.fs_stat(dir)
if stat ~= nil and stat.type == "directory" then
return true
end
@@ -85,7 +84,7 @@ local function setup_watch()
-- Only runs once
if M.has_watch_setup == false then
M.has_watch_setup = true
local event = uv.new_fs_event()
local event = vim.uv.new_fs_event()
if event == nil then
return
end
@@ -105,10 +104,10 @@ function M.read_projects_from_history()
open_history("r", function(_, fd)
setup_watch()
if fd ~= nil then
uv.fs_fstat(fd, function(_, stat)
vim.uv.fs_fstat(fd, function(_, stat)
if stat ~= nil then
uv.fs_read(fd, stat.size, -1, function(_, data)
uv.fs_close(fd, function(_, _) end)
vim.uv.fs_read(fd, stat.size, -1, function(_, data)
vim.uv.fs_close(fd, function(_, _) end)
deserialize_history(data)
end)
end
@@ -170,8 +169,8 @@ function M.write_projects_to_history()
end

-- Write string out to file and close
uv.fs_write(file, out, -1)
uv.fs_close(file)
vim.uv.fs_write(file, out, -1)
vim.uv.fs_close(file)
end
end

5 changes: 2 additions & 3 deletions lua/project_nvim/utils/path.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local config = require("project_nvim.config")
local uv = vim.loop
local M = {}

M.datapath = vim.fn.stdpath("data") -- directory
@@ -14,9 +13,9 @@ end

function M.create_scaffolding(callback)
if callback ~= nil then -- async
uv.fs_mkdir(M.projectpath, 448, callback)
vim.uv.fs_mkdir(M.projectpath, 448, callback)
else -- sync
uv.fs_mkdir(M.projectpath, 448)
vim.uv.fs_mkdir(M.projectpath, 448)
end
end