Closed jaidetree closed 1 year ago
Okay, firstly, patterns
is not regexp. So, *.org
doesn't work as expected. This is mentioned in the docs, but apparently not enough.
patterns
used to be a regular regexp, then transformed to lua patterns, and now finally doesn't do any pattern matching at all. This was supposedly done to improve performance and complxity, although I didn't benchmark :P. And because usually there is a better pattern
out there which doesn't require this. Supporting lua patterns is certainly possible and pretty painless, so I will think about it, after benchmarking a bit.
Does ~/projects
and ~/dotfiles
contain a subdirectory with .git
directory inside? If not, the bug is explained. I think ~/dotfiles
at least doesn't have such directory.
Also note that it has to be a direct subdirectory. ~/projects/A/B/.git
doesn't count. Only ~/projects/A/.git
does.
Information that will be helpful:
tree -a -L 2
from both ~/projects
and ~/dotfiles
. Censor personal information as required.I will look at your issue further in a couple of hours. I do not use fennel, so I will need to learn some things first.
My mistake on missing the pattern matching. What about supporting a predicate function or table for the patterns? Then in userland could do pattern matching at own peril or other testing methods.
No need to worry about fennel if not interested, here's the lua equivalent:
use("gnikdroy/projections.nvim", {
after={"telescope.nvim"},
config=function () require("config.plugins.projections") end
})
-- Equivalent lua of config/plugins/projections.fnl
local projections = require("projections")
projections.setup({
workspaces={
{"~/projects", {".git"}},
{"~/dotfiles", {".git", ".org"}} -- Fixed this given the above
}
})
Lastly, just looked for ~/.local/share/nvim/projections_workspaces.json
but it does not seem to exist.
Supporting a predicate function would be fine. But then these types of thing can only be done from config and not from the json file.
I am open to bringing back lua patterns, which would enable a lot. The more worrying issue is that it is not even recognizing .git folders. I will report after testing a bit.
I cannot reproduce this at all, sadly.
Workspace.get_workspaces_from_config()
Returning an empty table, even though projections.config.config.workspaces has the table as defined below
This shouldn't happen, the function itself is very simple. https://github.com/GnikDroy/projections.nvim/blob/07540a1c089785cafe8690e096447cf1a166c497/lua/projections/workspace.lua#L113-L128
Since, you have a fork setup on your machine anyway, can you test out that function on your machine?
packer
supports including plugins from your filesystem, so it is pretty simple to do this.
Just replace
use("gnikdroy/projections.nvim", {
with
use(vim.fs.normalize("/path/to/plugin"), {
Maybe replace the function with,
function Workspace.get_workspaces_from_config()
local workspaces = {}
vim.pretty_print(config.workspaces)
for _, ws in ipairs(config.workspaces) do
-- has been configured for { path, patterns }
vim.pretty_print(ws)
if type(ws) == "table" then
local path, patterns = unpack(ws)
table.insert(workspaces, Workspace.new(Path.new(path), patterns))
end
-- has been configured for "path"
if type(ws) == "string" then
table.insert(workspaces, Workspace.new(Path.new(ws), config.patterns))
end
end
vim.pretty_print(workspaces)
workspaces = utils._unique_workspaces(workspaces)
vim.pretty_print(workspaces)
return workspaces
end
and post the result of :messages
here
You can also try with an empty patterns list {}
. This will select all subdirectories.
Any performance regressions will be handled once they arrive.
💡 Aha figured it out!
I was able to get it working by replacing the definition of the get_workspaces_from_config with an identical definition at runtime and that worked.
This got me thinking it had something to do with timing like perhaps the extension was calling get_workspaces_from_config before projections was setup, which would explain why the function returned an empty table.
I tried moving the Sessions require below my setup call. My config/plugins/projections.fnl started from:
(local projections (require :projections))
(local Session (require :projections.session))
(local telescope (require :telescope))
(projections.setup
{:workspaces [["~/projects" [".git"]]
["~/dotfiles" []]]})
;; Switch to project if vim was started in project dir
(let [switcher (require :projections.switcher)]
(vim.api.nvim_create_autocmd
[:VimEnter]
{:callback #(when (= (vim.fn.argc) 0)
(switcher.switch (vim.loop.cwd)))}))
;; Auto-save session on exit
(vim.api.nvim_create_autocmd
[:VimLeavePre]
{:callback #(Session.store (vim.loop.cwd))})
;; Register a command to restore the last project session
(vim.api.nvim_create_user_command
:RestoreProjectSession
(fn []
(Session.restore (vim.loop.cwd)))
{})
(vim.opt.sessionoptions:append "localoptions")
(telescope.load_extension :projections)
Then changed it to:
(local projections (require :projections))
(local telescope (require :telescope))
(projections.setup
{:workspaces [["~/projects" [".git"]]
["~/dotfiles" []]]})
(local Session (require :projections.session))
;; Switch to project if vim was started in project dir
(let [switcher (require :projections.switcher)]
(vim.api.nvim_create_autocmd
[:VimEnter]
{:callback #(when (= (vim.fn.argc) 0)
(switcher.switch (vim.loop.cwd)))}))
;; Auto-save session on exit
(vim.api.nvim_create_autocmd
[:VimLeavePre]
{:callback #(Session.store (vim.loop.cwd))})
;; Register a command to restore the last project session
(vim.api.nvim_create_user_command
:RestoreProjectSession
(fn []
(Session.restore (vim.loop.cwd)))
{})
(vim.opt.sessionoptions:append "localoptions")
(telescope.load_extension :projections)
The only difference was moving:
(local Session (require :projections.session))
Below the setup call, and sure enough once I restarted neovim it started working correctly showing all the projects I can switch to and even restored the last file I had open in them!
I have not looked into why the require order matters so much here. Happy to look into it further but at the same time I don't think it would be unreasonable to see if someone else runs into it before spending more time on it as my configuration is not likely the most common setup.
Thanks for giving it a thorough look. That was a tricky one!
I see. Yes the order matters here, probably in a lot of other plugins as well.
Session
uses projection.config
and projection.config
is setup by setup()
. If you load Session
before calling setup
, Session
will cache the value of config
(which has default values!) and subsequent setup()
will have no effect on Session
.
I can remove the caching behavior, but I think most people do call setup()
before loading anything. So, I will keep the current behavior. I have renamed the issue to better reflect the problem for future users.
Reproduction
:Telescope projections
either from hotkey or manual cmdExpected
.git
directoryActual
Exploration
Read through some of the code and pinpointed it to:
Returning an empty table, even though
projections.config.config.workspaces
has the table as defined below.Config