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

fix: magnet link #429

Merged
merged 2 commits into from
Jul 11, 2024
Merged

fix: magnet link #429

merged 2 commits into from
Jul 11, 2024

Conversation

billymosis
Copy link
Contributor

  • Added check for magnet links (magnet:?xt) to prevent not found false alarms in LSP.

Context:
image

@tjex
Copy link
Member

tjex commented Jul 9, 2024

Thanks for the pr :)

The approach so far for appeasing the LSP is to ignore urls that are not links to notes. #391 is an example of this.

Here in document.go

for _, match := range markdownLinkRegex.FindAllStringSubmatchIndex(line, -1) {

I think it's still a better approach than adding a magnet link scheme to IsURL because

a) it reduces load on the lsp and
b) it doesn't dilute the meaning of IsURL.

While a magnet link is in essence a url, for our purposes, it may be cleaner to just ignore it rather than validate it? Happy for any counter thoughts.

@billymosis
Copy link
Contributor Author

Thanks for the feedback!

I missed the file and line you mentioned in document.go. I see your point about ignoring URLs that are not links to notes, as shown in PR #391.

Just to provide more context that I use obsidian and zk . And on the obsidian there was no linting error. And I could just click the magnet link easily. If I were using exclamation on the front and using back tick it will clutter my obsidian view.

What if I add something like this on existing file:/// check

			// ignore tripple dash file URIs [title](file:///foo.go)
			if match[5]-match[4] >= 8 {
				linkURL := line[match[4]:match[5]]
				fileURIresult := linkURL[:8]
				if fileURIregex.MatchString(fileURIresult) {
					continue
				}
                        // Ignore magnet
				if regexp.MustCompile(`magnet:?`).MatchString(fileURIresult) {
					continue
				}
			}

@tjex
Copy link
Member

tjex commented Jul 10, 2024

That's quite convenient that it's also 8 chars.

May as well add it in the same if statement, to reduce branching and keep them together.
And it would be nicer to declare the regex for the magnet link as a variable beforehand (up in the file where the others are also declared), to maintain readability and reusability.

So:

magnetRegex := regexp.MustCompile(`magnet:?`)

			// ignore tripple dash file URIs [title](file:///foo.go) and magnet links
			if match[5]-match[4] >= 8 {
				linkURL := line[match[4]:match[5]]
				fileURIresult := linkURL[:8]
				if fileURIregex.MatchString(fileURIresult) || if magnetRegex.MatchString(fileURIresult) {
					continue
				}
			}

Double check you don't need to escape the ? char in the regex statement!

@billymosis
Copy link
Contributor Author

I've updated the commit. Let me know if adjustments are needed.

Copy link
Member

@tjex tjex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

@tjex tjex merged commit 53df879 into zk-org:main Jul 11, 2024
3 checks passed
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.

2 participants