fix(lua): remove uri fragment from file paths (#27647)

Problem: Some LSP servers return `textDocument/documentLink` responses
         containing file URIs with line/column numbers in the fragment.
         `vim.uri_to_fname` returns invalid file names for these URIs.

Solution: Remove the URI fragment from file URIs.
This commit is contained in:
Ilia Choly
2024-02-28 04:50:53 -05:00
committed by GitHub
parent cb146cc4aa
commit 0190771713
2 changed files with 19 additions and 0 deletions

View File

@@ -88,6 +88,12 @@ describe('URI methods', function()
eq('/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt', exec_lua(test_case))
end)
it('file path with uri fragment', function()
exec_lua("uri = 'file:///Foo/Bar/Baz.txt#fragment'")
eq('/Foo/Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)'))
end)
end)
describe('decode Windows filepath', function()
@@ -184,6 +190,15 @@ describe('URI methods', function()
]]
)
end)
it('uri_to_fname returns non-file schema URI with fragment unchanged', function()
eq(
'scheme://path#fragment',
exec_lua [[
return vim.uri_to_fname('scheme://path#fragment')
]]
)
end)
end)
end)