]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Simplify cygwin path conversions
authorPeter Jankuliak <p.jankuliak@gmail.com>
Thu, 11 May 2023 19:52:15 +0000 (20:52 +0100)
committerPeter Jankuliak <p.jankuliak@gmail.com>
Thu, 11 May 2023 19:52:15 +0000 (20:52 +0100)
autoload/lsp/util.vim

index bb783d33b60179a45155918efe2a7264770fc4ab..f9add18ded704c62edb0603225eb77d2abf826ec 100644 (file)
@@ -112,8 +112,10 @@ export def LspFileToUri(fname: string): string
   var uri: string = fname->fnamemodify(':p')
 
   if has("win32unix")
-    # We're in Cygwin
-    uri = CygwinToWindowsPath(uri)
+    # We're in Cygwin, we need to convert POSIX style paths to Windows style.
+    # `cygpath -m` converts paths of the form "/cygdrive/c/foo/bar" to "C:/foo/bar", and
+    # paths of the form "/home/pete/foo" to "C:/cygwin64/home/pete/foo".
+    uri = system($'cygpath -m {uri}')->substitute('^\(\p*\).*$', '\=submatch(1)', "")
   endif
 
   var on_windows: bool = false
@@ -138,31 +140,6 @@ export def LspFileToUri(fname: string): string
   return uri
 enddef
 
-# Convert POSIX paths as used in Cygwin to native Windows paths
-def CygwinToWindowsPath(path: string): string
-  if path =~? '^\/cygdrive\/'
-    # Convert paths of the form "/cygdrive/c/foo/bar" to "c:/foo/bar"
-
-    return path->substitute('^\/cygdrive\/\(\a\)\/', '\=submatch(1) .. ":/"', "")
-  elseif path =~? '^\/'
-    # Convert paths of the form "/home/pete/foo" to "C:/cygwin64/home/pete/foo"
-
-    if g:cygwinroot->len() == 0
-      # https://stackoverflow.com/a/7449029/273348
-      var query: string = "reg query HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Cygwin\\\\setup /v rootdir | grep rootdir"
-
-      g:cygwinroot = system(query)->substitute(
-            \ '^\s*\S\+\s\+\S\+\s\+\(\p\+\).*$',
-            \ '\=submatch(1)',
-            \ "")
-    endif
-
-    return $'{g:cygwinroot}{path}'
-  else
-    return path
-  endif
-enddef
-
 # Convert a Vim buffer number to an LSP URI (file://<absolute_path>)
 export def LspBufnrToUri(bnr: number): string
   return LspFileToUri(bnr->bufname())