Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
8f984f6
chore: Format with stylua.
DrKJeff16 Jun 30, 2024
2a18fba
fix: Got rid of deprecations.
DrKJeff16 Jun 30, 2024
8cb4b93
fix: Renamed declared identifiers.
DrKJeff16 Jun 30, 2024
b6ec183
fix: Favour `vim.uv` over `vim.loop`.
DrKJeff16 Jun 30, 2024
85c2300
docs: Add some annotations.
DrKJeff16 Jun 30, 2024
0268421
docs: Add annotation to func for warning removal.
DrKJeff16 Jun 30, 2024
51fff27
fix: Favour `vim.uv` over `vim.loop`.
DrKJeff16 Jun 30, 2024
e7a4c10
docs: Add some annotations.
DrKJeff16 Jun 30, 2024
85df8e7
docs: Add annotation to func for warning removal.
DrKJeff16 Jun 30, 2024
f98a0b9
fix: (Read description) Annotations + code fixes.
DrKJeff16 Aug 9, 2024
4e7d846
fix: (Read description) `project.lua` code improvements
DrKJeff16 Aug 9, 2024
3249dca
fix: (Read description) `utils/history.lua` code improvements
DrKJeff16 Aug 9, 2024
85bc488
fix: Favour `vim.uv` over `vim.loop`.
DrKJeff16 Jun 30, 2024
41a7a09
fix: (Read description) Annotations + code fixes.
DrKJeff16 Aug 9, 2024
495a874
fix: (Read description) `project.lua` code improvements
DrKJeff16 Aug 9, 2024
6f1ed8d
fix: (Read description) `utils/history.lua` code improvements
DrKJeff16 Aug 9, 2024
1e716ea
chore: Add Vim comment to `README` for consistent indentation.
DrKJeff16 Aug 11, 2024
226f3eb
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
b4e4c9d
feat: Added install instructions for `lazy.nvim`.
DrKJeff16 Aug 11, 2024
58765dd
fix: Extended instructions, fixed some words.
DrKJeff16 Aug 11, 2024
9f1505c
fix(telescope): Added annotations across the file.
DrKJeff16 Aug 12, 2024
aca62fb
fix(telescope): Fixed redundant conditional statement.
DrKJeff16 Aug 12, 2024
f86cf8e
fix(telescope): Added annotations across the file.
DrKJeff16 Aug 12, 2024
e4db2d4
fix(telescope): Fixed redundant conditional statement.
DrKJeff16 Aug 12, 2024
33702e2
chore: Added Vim comments on top of all lua files.
DrKJeff16 Aug 12, 2024
4a0eb11
refactor(project)!: Rewrote autocmd statements using Lua.
DrKJeff16 Aug 12, 2024
6fc9275
chore: Added Vim comments on top of all lua files.
DrKJeff16 Aug 12, 2024
5ac6e7a
refactor(project)!: Rewrote autocmd statements using Lua.
DrKJeff16 Aug 12, 2024
19fd3b8
fix(telescope): Added annotations across the file.
DrKJeff16 Aug 12, 2024
168826a
fix(telescope): Fixed redundant conditional statement.
DrKJeff16 Aug 12, 2024
048fd2f
chore: Added Vim comments on top of all lua files.
DrKJeff16 Aug 12, 2024
96e778b
refactor(project)!: Rewrote autocmd statements using Lua.
DrKJeff16 Aug 12, 2024
3dc4dec
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
cab38c6
chore: Add Vim comment to `README` for consistent indentation.
DrKJeff16 Aug 11, 2024
222884d
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
cdd0d2a
feat: Added install instructions for `lazy.nvim`.
DrKJeff16 Aug 11, 2024
554ebc9
fix: Extended instructions, fixed some words.
DrKJeff16 Aug 11, 2024
136615f
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
1caa6e1
Merge remote-tracking branch 'refs/remotes/origin/docs' into docs
DrKJeff16 Aug 21, 2024
2c66e15
chore: Add Vim comment to `README` for consistent indentation.
DrKJeff16 Aug 11, 2024
9361f14
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
48e1e3f
feat: Added install instructions for `lazy.nvim`.
DrKJeff16 Aug 11, 2024
00a6906
fix: Extended instructions, fixed some words.
DrKJeff16 Aug 11, 2024
5f8661d
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
794f45f
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
2424772
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
fc134ea
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
ba2f6be
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
471e693
Merge remote-tracking branch 'refs/remotes/origin/main'
DrKJeff16 Aug 21, 2024
9b9cb37
fix!: Set type annotation to main module, improve `setup()`.
DrKJeff16 Aug 21, 2024
eede615
fix!: Set type annotation to main module, improve `setup()`.
DrKJeff16 Aug 21, 2024
3759f76
feat: Added install instructions for `lazy.nvim`.
DrKJeff16 Aug 11, 2024
5d97033
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
e685055
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
8b28ce9
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
442ddd1
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
ac8b643
fix: Extended instructions, fixed some words.
DrKJeff16 Aug 11, 2024
3ff24f5
fix: More hyperlinks and better code blocks in `README`.
DrKJeff16 Aug 11, 2024
c63ba91
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
3914103
feat: Added install instructions for `lazy.nvim`.
DrKJeff16 Aug 11, 2024
250d1b1
fix(README): Aesthetic fixes, sections dropped, comments and more.
DrKJeff16 Aug 12, 2024
2aa7f74
Merge branch 'main' of github.com:DrKJeff16/project.nvim
DrKJeff16 Aug 21, 2024
bb0e2d2
ci: Add `pre-commot` hooks.
DrKJeff16 Jun 16, 2025
b41821e
ci: Change stylua options for the defaults I use.
DrKJeff16 Jun 16, 2025
df6192c
chore: Format with stylua.
DrKJeff16 Jun 16, 2025
4c61356
docs(README): Update README to fix corrections, deprecations, and style.
DrKJeff16 Jun 16, 2025
f638684
refactor(project): Favour using `for x, y in next, T ...` FOR loops.
DrKJeff16 Jun 18, 2025
e94a20f
refactor: Favour `for x,y in next, T` loops.
DrKJeff16 Jun 18, 2025
0055222
docs(config): Add descriptions to annotations for `project_nvim.config`.
DrKJeff16 Jun 20, 2025
b18264d
perf(project): Decrease complexity for some code blocks, separated cmds.
DrKJeff16 Jun 20, 2025
6943ba4
feat(project)!: Added an autocmd event to existing ones.
DrKJeff16 Jun 20, 2025
9a0ad6b
feat: Added entry points for submodules.
DrKJeff16 Jun 20, 2025
1524b04
Revert "feat: Added entry points for submodules."
DrKJeff16 Jun 20, 2025
d73f435
docs(project): Added annotations and personal comments (mostly warnin…
DrKJeff16 Jun 20, 2025
bf0cc79
fix(project): Read commit description.
DrKJeff16 Jun 20, 2025
b85f7bb
chore: Annotations fixed and renamed `init.lua` module table.
DrKJeff16 Jun 20, 2025
a6e457b
fix(telescope): Decreased complexity, added annotations.
DrKJeff16 Jun 20, 2025
c1aa993
chore(project): Fix bad TODO comment.
DrKJeff16 Jun 20, 2025
0acd3da
docs: Rewrote `README.md` and added more structure to it.
DrKJeff16 Jun 21, 2025
bab1089
fixup: Removed emojis from titles for TOC to be of use in README.
DrKJeff16 Jun 21, 2025
d0e62e1
chore(README): Use parentheses for better consistency.
DrKJeff16 Jun 21, 2025
16f9e79
fix: Fixed typo (read description).
DrKJeff16 Jun 21, 2025
8817938
feat(repo): Add default issue templates for this repo.
DrKJeff16 Jun 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 60 additions & 44 deletions lua/project_nvim/config.lua
Original file line number Diff line number Diff line change
@@ -1,50 +1,66 @@
local M = {}

---@class ProjectOptions
M.defaults = {
-- Manual mode doesn't automatically change your root directory, so you have
-- the option to manually do so using `:ProjectRoot` command.
manual_mode = false,

-- Methods of detecting the root directory. **"lsp"** uses the native neovim
-- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here
-- order matters: if one is not detected, the other is used as fallback. You
-- can also delete or rearangne the detection methods.
detection_methods = { "lsp", "pattern" },

-- All the patterns used to detect root dir, when **"pattern"** is in
-- detection_methods
patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },

-- Table of lsp clients to ignore by name
-- eg: { "efm", ... }
ignore_lsp = {},

-- Don't calculate root dir on specific directories
-- Ex: { "~/.cargo/*", ... }
exclude_dirs = {},

-- Show hidden files in telescope
show_hidden = false,

-- When set to false, you will get a message when project.nvim changes your
-- directory.
silent_chdir = true,

-- What scope to change the directory, valid options are
-- * global (default)
-- * tab
-- * win
scope_chdir = 'global',

-- Path where project.nvim will store the project history for use in
-- telescope
datapath = vim.fn.stdpath("data"),
}
---@field manual_mode? boolean
---@field detection_methods? ("lsp"|"pattern")[]
---@field patterns? string[]
---@field ignore_lsp? string[]
---@field exclude_dirs? string[]
---@field show_hidden? boolean
---@field silent_chdir? boolean
---@field datapath? `vim.fn.stdpath("data")`|string

---@class Project
---@field defaults ProjectOptions
---@field options ProjectOptions
---@field setup fun(options: ProjectOptions)

---@type Project
---@diagnostic disable-next-line:missing-fields
local M = {
defaults = {
-- Manual mode doesn't automatically change your root directory, so you have
-- the option to manually do so using `:ProjectRoot` command.
manual_mode = false,

-- Methods of detecting the root directory. **"lsp"** uses the native neovim
-- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here
-- order matters: if one is not detected, the other is used as fallback. You
-- can also delete or rearangne the detection methods.
detection_methods = { "lsp", "pattern" },

-- All the patterns used to detect root dir, when **"pattern"** is in
-- detection_methods
patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },

-- Table of lsp clients to ignore by name
-- eg: { "efm", ... }
ignore_lsp = {},

---@type ProjectOptions
M.options = {}
-- Don't calculate root dir on specific directories
-- Ex: { "~/.cargo/*", ... }
exclude_dirs = {},

-- Show hidden files in telescope
show_hidden = false,

-- When set to false, you will get a message when project.nvim changes your
-- directory.
silent_chdir = true,

-- What scope to change the directory, valid options are
-- * global (default)
-- * tab
-- * win
scope_chdir = "global",

-- Path where project.nvim will store the project history for use in
-- telescope
datapath = vim.fn.stdpath("data"),
},

options = {},
}

---@param options ProjectOptions
M.setup = function(options)
M.options = vim.tbl_deep_extend("force", M.defaults, options or {})

Expand Down
47 changes: 25 additions & 22 deletions lua/project_nvim/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 uv = vim.uv or vim.loop
local M = {}

-- Internal states
Expand All @@ -12,8 +12,10 @@ 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 bufnr = vim.api.nvim_get_current_buf()

local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
local clients = vim.lsp.get_clients({ bufnr = bufnr })
if next(clients) == nil then
return nil
end
Expand All @@ -39,12 +41,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(path_str)
path_str = path_str:match("^(.*)/")
if path_str == "" then
path_str = "/"
end
return path
return path_str
end

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

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

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

local function has(dir, identifier)
Expand Down Expand Up @@ -176,12 +177,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 +215,9 @@ function M.get_project_root()
end

function M.is_file()
local buf_type = vim.api.nvim_buf_get_option(0, "buftype")
local bufnr = vim.api.nvim_get_current_buf()

local buf_type = vim.api.nvim_get_option_value("buftype", { buf = bufnr })

local whitelisted_buf_type = { "", "acwrite" }
local is_in_whitelist = false
Expand Down Expand Up @@ -251,7 +254,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 c or "%" .. c
end

-- Convert tokens at end of charset.
Expand Down
14 changes: 7 additions & 7 deletions lua/project_nvim/utils/history.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local path = require("project_nvim.utils.path")
local uv = vim.loop
local uv = vim.uv or vim.loop
local M = {}
local is_windows = vim.fn.has('win32') or vim.fn.has('wsl')
local is_windows = vim.fn.has("win32") or vim.fn.has("wsl")

M.recent_projects = nil -- projects from previous neovim sessions
M.session_projects = {} -- projects from current neovim session
Expand All @@ -27,13 +27,13 @@ local function dir_exists(dir)
end

local function normalise_path(path_to_normalise)
local normalised_path = path_to_normalise:gsub("\\", "/"):gsub("//", "/")
local normalised_path = path_to_normalise:gsub("\\", "/"):gsub("//", "/")

if is_windows then
normalised_path = normalised_path:sub(1,1):lower()..normalised_path:sub(2)
end
if is_windows then
normalised_path = normalised_path:sub(1, 1):lower() .. normalised_path:sub(2)
end

return normalised_path
return normalised_path
end

local function delete_duplicates(tbl)
Expand Down
2 changes: 1 addition & 1 deletion lua/project_nvim/utils/path.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local config = require("project_nvim.config")
local uv = vim.loop
local uv = vim.uv or vim.loop
local M = {}

M.datapath = vim.fn.stdpath("data") -- directory
Expand Down
56 changes: 29 additions & 27 deletions lua/telescope/_extensions/projects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,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