Skip to content

Commit 296fb98

Browse files
Agorgianitis Loukasmattn
andauthored
Transform cygwin/msys2 paths to windows before encoding them to URIs (#1144)
* Transform cygwin paths to windows before encoding them to uris * Transform windows paths to cygwin after decoding them from uris Co-authored-by: mattn <[email protected]>
1 parent 89d2889 commit 296fb98

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

autoload/lsp/utils.vim

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function! s:encode_uri(path, start_pos_encode, default_prefix) abort
7272
endfunction
7373

7474
let s:path_to_uri_cache = {}
75-
if has('win32') || has('win64')
75+
if has('win32') || has('win64') || has('win32unix')
7676
function! lsp#utils#path_to_uri(path) abort
7777
if has_key(s:path_to_uri_cache, a:path)
7878
return s:path_to_uri_cache[a:path]
@@ -82,16 +82,22 @@ if has('win32') || has('win64')
8282
let s:path_to_uri_cache[a:path] = a:path
8383
return s:path_to_uri_cache[a:path]
8484
else
85+
" Transform cygwin paths to windows paths
86+
let l:path = a:path
87+
if has('win32unix')
88+
let l:path = substitute(a:path, '\c^/\([a-z]\)/', '\U\1:/', '')
89+
endif
90+
8591
" You must not encode the volume information on the path if
8692
" present
87-
let l:end_pos_volume = matchstrpos(a:path, '\c[A-Z]:')[2]
93+
let l:end_pos_volume = matchstrpos(l:path, '\c[A-Z]:')[2]
8894

8995
if l:end_pos_volume == -1
9096
let l:end_pos_volume = 0
9197
endif
9298

93-
let s:path_to_uri_cache[a:path] = s:encode_uri(substitute(a:path, '\', '/', 'g'), l:end_pos_volume, 'file:///')
94-
return s:path_to_uri_cache[a:path]
99+
let s:path_to_uri_cache[l:path] = s:encode_uri(substitute(l:path, '\', '/', 'g'), l:end_pos_volume, 'file:///')
100+
return s:path_to_uri_cache[l:path]
95101
endif
96102
endfunction
97103
else
@@ -111,13 +117,21 @@ else
111117
endif
112118

113119
let s:uri_to_path_cache = {}
114-
if has('win32') || has('win64')
120+
if has('win32') || has('win64') || has('win32unix')
115121
function! lsp#utils#uri_to_path(uri) abort
116122
if has_key(s:uri_to_path_cache, a:uri)
117123
return s:uri_to_path_cache[a:uri]
118124
endif
119125

120-
let s:uri_to_path_cache[a:uri] = substitute(s:decode_uri(a:uri[len('file:///'):]), '/', '\\', 'g')
126+
let l:path = substitute(s:decode_uri(a:uri[len('file:///'):]), '/', '\\', 'g')
127+
128+
" Transform windows paths to cygwin paths
129+
if has('win32unix')
130+
let l:path = substitute(l:path, '\c^\([A-Z]\):\\', '/\l\1/', '')
131+
let l:path = substitute(l:path, '\\', '/', 'g')
132+
endif
133+
134+
let s:uri_to_path_cache[a:uri] = l:path
121135
return s:uri_to_path_cache[a:uri]
122136
endfunction
123137
else

0 commit comments

Comments
 (0)