-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(uri): support uri path parsing with
Path.from_uri
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
local M = {} | ||
|
||
---Parse a uri and return its path. Protocol is saved at `self._uri_protocol`. | ||
---@param uri string | ||
---@return string protocol # URI protocol (without `:`) such as `file`, `sftp`. | ||
---@return string filepath # Path-like string representation that must be passed to `Path.new` to be normalized. | ||
function M.parse_uri(uri) | ||
local colon = uri:find(":") | ||
assert(colon, string.format([[%s is not a valid uri.]], uri)) | ||
assert(colon > 2, string.format([[Failed to parse uri schema for '%s'. Please report a BUG.]], uri)) | ||
local protocol = uri:sub(1, colon - 1) | ||
local file = vim.uri_decode(uri):gsub(protocol .. ":/", ""):gsub("^/+([a-zA-Z]:)", "%1") | ||
return protocol, file | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters