diff options
Diffstat (limited to 'runtime/lua/vim/uri.lua')
-rw-r--r-- | runtime/lua/vim/uri.lua | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/runtime/lua/vim/uri.lua b/runtime/lua/vim/uri.lua index 9c3535c676..f1a12c72ec 100644 --- a/runtime/lua/vim/uri.lua +++ b/runtime/lua/vim/uri.lua @@ -7,6 +7,9 @@ local uri_decode do local schar = string.char + + --- Convert hex to char + --@private local function hex_to_char(hex) return schar(tonumber(hex, 16)) end @@ -34,6 +37,8 @@ do else tohex = function(b) return string.format("%02x", b) end end + + --@private local function percent_encode_char(char) return "%"..tohex(sbyte(char), 2) end @@ -45,10 +50,14 @@ do end +--@private local function is_windows_file_uri(uri) return uri:match('^file:///[a-zA-Z]:') ~= nil end +--- Get a URI from a file path. +--@param path (string): Path to file +--@return URI local function uri_from_fname(path) local volume_path, fname = path:match("^([a-zA-Z]:)(.*)") local is_windows = volume_path ~= nil @@ -67,6 +76,9 @@ end local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*' +--- Get a URI from a bufnr +--@param bufnr (number): Buffer number +--@return URI local function uri_from_bufnr(bufnr) local fname = vim.api.nvim_buf_get_name(bufnr) local scheme = fname:match(URI_SCHEME_PATTERN) @@ -77,6 +89,9 @@ local function uri_from_bufnr(bufnr) end end +--- Get a filename from a URI +--@param uri (string): The URI +--@return Filename local function uri_to_fname(uri) local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri) if scheme ~= 'file' then @@ -93,7 +108,10 @@ local function uri_to_fname(uri) return uri end --- Return or create a buffer for a uri. +--- Return or create a buffer for a uri. +--@param uri (string): The URI +--@return bufnr. +--@note Creates buffer but does not load it local function uri_to_bufnr(uri) local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri) if scheme == 'file' then |