mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
@@ -3,7 +3,7 @@ function! lsp#utils#is_file_uri(uri) abort
|
||||
endfunction
|
||||
|
||||
function! lsp#utils#is_remote_uri(uri) abort
|
||||
return a:uri =~# '^\w\+::' || a:uri =~# '^\w\+://'
|
||||
return a:uri =~# '^\w\+::' || a:uri =~# '^[a-z][a-z0-9+.-]*://'
|
||||
endfunction
|
||||
|
||||
function! s:decode_uri(uri) abort
|
||||
@@ -42,7 +42,7 @@ endfunction
|
||||
|
||||
if has('win32') || has('win64')
|
||||
function! lsp#utils#path_to_uri(path) abort
|
||||
if empty(a:path)
|
||||
if empty(a:path) || lsp#utils#is_remote_uri(a:path)
|
||||
return a:path
|
||||
else
|
||||
" You must not encode the volume information on the path if
|
||||
@@ -58,7 +58,7 @@ if has('win32') || has('win64')
|
||||
endfunction
|
||||
else
|
||||
function! lsp#utils#path_to_uri(path) abort
|
||||
if empty(a:path)
|
||||
if empty(a:path) || lsp#utils#is_remote_uri(a:path)
|
||||
return a:path
|
||||
else
|
||||
return s:encode_uri(a:path, 0, 'file://')
|
||||
|
||||
@@ -46,6 +46,40 @@ Describe lsp#utils
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#path_to_uri
|
||||
It should return uri from path (Windows)
|
||||
if !has('win32')
|
||||
Skip This tests is not for UNIX
|
||||
endif
|
||||
let tests = [
|
||||
\ {'path': 'C:\path\to\the\file.txt', 'uri': 'file:///C:/path/to/the/file.txt'},
|
||||
\ {'path': 'C:\path\to\the\file+name.txt', 'uri': 'file:///C:/path/to/the/file%2Bname.txt'},
|
||||
\ {'path': 'C:\path\to\the\file name.txt', 'uri': 'file:///C:/path/to/the/file%20name.txt'},
|
||||
\ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
|
||||
\]
|
||||
for test in tests
|
||||
let uri = lsp#utils#path_to_uri(test.path)
|
||||
Assert Equals(uri, test.uri)
|
||||
endfor
|
||||
End
|
||||
|
||||
It should return uri from path (UNIX)
|
||||
if has('win32')
|
||||
Skip This tests is not for Windows
|
||||
endif
|
||||
let tests = [
|
||||
\ {'path': '/path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
|
||||
\ {'path': '/path/to/the/file+name.txt', 'uri': 'file:///path/to/the/file%2Bname.txt'},
|
||||
\ {'path': '/path/to/the/file name.txt', 'uri': 'file:///path/to/the/file%20name.txt'},
|
||||
\ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
|
||||
\]
|
||||
for test in tests
|
||||
let uri = lsp#utils#path_to_uri(test.path)
|
||||
Assert Equals(uri, test.uri)
|
||||
endfor
|
||||
End
|
||||
End
|
||||
|
||||
Describe lsp#utils#find_nearest_parent_file_directory
|
||||
It should return the root directory if it is found
|
||||
let tests = [
|
||||
|
||||
Reference in New Issue
Block a user