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: allow save_key to be a function #30

Open
aarondill opened this issue Mar 22, 2024 · 2 comments
Open

Feat: allow save_key to be a function #30

aarondill opened this issue Mar 22, 2024 · 2 comments

Comments

@aarondill
Copy link

I'd like to assign a function that returns the root to save_key.
This would allow me to use LSP to return the root instead of only cwd and git_root.
The new type of save_key would be

---@type string|fun(): string?

if the function returns nil, use the CWD as the root, else use the returned value

@otavioschwanck
Copy link
Owner

I'd like to assign a function that returns the root to save_key. This would allow me to use LSP to return the root instead of only cwd and git_root. The new type of save_key would be

---@type string|fun(): string?

if the function returns nil, use the CWD as the root, else use the returned value

You can define the save_key on lua/arrow/save_keys.lua and open an PR to arrow. This way, others will can use too.

The reason that save_key is not free is because it can be very sensitive (and break other parts if not well implemented)

@aarondill
Copy link
Author

aarondill commented Mar 23, 2024

@otavioschwanck id like to use the algorithm defined in this file (taken from folke/LazyVim), which I feel is slightly out of scope for any PR here.

perhaps if we allowed save_key to be an array, we could use each in turn and fallback to cwd if all fail. ie, {"lsp", "git", { "markers", {listOfMarkers} }, "cwd" }

which would call

save_key.lsp()
save_key.git()
--same as: save_key.markers({listOfMarkers)
save_key.markers(unpack({listOfMarkers})
save_key.cwd()

this could then also allow users to supply a function for each marker, which would then be called.

basically, if save_key is a string, wrap it in a table (to make other processing easier)
for each save_key, if it's a string, index the save_key.lua module for the function, if it's a function, call it, if it's a table (assuming variable t), call t[1](unpack(t, 2)), allowing the users to pas options.

I could then add the lsp, and markers keys to save_key.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants