Feature: Project-relative paths for cross-machine annotation syncing #23
Labels
No labels
autorelease: pending
autorelease: tagged
bug
ci/cd
documentation
duplicate
enhancement
good first issue
help wanted
improvement
invalid
priority
high
priority
low
question
refactor
size
L
size
M
size
S
size
XS
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
noe.trevino/haunt.nvim#23
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Did you check the docs?
Is your feature request related to a problem? Please describe.
Currently, haunt.nvim stores file paths as absolute paths in the JSON format, which makes syncing annotations across different machines difficult or impossible when project directories are located at different paths.
Describe the solution you'd like
Implement project root detection and store file paths relative to the project root instead of absolute paths.
Project Root Detection
Detect project root by looking for common markers (in order of priority):
.gitdirectorypyproject.toml(Python)Cargo.toml(Rust)package.json(Node.js)go.mod(Go).projectrootor similar custom markerStorage Format
Instead of:
Store as:
or even simpler, organize by project:
Describe alternatives/other solutions you've considered
Additional context
No response
@EdSplendor
I actually think the first solution you mentioned is better.
I am going to think about this and give it a shot.
To be honest, it will not be urgently at the top of my list. I think the effort to reward ratio for this is not the best.
I will keep in touch
I was looking for the same thing. Turns out that you can just do this with an autocommand by reinitialising haunt on BufEnter, specifying
data_dirby searching upwards until you find a git repo.This is a bit hacky, but it's only a few lines of code and reliably delivers me a
haunts/directory at the root of my git repo.I'll do some digging through the codebase; the reinitialisation was a matter of playing it safe, but optimally we could just set
data_dirdirectly.P.S. Great plugin! Thanks for all the hard work!
@impact-basin
WOW. that is freaking sick. I am glad i exposed setting the data directory.
Calling
.setupDoes not reinstall the plugin, but it DOES clear out all of your configurations options, and merges again with the default opts. I can expose a function that changes the data directory, but we should still need to refresh all the bookmarks since we are changing where things are stored on disk.In terms of edge cases, I am thinking: "what if the user has two git repos at once?"
And i dont think we should support that. Its far too complex for what it is worth. This works for submodules since those use a .git file, not directory.
I think we should not support this as a full fledged feature, but we can include what you did on the readme, and i can expose the changing of the data_dir so it doesnt clear the config. (it will still do all the other stuff)
What are both of your thoughts?
Sounds great to me! Glad to be of use :-) Let me know if I can help with anything!
It seems to me that nested situations are inherently supported by finddir() -- it will find the closest-in git repo (so if you're in a submodule, it'll associate the notes with that submodule and not the parent).
Maybe it should be from the filepath of the buffer you've entered, rather than nvim's current directory, in case you're editing files across multiple git repos.
It's getting a bit late in the UK - but I'll fix this up tomorrow!
Here is the change.
https://github.com/user-attachments/assets/41f5c0d8-bbe2-41fe-8147-a80f5462ced7
which means the autocommand can now be:
And the plugin will simply reload everything, and change the data dir.
@EdSplendor @impact-basin
Please test and get back to me! I dont have to time, and I wont be able to either tomorrow.
Take a look at the
CONTRIBUTING.mdand checkout the branch of PR #33Thanks for implementing this!
I'll run through some scenarios this weekend.
This is brilliant, @TheNoeTrevino -- this is exactly how I've always wanted to keep my notes and TODOs, without ever knowing it. I've been using it all day.
The new function is working admirably. Better - it's extremely flexible, letting you swap note sources on the fly.
Here's my current janky config. This lets me switch between per-buffer notes, per-repo notes, notes held at the current working directory, and "private" notes held at the usual datapath.
This is just a sketch of something good enough for my current needs - the functions work, but the autocommand will go all funky if you open a buffer that's not in a Git repo. Some amount of sanity-checking is worthwhile.
I will have to clean this up tomorrow. It's the department happy hour now - the hour per month that the department is happy :-).
@impact-basin
Dude! that is awesome!!!
If you could do me the greatest favor:
Once you do the 'clean up' (looks great to me) could you please post in the discussions tab about this in the show and tell? People will definitely be interested in this sort of thing. I would also consider this a success story :D
I am glad that new exposed function is working well for you!! Its way better than resetting the entirety of the configuration. I am going to leave this issue open until @EdSplendor gets back to me this weekend.
@impact-basin
I believe you can do something like this:
It might be a tad slow though, since it searches upwards. I am not very familiar with 'how far it will go'
Thanks for the change_data_dir() implementation!
However, this still stores absolute paths in the JSON files themselves. For true cross-machine syncing, we'd need the JSON to contain relative paths (e.g., src/main.py instead of /home/user/project/src/main.py). This way, the JSON files could be synced via cloud storage (Dropbox, Google Drive, etc.) or committed to Git and work regardless of where the project is located on different machines.
The current solution helps organize annotations by project, but if I sync the haunts/ directory to another machine where my project is at a different path (e.g., /Users/username/code/project vs /home/username/projects/project), the absolute paths in the JSON won't match and the annotations won't load.
Unfortunately, I'm not a Lua programmer and won't be able to help with the implementation directly. However, I'll try to implement this with LLM assistance, and if I'm successful, I'll submit a pull request. If anyone with Lua experience wants to tackle this in the meantime, that would be greatly appreciated!
what if to use relative path for detected git repo and fall back to original behaviour for non git.
something like
github.com/ewok/haunt.nvim@b9699560cfI changed mainly two things:
project = same storage file, regardless of location
appear correctly after moving projects
So, now annotations should survive project moves and sync across machines.
@EdSplendor
That is one fat PR! I am going to take a look soon, but I will be honest it might take me a couple of days
@TheNoeTrevino Is there any progress on this? It would be really great if bookmarks could be relative paths. As an aside, the picker (I'm using fzf-lua) also shows the full path and ideally, it would just show enough to make the entry unique so there is more space for the annotation; on Reddit, I read in a post that that is configurable but I couldn't find it anywhere. In any case, possibly that would become moot if relative paths are supported.
@rubin55
Yes! Check out the hooks PR. The plan is for that to have a way for the users to grab the current books marks, make a copy and mutate (standardize paths and whatnot) then save to a place of their choosing.
I have been busy with moving across the country, so I Haven't gotten around to merging it, but I can prioritize it this weekend.
Once I merge I will let you know provide some snippets that might work, and we can see if it works for you or not, then we can work from there.
@rubin55
As for the fzf lua thing, I think we should open a new PR about that. To be honest, I am completely blind to issues regarding anything other than
snacks.nvimsince that is what I use. Feel free to open an issue about it and I'll see what I can do. Should be relatively simple@EdSplendor @impact-basin @ewok @rubin55
I apologize for the delay. I have spend a lot of time thinking about how to implement it, and i have added the functionality to the nightly branch for testing! I have had huge success adding my bookmarks to my NAS and targeting that, which moves them across my machines. You can choose a github repo or what not.
Here are some technical details:
{first commit hash + branch(if per branch is enabled)}. This is then hashedHere is an example of a file:
This was a huge refactor for how we do storage. So, there is a migration process.
Please, target the nightly branch and let me know how you like it!
I will be merging this into main sometimes this weekend once its been looked at a bit.
Thank you for the wait!
Please see
:h haunt-sharingfor a tutorial on this. Once you target nightly of course