diff --git a/.selene-schema.yml b/.selene-schema.yml new file mode 100644 index 0000000..b975114 --- /dev/null +++ b/.selene-schema.yml @@ -0,0 +1,45 @@ +--- +base: lua51 +name: .selene-schema +globals: + after_each: + args: + - type: function + assert.equals: + args: + - type: any + - type: any + - required: false + type: any + assert.is_not: + any: true + assert.same: + args: + - type: any + - type: any + assert.spy: + args: + - type: any + assert.stub: + args: + - type: any + assert.truthy: + args: + - type: any + before_each: + args: + - type: function + describe: + args: + - type: string + - type: function + it: + args: + - type: string + - type: function + jit: + any: true + vim: + any: true + base: + any: true diff --git a/README.md b/README.md index 69594fc..67496d2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +## Changes over the original project +* Nvim 0.10 and 0.11 support. +* Ability to exclude buffers from autocd. + # 🗃️ project.nvim **project.nvim** is an all in one neovim plugin written in lua that provides @@ -7,7 +11,7 @@ superior project management. ## ⚡ Requirements -- Neovim >= 0.5.0 +- Neovim >= 0.10.0 ## ✨ Features @@ -121,6 +125,12 @@ use { -- * win scope_chdir = 'global', + -- Don't chdir for certain buffers + exclude_chdir = { + filetype = {"", "OverseerList", "alpha"}, + buftype = {"nofile", "terminal"}, + }, + -- Path where project.nvim will store the project history for use in -- telescope datapath = vim.fn.stdpath("data"), diff --git a/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index 36e3027..de5465f 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -37,6 +37,12 @@ M.defaults = { -- * win scope_chdir = 'global', + -- Don't chdir for certain buffers + exclude_chdir = { + filetype = {"", "OverseerList", "alpha"}, + buftype = {"nofile", "terminal"}, + }, + -- Path where project.nvim will store the project history for use in -- telescope datapath = vim.fn.stdpath("data"), diff --git a/lua/project_nvim/project.lua b/lua/project_nvim/project.lua index 76972ee..76b71f4 100644 --- a/lua/project_nvim/project.lua +++ b/lua/project_nvim/project.lua @@ -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 @@ -214,7 +213,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 @@ -232,6 +231,16 @@ function M.is_file() end function M.on_buf_enter() + -- if filetype is excluded, return + for _, filetype in pairs(config.options.exclude_chdir.filetype) do + if filetype == vim.bo.filetype then return end + end + + -- if buftype is excluded, return + for _, buftype in pairs(config.options.exclude_chdir.buftype) do + if vim.bo.buftype ~= "" and buftype == vim.bo.buftype then return end + end + if vim.v.vim_did_enter == 0 then return end @@ -257,7 +266,7 @@ end function M.init() local autocmds = {} if not config.options.manual_mode then - autocmds[#autocmds + 1] = 'autocmd VimEnter,BufEnter * ++nested lua require("project_nvim.project").on_buf_enter()' + autocmds[#autocmds + 1] = 'autocmd BufReadPost * ++nested lua require("project_nvim.project").on_buf_enter()' if vim.tbl_contains(config.options.detection_methods, "lsp") then M.attach_to_lsp() diff --git a/lua/project_nvim/utils/history.lua b/lua/project_nvim/utils/history.lua index 486c1ee..55b2989 100644 --- a/lua/project_nvim/utils/history.lua +++ b/lua/project_nvim/utils/history.lua @@ -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 diff --git a/lua/project_nvim/utils/path.lua b/lua/project_nvim/utils/path.lua index 69ac7ad..314fccd 100644 --- a/lua/project_nvim/utils/path.lua +++ b/lua/project_nvim/utils/path.lua @@ -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 diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..d4b5ea1 --- /dev/null +++ b/selene.toml @@ -0,0 +1,7 @@ +std=".selene-schema" + +[lints] +global_usage = "allow" +mixed_table = "allow" +multiple_statements = "allow" +shadowing = "warn"