When i use code-rewriting power tools, or even a simple copy/paste to move a form, my vscode bookmarks break (they are trying to keep track of line number, and and often failing to do so). This seems like a basic tool that is fundamentally broken. Is there a way to keep track cherry-picked code locations that uses more semantic or dynamic tooling? What are others doing?
I do not know. Therefore, circumstances call for uninformed speculation: Probably the bookmarker subscribes to document-change events just as Calva's document model does. If that's so, then commands that effect small edits (however numerous) will usually be "bookmark-friendlier" than commands implemented as one giant change-of-document-text, since the bookmarker will have no idea what to do with bookmarks that were within any particular changed region. Calva's reformat commands make lots of tiny little insertions and removals, but I do not know how VS Code implements dragging selections.
For semantically aware "bookmarks" I sometimes enjoy a tree view that occasionally presents itself in my field of vision as an alternative to the list of files. That view, and go-to-file and go-to-definition, make it reasonably quick to find what I'm looking for.
I am using the standard popular vscode extension. I looked for others but had the same results. I dont know what the underlying line-tracking mechanism is.
One alternative could be to use one of the documentation libraries that can scan the codebase and generate and index html page with code links than can jump right to the local code in the ide. And maybe put medata on certain forms to gather and index of “favorites”. This sounds a bit heavyweight though. I was wondering if there was something more in-line in the editor. Maybe using the code outline functionality, or clojure-lsp, etc.
Probably using joyride + clojure-lsp would go far. But is there any prior art?
I'm curious what you use bookmarks for? I don't think I've ever encountered anyone using them so I'm not sure what the use case would be...
If my codebase is sprawling, and I have a related set of functions in different files, my first thought is to have a curated local index of relevant code to work from. This can reduce mental clutter, and also serve as a navigator panel to jump around. It makes sense for me for this index to be be granular on the level of forms, rather than files. Because files can be long and hard to decipher on the fly. In clojure, I can often build a new pure namespace to collect disparate things. And navigating code definitions and references definitely helps. But in non-clojure code, the classical bookmarking think feels even more helpful.
If that cherrypicked index of forms is tight enough, the bookmarks could even be used in eval commands.
Interesting. I'll have to look at that -- we have 150k lines of Clojure (and a similar amount of JS in another repo). What extension do you use?
https://github.com/alefragnani/vscode-bookmarks I believe this is the default popular one
Critically the bookmarks can be named, to create a semantic index. By default the view sorts bookmarks by file, and doesn’t have different bookmark groups, which is not ideal. I want like a lightweight mini-workspace (that can span files) with custom location names that are relevant to the working context.
4.3M downloads - impressive. I'll try it out. Always looking for ways to tweak my workflow.
In my limited testing. Commands like reformat code or slurp exp seems to trigger bookmark line number updates. But drag-sexpy-forward/backward dont.
Vscode can produce and use code locations links like this
But again, these are not stable. It seems like line number is not the right abstraction. I wonder if there could be a thing to track the code form. It should work in comment forms and non-named code. Maybe the only solution is to lint the code to set anchors?
If the code is pretty stable, this is not much of a problem.fyi this one gives “meta” bookmarks to collect locations by linting an @context token
https://marketplace.visualstudio.com/items?itemName=tintinweb.vscode-inline-bookmarks
This one allows one to collect and restore a group of tabs. Which servers as a kind of mini-workspace. But only works at file level. https://marketplace.visualstudio.com/items?itemName=amodio.restore-editors
The author of that popular extension is since a while a member of the VS Code team.
Centuries ago I used Panic's editor Coda, which has since been renamed and rebranded, and it had a feature where you could create a comment with a particular prefix, sort of like //MARK: and it would show up in the navigation panels, could be searched for, etc., functioning just like a bookmark. I always loved that feature to help me organize my code, and I haven't ever seen anything like it anywhere else.
seems like the “Inline Bookmarks” extension above is supposed to do something like that. But It doesnt seem to be working for me.
Some potential resources for a clojure-specific tool. https://clojure-lsp.io/features/#show-all-workspaceproject-symbols https://clojure-lsp.io/features/#project-tree https://calva.io/clojure-lsp/#extra-commands https://github.com/borkdude/edamame https://github.com/clj-kondo/clj-kondo/tree/master/analysis prior art combining the above? https://github.com/borkdude/unused-deps
> In my limited testing. Commands like reformat code or slurp exp seems to trigger bookmark line number updates. But drag-sexpy-forward/backward dont. This is an interesting observation, I think we have some different ways we apply edits, so it could be that this matters. WDYT, @phill?