feat(#1851): add bookmarks.persist, default path: vim.fn.stdpath("data") .. "/nvim-tree-bookmarks.json", disabled by default#3033
Conversation
alex-courtis
left a comment
There was a problem hiding this comment.
This looks great! I'll give it a full review and test in the next few days.
Initial thoughts:
- Should we be using
vim.json.encodeinstead of the fn ? - Please don't move existing methods (constructor, toggle)
- This should be an optional feature in
nvim-tree-opts, disabled by default - This needs checking and safety
- Use a pcall or similar to prevent an error being raised
- Report failures to the user
This comment has been minimized.
This comment has been minimized.
I'm happy with this providing the above is addressed. |
|
@alex-courtis updated |
|
Proposed help, please correct indexes and run ==============================================================================
5.19 OPTS: BOOKMARKS *nvim-tree-opts-bookmarks*
*nvim-tree.bookmarks.persist*
Persist bookmarks to a json file containing a list of absolute paths.
Type: `boolean` | `string`, Default: `false`
`true`: use default: `stdpath("data") .. "/nvim-tree-bookmarks.json"`
`string`: absolute path of your choice. |
lua/nvim-tree/explorer/filters.lua
Outdated
| if explorer then | ||
| for _, node in pairs(explorer.marks:list()) do | ||
| status.bookmarks[node.absolute_path] = node.type | ||
| for key, node in pairs(explorer.marks.marks) do |
There was a problem hiding this comment.
This is private and should not be accessed, see CI failure
Please use Marks:list()
I know this is not your code, but we can clean this up by using self.explorer (guaranteed not null) instead of calling core.
Edit: it appears that self.explorer.marks:list() is now returning an array of booleans instead of an array of nodes.
lua/nvim-tree.lua
Outdated
| marks = { | ||
| enable_persistence = false, | ||
| save_path = nil, -- nil will default to stdpath("data") .. "/nvim-tree-bookmarks.json" | ||
| }, |
There was a problem hiding this comment.
| marks = { | |
| enable_persistence = false, | |
| save_path = nil, -- nil will default to stdpath("data") .. "/nvim-tree-bookmarks.json" | |
| }, | |
| bookmarks = { | |
| persist = false, | |
| }, |
Rather than a toggle and path, we can use just one option that is boolean or string. This is consistent with other options.
See proposed help
We then add the type explitictly so that it may be validated. Add to ACCEPTED_TYPES:
bookmarks = {
persist = { "boolean", "string" },
},|
I've added you to this repository so that you may push branches and run CI in the future. |
|
Apologies, I was not clear about my request to simplify options and proposed help Attached is a patch with those changes gunzip simplify_options.diff.gz
git apply simplify_options.diff |
|
@xiantang I was looking for this feature! Could you kindly add the patched changes so we can all benefit from your implementation? Thank you and @alex-courtis for working on this :) |
If we don't hear back from @xiantang I would be most grateful for a new PR from you @bburgess19 with all the changes. |
|
Would you like me to complete this and merge it? |
|
ok i will continue it
…On Sat, 14 Jun 2025 at 3:29 PM, Alexander Courtis ***@***.***> wrote:
*alex-courtis* left a comment (nvim-tree/nvim-tree.lua#3033)
<#3033 (comment)>
@xiantang <https://github.com/xiantang>
Would you like me to complete this and merge it?
—
Reply to this email directly, view it on GitHub
<#3033 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIHB3TZ3Y5GOG3S2QK5HYUT3DPFNZAVCNFSM6AAAAABUBK6ZJGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZSGQZDGOBVGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
sorry for misunderstanding, u can complete this merge request.
…On Sat, 14 Jun 2025 at 3:29 PM, Alexander Courtis ***@***.***> wrote:
*alex-courtis* left a comment (nvim-tree/nvim-tree.lua#3033)
<#3033 (comment)>
@xiantang <https://github.com/xiantang>
Would you like me to complete this and merge it?
—
Reply to this email directly, view it on GitHub
<#3033 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIHB3TZ3Y5GOG3S2QK5HYUT3DPFNZAVCNFSM6AAAAABUBK6ZJGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZSGQZDGOBVGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I would be very grateful if you completed. You deserve all the credit for this great feature. |
|
i will work on this feature. |
Co-authored-by: Alexander Courtis <alex@courtis.org>
- Rename opts.marks to opts.bookmarks for better clarity - Simplify persist option to boolean | string (true uses default path) - Implement lazy node resolution for loaded bookmarks - Update documentation with new bookmarks configuration - Improve bulk operations to use public list() method consistently
- Rename opts.marks to opts.bookmarks for better clarity - Simplify persist option to boolean | string (true uses default path) - Implement lazy node resolution for loaded bookmarks - Update documentation with new bookmarks configuration - Improve bulk operations to use public list() method consistently
Co-authored-by: Alexander Courtis <alex@courtis.org>
|
@alex-courtis i think its ready for review now |
|
Many thanks for getting onto this one. I'll get to a review by this weekend. Please, please don't create copilot reviews :) |
|
I can't block the copilot user. I have tried to limit it at the org level. I guess the next step is Add Copilot custom instructions |
It's really annoying; I've already disabled it. |
There was a problem hiding this comment.
Looking good! A couple of small fixes and we're good to merge.
Test cases
1. Persist one mark then restart:
OK - mark is shown
2. Remove one mark then restart:
OK - mark not shown, file empty
3. Persist mark on file, quit, delete it, restart:
OK - mark is still in file
4. chmod 444 ~/.local/share/nvim/nvim-tree-bookmarks.json and mark:
FAIL - error shows "Invalid bookmarks.save_path" not "Invalid bookmarks.persist"
5. Repeat above and mark:
OK - no messages, persistence disabled
6. echo foobarbaz > ~/.local/share/nvim/nvim-tree-bookmarks.json:
OK - correct behaviour
message doesn't match the style of save failures, containing some stack: "Failed to load bookmarks: ...ker/start/nvim-tree.lua.dev/lua/nvim-tree/marks/init.lua:49: Expected value but found invalid token at character 1"
However there's not much we can do about that due to lua's poor exception handling. We'd need to check each and every io, file, vim.json call which is just not practical. It's fine: the save case will likely be the most common and has a nice message.
7. Reopen tree:
OK - no messages, persistence disabled for explorer instance
Error message will appear when you creat a new explorer instance however that seems like reasonable behaviour.
persist = "/tmp/foo.json"
OK - persists
persist = "/foo/bar/foo.json"
OK - error
Recommendations
- 4: fix message
Small Fixes
- Please use a
string.formatfor all notify calls.
notify.warn("Failed to load bookmarks: " .. loaded_marks) string concatenation can throw an exception on nils
- Remove "Enabling this is not useful as there is no means yet to persist bookmarks" from help
This is now useful :)
|
im fixing it |
…ation - Replace string concatenation with string.format in bookmark error messages - Remove outdated comment about bookmark persistence from documentation
|
d49cf10 @alex-courtis, please check this commit, if u have small changes to make, just apply them on this PR and merge it. tks |
alex-courtis
left a comment
There was a problem hiding this comment.
Many thanks for your contribution!
close #1851 (comment)