mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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:
		| @@ -104,6 +104,10 @@ function M.uri_to_fname(uri) | |||||||
|   if scheme ~= 'file' then |   if scheme ~= 'file' then | ||||||
|     return uri |     return uri | ||||||
|   end |   end | ||||||
|  |   local fragment_index = uri:find('#') | ||||||
|  |   if fragment_index ~= nil then | ||||||
|  |     uri = uri:sub(1, fragment_index - 1) | ||||||
|  |   end | ||||||
|   uri = M.uri_decode(uri) |   uri = M.uri_decode(uri) | ||||||
|   --TODO improve this. |   --TODO improve this. | ||||||
|   if is_windows_file_uri(uri) then |   if is_windows_file_uri(uri) then | ||||||
|   | |||||||
| @@ -88,6 +88,12 @@ describe('URI methods', function() | |||||||
|  |  | ||||||
|         eq('/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt', exec_lua(test_case)) |         eq('/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt', exec_lua(test_case)) | ||||||
|       end) |       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) |     end) | ||||||
|  |  | ||||||
|     describe('decode Windows filepath', function() |     describe('decode Windows filepath', function() | ||||||
| @@ -184,6 +190,15 @@ describe('URI methods', function() | |||||||
|         ]] |         ]] | ||||||
|         ) |         ) | ||||||
|       end) |       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) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ilia Choly
					Ilia Choly