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

Link parsing in VSCode breaks on non-ascii characters in titles #235

Closed
zkbpkp opened this issue Jul 5, 2022 · 2 comments · Fixed by #238
Closed

Link parsing in VSCode breaks on non-ascii characters in titles #235

zkbpkp opened this issue Jul 5, 2022 · 2 comments · Fixed by #238
Labels
bug Something isn't working

Comments

@zkbpkp
Copy link

zkbpkp commented Jul 5, 2022

Example:

image

I figured this is because regex returns offsets in bytes, not runes. Below is my quick fix for that, seems to work in VSCode, didn't test in Neovim.

diff --git a/internal/adapter/lsp/document.go b/internal/adapter/lsp/document.go
index bf32d4f..954d93e 100644
--- a/internal/adapter/lsp/document.go
+++ b/internal/adapter/lsp/document.go
@@ -176,6 +176,15 @@ func (d *document) DocumentLinkAt(pos protocol.Position) (*documentLink, error)
 	return nil, nil
 }
 
+func toRuneMatch(s string, i int) int {
+	res := 0
+	for j, _ := range s {
+	  if j >= i { break }
+	  res += 1
+	}
+	return res
+  }
+
 // DocumentLinks returns all the internal and external links found in the
 // document.
 func (d *document) DocumentLinks() ([]documentLink, error) {
@@ -217,13 +226,13 @@ func (d *document) DocumentLinks() ([]documentLink, error) {
 			if decodedHref, err := url.PathUnescape(href); err == nil {
 				href = decodedHref
 			}
-			appendLink(href, match[0], match[1], false, false)
+			appendLink(href, toRuneMatch(line, match[0]), toRuneMatch(line, match[1]), false, false)
 		}
 
 		for _, match := range wikiLinkRegex.FindAllStringSubmatchIndex(line, -1) {
 			href := line[match[2]:match[3]]
 			hasTitle := match[4] != -1
-			appendLink(href, match[0], match[1], hasTitle, true)
+			appendLink(href, toRuneMatch(line, match[0]), toRuneMatch(line, match[1]), hasTitle, true)
 		}
 	}
 
@mickael-menu mickael-menu added the bug Something isn't working label Jul 6, 2022
@mickael-menu
Copy link
Member

@zkbpkp Thank you for spotting this issue! I opened the PR #238 (branch issue-235), would you mind double-checking before I merge it? Thanks

@zkbpkp
Copy link
Author

zkbpkp commented Jul 10, 2022

@mickael-menu thank you for responding so quickly! Just checked #238, this fixes the issue for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants