fix(lsp): accept file URIs without a hostname

RFC 8089, which defines the file URI scheme, also allows URIs without a
hostname, i.e. of the form file:/path/to/file. These are returned by
some language servers and accepted by other LSP implementations, such as
VSCode's, so it is reasonable for us to accept them as well.
This commit is contained in:
Alessandro Pezzoni 2021-07-07 23:34:22 +01:00
parent 4547137aaf
commit a2c2a08652

View File

@ -52,7 +52,7 @@ end
--@private --@private
local function is_windows_file_uri(uri) local function is_windows_file_uri(uri)
return uri:match('^file:///[a-zA-Z]:') ~= nil return uri:match('^file:/+[a-zA-Z]:') ~= nil
end end
--- Get a URI from a file path. --- Get a URI from a file path.
@ -74,7 +74,7 @@ local function uri_from_fname(path)
return table.concat(uri_parts) return table.concat(uri_parts)
end end
local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*' local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):/+.*'
--- Get a URI from a bufnr --- Get a URI from a bufnr
--@param bufnr (number): Buffer number --@param bufnr (number): Buffer number
@ -100,10 +100,10 @@ local function uri_to_fname(uri)
uri = uri_decode(uri) uri = uri_decode(uri)
-- TODO improve this. -- TODO improve this.
if is_windows_file_uri(uri) then if is_windows_file_uri(uri) then
uri = uri:gsub('^file:///', '') uri = uri:gsub('^file:/+', '')
uri = uri:gsub('/', '\\') uri = uri:gsub('/', '\\')
else else
uri = uri:gsub('^file://', '') uri = uri:gsub('^file:/+', '/')
end end
return uri return uri
end end