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

LSP autocompletion for heading IDs #224

Open
mickael-menu opened this issue Jun 3, 2022 · 7 comments
Open

LSP autocompletion for heading IDs #224

mickael-menu opened this issue Jun 3, 2022 · 7 comments
Labels
feature request Something is missing

Comments

@mickael-menu
Copy link
Member

Discussed in zk-org/zk-nvim#53

Originally posted by @dzintars June 3, 2022
Hi all. REALLY impressive tooling! :)
I have a question about Heading ID autocompletion?
Is it possible?
I know that if many nested levels i a single note breaks the "atomicity rule", but still..
image
There is an image of what i mean. That Tmux note contains few sections, i would like to link to.
This is how it looks in Obsidian:
Frame 1
I believe block references are Obsidian specific only so i don't care much about them.
But Heading IDs would be helpful to have after typing #. Currently it returns list of tags.

@mickael-menu mickael-menu added the feature request Something is missing label Jun 3, 2022
@mickael-menu
Copy link
Member Author

It's not high on my personal list as my notes are pretty small, but this should certainly be possible with zk.

It requires a few things:

  1. Indexing the HTML anchors in the database, and generate some for the headings.
  2. Adding a new LSP auto-completion type triggered with # inside a link, which will return the anchors for the linked note.
  3. Properly handle jumping to an anchor from an LSP link, instead of going to the top of the linked note.

Number 1 is not so easy. HTML anchors (<a id="my-header"></a>) are standardized, but not the generation of anchors from headings. Most implementations seem to use lowercased camel-case but there are variations and treatment of special characters is unclear.

If someone wants to help kickstart this feature without diving in the code, it would be helpful to find and list the various implementations used to generate heading anchors.

@eric-hansen
Copy link

Regarding anchor ID...

Why not just create a hash (sha256 or 512) of it? This way you don't need to worry about all these weird edge cases, the id will be standardized and consistent, and won't have to worry about formatting.

@dzintars
Copy link

dzintars commented Jun 3, 2022

It is definitely just a "nice to have" feature and not the deal breaker for me personally.

@mickael-menu
Copy link
Member Author

@eric-hansen Inside zk we can handle it however we want. I'm mainly worried about interoperability: it should work in Obsidian, GitHub, Emanote/Neuron, etc.

An alternative could be to insert an HTML anchor manually when linking to a section, but this would look a bit ugly in the notes IMHO.

@mickael-menu
Copy link
Member Author

mickael-menu commented Jun 3, 2022

@mickael-menu
Copy link
Member Author

Maybe inserting a manual anchor is not so bad. Yes it's ugly, but it's guaranteed to work everywhere and it's also stable if you change the heading title or reorder the sections (assuming index-based generated IDs).

# My heading
<a id="e3f"/>

Content with [link](#e3f)

However this poses some challenging with LCP, I'm not sure we can modify the target document during completion.

@tomtomjhj
Copy link

I'm also in favor of manual anchor because it is grep-able and can be given some meaningful name.

Personally, I really like Obsidian's block ID despite its incompatibility, because it looks clean in plain text and enables fine-grained references.
I actually planned to implement it (currently only the parser is implemented), but I couldn't find time to work on it.

related: srid/emanote#105

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

No branches or pull requests

4 participants