Skip to content

LSP: resolve leading-slash links against the notebook root#745

Open
zmre wants to merge 2 commits into
zk-org:devfrom
zmre:fix/notebook-root-links
Open

LSP: resolve leading-slash links against the notebook root#745
zmre wants to merge 2 commits into
zk-org:devfrom
zmre:fix/notebook-root-links

Conversation

@zmre

@zmre zmre commented Jul 6, 2026

Copy link
Copy Markdown

Links like [Note](/sub/note-a) are now resolved relative to the notebook root, which aligns with the way most Markdown renderers treat root-relative destinations. So if building notes as a series of web pages, absolute refers to the project root. We still fallback to the filesystem root for absolute to allow links to anything on the drive.

Previously these links were joined onto the current note's directory (ie, /path/to/note_parent//absolute/link which I think produced unexpected behaviors in almost all cases, broke go-to-definition, hover, references, and produced false dead-link diagnostics for any links with leading slashes.

This was brought up and closed in #494 , but I believe it has merit and I don't see any downside to supporting this behavior. Obviously feel free to disagree.

Fixes #494

Note

I didn't see anything in CONTRIBUTING.md about AI. I'm mostly a rust programmer and have only lightly dabbled in Go, so I did use AI to help me with this fix and especially in generating tests to validate it. If that's not okay, I completely understand. I hand wrote aspects and reviewed every line manually and I believe this is a useful contribution of good quality.

@zmre

zmre commented Jul 8, 2026

Copy link
Copy Markdown
Author

Just some more context: I submitted this because zk commonly flags errors in my docs that aren't errors. I don't want to suppress them because I want to know when there are bad links. The pattern of using absolute paths to refer to the top of the repo is very common and wasn't previously working for either actual absolute paths (relative to filesystem root) or for repo-relative ones, but now can work for either of those cases. Anyway, I hope it's a welcome change.

zmre added 2 commits July 11, 2026 19:07
Links like [Note](/sub/note-a) are now resolved relative to the notebook
root, which aligns with the way most Markdown renderers treat root-relative
destinations. So if building notes as a series of web pages, absolute refers
to the project root. We still fallback to the filesystem root for absolute
to allow links to anything on the drive.

Previously these links were joined onto the current note's directory
(ie, `/path/to/note_parent//absolute/link` which I think produced unexpected
behaviors in almost all cases, failed to resolve, broke go-to-definition,
hover, references, and produced false dead-link diagnostics.

This was closed in zk-org#494, but I believe it has merit and I don't see any
downside to supporting this behavior.

Fixes zk-org#494
@WhyNotHugo WhyNotHugo force-pushed the fix/notebook-root-links branch from e972203 to f72c853 Compare July 11, 2026 17:07
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

Successfully merging this pull request may close these issues.

LSP is unable to resolve non-relative paths

1 participant