From 4105843c64bd64487c1021bfd8031af5803f69dc Mon Sep 17 00:00:00 2001 From: Zeioth Date: Fri, 21 Jul 2023 23:32:29 +0200 Subject: [PATCH 01/11] feat(exclude-from-chdir) Allow users to exclude certain filetypes and buftypes from chdir. This feature allow users to exclude certain plugins from triggering chdir. --- README.md | 6 ++++++ lua/project_nvim/config.lua | 6 ++++++ lua/project_nvim/project.lua | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 69594fc..224f93d 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,12 @@ use { -- * win scope_chdir = 'global', + -- Don't chdir for specific filetypes + exclude_filetype_chdir = {"", "OverseerList",}, + + -- Don't chdir for specific buftypes + exclude_buftype_chdir = {"", "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..9f850f4 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 specific filetypes + exclude_filetype_chdir = {"", "OverseerList"}, + + -- Don't chdir for specific buftypes + exclude_buftype_chdir = {"", "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..25c40dc 100644 --- a/lua/project_nvim/project.lua +++ b/lua/project_nvim/project.lua @@ -232,6 +232,16 @@ function M.is_file() end function M.on_buf_enter() + -- if filetype is excluded, return + for _, filetype in pairs(config.options.exclude_filetype_chdir) do + if filetype == vim.bo.filetype then return end + end + + -- if buftype is excluded, return + for _, buftype in pairs(config.options.exclude_buftype_chdir) do + if buftype == vim.bo.buftype then return end + end + if vim.v.vim_did_enter == 0 then return end From fa1df3adb4d9f9fffb1cf5d2efe3d979da1e69e2 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Mon, 7 Aug 2023 00:22:20 +0200 Subject: [PATCH 02/11] fix(detect nofile instead of "") --- lua/project_nvim/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index 9f850f4..389b283 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -41,7 +41,7 @@ M.defaults = { exclude_filetype_chdir = {"", "OverseerList"}, -- Don't chdir for specific buftypes - exclude_buftype_chdir = {"", "terminal"}, + exclude_buftype_chdir = {"nofile", "terminal"}, -- Path where project.nvim will store the project history for use in -- telescope From dc6b7e4d544be6b813333aecdb3f980e3a6baef7 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Mon, 7 Aug 2023 00:23:53 +0200 Subject: [PATCH 03/11] fix: The right autocmd is BufReadPost, not BufEnter cd only when opening the file. Otherwise the behavior won't be what the user expects. --- lua/project_nvim/project.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/project_nvim/project.lua b/lua/project_nvim/project.lua index 25c40dc..f127808 100644 --- a/lua/project_nvim/project.lua +++ b/lua/project_nvim/project.lua @@ -239,7 +239,7 @@ function M.on_buf_enter() -- if buftype is excluded, return for _, buftype in pairs(config.options.exclude_buftype_chdir) do - if buftype == vim.bo.buftype then return end + if vim.bo.buftype ~= "" and buftype == vim.bo.buftype then return end end if vim.v.vim_did_enter == 0 then @@ -267,7 +267,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() From 3d30a4ddaf0f0c30892fb2f36fa4669499d7e6db Mon Sep 17 00:00:00 2001 From: Zeioth Date: Mon, 7 Aug 2023 00:35:10 +0200 Subject: [PATCH 04/11] ignore filetype alpha by default --- lua/project_nvim/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index 389b283..500b2ba 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -38,7 +38,7 @@ M.defaults = { scope_chdir = 'global', -- Don't chdir for specific filetypes - exclude_filetype_chdir = {"", "OverseerList"}, + exclude_filetype_chdir = {"", "OverseerList", "alpha"}, -- Don't chdir for specific buftypes exclude_buftype_chdir = {"nofile", "terminal"}, From 83cbf401e1aeef64e4d57749b5409d0db0d3b441 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Fri, 24 May 2024 15:55:27 +0200 Subject: [PATCH 05/11] break!: Removed deprecated nvim 0.9 functions. Use nvim 0.10 instead. --- lua/project_nvim/project.lua | 9 ++++----- lua/project_nvim/utils/history.lua | 19 +++++++++---------- lua/project_nvim/utils/path.lua | 5 ++--- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lua/project_nvim/project.lua b/lua/project_nvim/project.lua index 25c40dc..77d03c5 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 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 From 68b16aad8b55ef2b3cf1ced29c5792a8df777d05 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Fri, 24 May 2024 16:43:18 +0200 Subject: [PATCH 06/11] Update README.md --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 224f93d..ddf32ea 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 @@ -218,3 +222,11 @@ print(vim.inspect(recent_projects)) - All pull requests are welcome. - If you encounter bugs please open an issue. + +## TODOS +In the future i'd like to divide this plugin into two plugins: + +* autocd.nvim +* project.nvim + +As that's two different cases of use. From 4531953634fd97b71df156c1879d1f8f750460ac Mon Sep 17 00:00:00 2001 From: Zeioth Date: Sat, 25 May 2024 00:39:44 +0200 Subject: [PATCH 07/11] break!: exclude_buftype_chdir and exclude_filetype_chdir are now replaced by `exclude_chdir`. --- lua/project_nvim/config.lua | 8 ++++---- lua/project_nvim/project.lua | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index 500b2ba..6d27761 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -38,10 +38,10 @@ M.defaults = { scope_chdir = 'global', -- Don't chdir for specific filetypes - exclude_filetype_chdir = {"", "OverseerList", "alpha"}, - - -- Don't chdir for specific buftypes - exclude_buftype_chdir = {"nofile", "terminal"}, + exclude_chdir = { + filetype = {"", "OverseerList", "alpha"}, + buftype = {"nofile", "terminal"}, + }, -- Path where project.nvim will store the project history for use in -- telescope diff --git a/lua/project_nvim/project.lua b/lua/project_nvim/project.lua index 62446bf..da0e59b 100644 --- a/lua/project_nvim/project.lua +++ b/lua/project_nvim/project.lua @@ -232,12 +232,12 @@ end function M.on_buf_enter() -- if filetype is excluded, return - for _, filetype in pairs(config.options.exclude_filetype_chdir) do + 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_buftype_chdir) do + for _, buftype in pairs(config.options.exclude_chdir.buftype) do if vim.bo.buftype ~= "" and buftype == vim.bo.buftype then return end end From 368f4db6f37d8d9c87453709b3cc11fea94fe757 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Sat, 25 May 2024 00:40:40 +0200 Subject: [PATCH 08/11] comments --- lua/project_nvim/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index 6d27761..de5465f 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -37,7 +37,7 @@ M.defaults = { -- * win scope_chdir = 'global', - -- Don't chdir for specific filetypes + -- Don't chdir for certain buffers exclude_chdir = { filetype = {"", "OverseerList", "alpha"}, buftype = {"nofile", "terminal"}, From f19455d2fad52d86ecea019de72ae2e4a5fc7711 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Sat, 25 May 2024 00:41:10 +0200 Subject: [PATCH 09/11] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ddf32ea..ae8798a 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,11 @@ use { -- * win scope_chdir = 'global', - -- Don't chdir for specific filetypes - exclude_filetype_chdir = {"", "OverseerList",}, - - -- Don't chdir for specific buftypes - exclude_buftype_chdir = {"", "terminal"}, + -- 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 From 173b5c92a0cdff15bc8dd1876d7f74d12abf6981 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Sun, 26 May 2024 15:01:59 +0200 Subject: [PATCH 10/11] Update README.md --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index ae8798a..67496d2 100644 --- a/README.md +++ b/README.md @@ -222,11 +222,3 @@ print(vim.inspect(recent_projects)) - All pull requests are welcome. - If you encounter bugs please open an issue. - -## TODOS -In the future i'd like to divide this plugin into two plugins: - -* autocd.nvim -* project.nvim - -As that's two different cases of use. From 95f56b8454f3285b819340d7d769e67242d59b53 Mon Sep 17 00:00:00 2001 From: Zeioth Date: Sun, 26 May 2024 20:59:39 +0200 Subject: [PATCH 11/11] chore: deprecation removed + selene schema added. --- .selene-schema.yml | 45 ++++++++++++++++++++++++++++++ lua/project_nvim/config.lua | 10 +++---- lua/project_nvim/project.lua | 19 ++++++------- lua/project_nvim/utils/history.lua | 19 ++++++------- lua/project_nvim/utils/path.lua | 5 ++-- selene.toml | 7 +++++ 6 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 .selene-schema.yml create mode 100644 selene.toml 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/lua/project_nvim/config.lua b/lua/project_nvim/config.lua index 9f850f4..de5465f 100644 --- a/lua/project_nvim/config.lua +++ b/lua/project_nvim/config.lua @@ -37,11 +37,11 @@ M.defaults = { -- * win scope_chdir = 'global', - -- Don't chdir for specific filetypes - exclude_filetype_chdir = {"", "OverseerList"}, - - -- Don't chdir for specific buftypes - exclude_buftype_chdir = {"", "terminal"}, + -- 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 diff --git a/lua/project_nvim/project.lua b/lua/project_nvim/project.lua index 25c40dc..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 @@ -233,13 +232,13 @@ end function M.on_buf_enter() -- if filetype is excluded, return - for _, filetype in pairs(config.options.exclude_filetype_chdir) do + 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_buftype_chdir) do - if buftype == vim.bo.buftype then return end + 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 @@ -267,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"