Skip to content

Commit e6ffe7c

Browse files
authored
Make sure we handle # in links (#3999)
- see #3995
1 parent 7514fe7 commit e6ffe7c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lsp-mode.el

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,12 @@ On other systems, returns path without change."
17741774
(file
17751775
(concat (decode-coding-string (url-filename url)
17761776
(or locale-coding-system 'utf-8))
1777-
(when target
1777+
(when (and target
1778+
(not (s-match
1779+
(rx "#" (group (1+ num)) (or "," "#")
1780+
(group (1+ num))
1781+
string-end)
1782+
uri)))
17781783
(concat "#" target))))
17791784
(file-name (if (and type (not (string= type "file")))
17801785
(if-let ((handler (lsp--get-uri-handler type)))
@@ -4869,7 +4874,7 @@ Applies on type formatting."
48694874
(pcase type
48704875
("file"
48714876
(find-file (lsp--uri-to-path url))
4872-
(-when-let ((_ line column) (s-match (rx "#" (group (1+ num)) "," (group (1+ num))) url))
4877+
(-when-let ((_ line column) (s-match (rx "#" (group (1+ num)) (or "," "#") (group (1+ num))) url))
48734878
(goto-char (lsp--position-to-point
48744879
(lsp-make-position :character (1- (string-to-number column))
48754880
:line (1- (string-to-number line)))))))

test/lsp-common-test.el

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727

2828
(ert-deftest lsp--path-to-uri-1 ()
2929
(elenv-with-windows
30-
(let ((lsp--uri-file-prefix "file:///"))
31-
(should (equal (lsp--path-to-uri "c:/Users/?/") "file:///c:/Users/%3F/"))))
30+
(let ((lsp--uri-file-prefix "file:///"))
31+
(should (equal (lsp--path-to-uri "c:/Users/?/") "file:///c:/Users/%3F/"))))
3232
(elenv-with-os '(darwin gnu/linux)
33-
(let ((lsp--uri-file-prefix "file://"))
34-
(should (equal (lsp--path-to-uri "/root/file/hallo welt") "file:///root/file/hallo%20welt")))
35-
(should (equal (lsp--uri-to-path "file:///home/nim-%23devel")
36-
"/home/nim-#devel"))))
33+
(let ((lsp--uri-file-prefix "file://"))
34+
(should (equal (lsp--path-to-uri "/root/file/hallo welt") "file:///root/file/hallo%20welt")))
35+
(should (equal (lsp--uri-to-path "file:///home/nim-%23devel")
36+
"/home/nim-#devel"))
37+
(should (equal (lsp--uri-to-path "file:///home/yyoncho/Sources/DemoProjects/lua/lua.lua#1#9")
38+
"/home/yyoncho/Sources/DemoProjects/lua/lua.lua"))))
3739

3840
(ert-deftest lsp--path-to-uri-2 ()
3941
(let ((lsp--uri-file-prefix "file:///")

0 commit comments

Comments
 (0)