Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support msys2 (path format) #3787

Open
q962 opened this issue Apr 27, 2022 · 4 comments
Open

Support msys2 (path format) #3787

q962 opened this issue Apr 27, 2022 · 4 comments

Comments

@q962
Copy link

q962 commented Apr 27, 2022

Because msys simulates the linux environment, the path format used in msys is the same as the linux path format.

But there is a path conversion tool in msys2
cygpath -m /home/name/path => D:/msys64_install_path/home/name/path

just need to slightly modified

let fullpath = fnamemodify(bufname, ':p')
if has_key(environ(), 'MSYSTEM')
  " cygpath returns results containing \n
  let fullpath = system("cygpath -m " . fullpath)[0:-2]
endif
"...

'fullpath': empty(bufname) ? '' : fullpath,

About the MSYSTEM :https://www.msys2.org/docs/environments/

@q962
Copy link
Author

q962 commented Apr 27, 2022

Local validation is correct. Ability to open include files correctly

Before modification, 'd:' will be added before the original path, resulting in a wrong path

For example: D:\home\name\path

@q962
Copy link
Author

q962 commented May 16, 2022

Are there any other files besides utils that involve path?

diff --git a/autoload/coc/util.vim b/autoload/coc/util.vim
index 95f5fe1..37c4a9b 100644
--- a/autoload/coc/util.vim
+++ b/autoload/coc/util.vim
@@ -3,6 +3,12 @@ let s:root = expand('<sfile>:h:h:h')
 let s:is_win = has('win32') || has('win64')
 let s:is_vim = !has('nvim')
 let s:vim_api_version = 28
+let s:is_msys = has_key(environ(), 'MSYSTEM')
+let s:root_path = ""
+if s:is_msys
+  " remove '/\n'
+  let s:root_path = system('cygpath -m /')[0:-3]
+endif
 
 function! coc#util#api_version() abort
   return s:vim_api_version
@@ -33,10 +39,20 @@ function! coc#util#jumpTo(line, character) abort
   call coc#cursor#move_to(a:line, a:character)
 endfunction
 
+function! coc#util#path_conversion(path) abort
+  if s:is_msys
+     " remove '\n'
+      let path = system("cygpath -m " . a:path)[0:-2]
+  endif
+  " echom 'cygpath@'. path
+  return path
+endfunction
+
+
 function! coc#util#path_replace_patterns() abort
   if has('win32unix') && exists('g:coc_cygqwin_path_prefixes')
-    echohl WarningMsg 
-    echon 'g:coc_cygqwin_path_prefixes is deprecated, use g:coc_uri_prefix_replace_patterns instead' 
+    echohl WarningMsg
+    echon 'g:coc_cygqwin_path_prefixes is deprecated, use g:coc_uri_prefix_replace_patterns instead'
     echohl None
     return g:coc_cygqwin_path_prefixes
   endif
@@ -249,7 +265,7 @@ function! coc#util#get_bufoptions(bufnr) abort
         \ 'filetype': getbufvar(a:bufnr, '&filetype'),
         \ 'iskeyword': getbufvar(a:bufnr, '&iskeyword'),
         \ 'changedtick': getbufvar(a:bufnr, 'changedtick'),
-        \ 'fullpath': empty(bufname) ? '' : fnamemodify(bufname, ':p'),
+        \ 'fullpath': empty(bufname) ? '' : coc#util#path_conversion(fnamemodify(bufname, ':p')),
         \}
 endfunction
 
@@ -299,7 +315,7 @@ function! coc#util#preview_info(info, filetype, ...) abort
   wincmd p
 endfunction
 
-function! coc#util#get_config_home()
+function! s:get_config_home()
   if !empty(get(g:, 'coc_config_home', ''))
       return resolve(expand(g:coc_config_home))
   endif
@@ -322,6 +338,10 @@ function! coc#util#get_config_home()
   endif
 endfunction
 
+function! coc#util#get_config_home()
+  return coc#util#path_conversion(s:get_config_home())
+endfunction
+
 function! coc#util#get_data_home()
   if !empty(get(g:, 'coc_data_home', ''))
     let dir = resolve(expand(g:coc_data_home))
@@ -336,6 +356,7 @@ function! coc#util#get_data_home()
       endif
     endif
   endif
+  let dir = coc#util#path_conversion(dir)
   if !isdirectory(dir)
     call coc#float#create_notification(['creating data directory: '.dir], {'timeout': 2000})
     call mkdir(dir, "p", 0755)
@@ -364,7 +385,7 @@ function! coc#util#get_complete_option()
         \ 'input': empty(input) ? '' : input,
         \ 'line': line,
         \ 'filetype': &filetype,
-        \ 'filepath': expand('%:p'),
+        \ 'filepath': coc#util#path_conversion(expand('%:p')),
         \ 'bufnr': bufnr('%'),
         \ 'linenr': pos[1],
         \ 'colnr' : pos[2],
@@ -536,6 +557,8 @@ function! coc#util#getpid()
 endfunction
 
 function! coc#util#vim_info()
+  let l:runtimepath = join(map(globpath(&runtimepath, "", 0, 1), {key,path->s:root_path.path}), ',')
+
   return {
         \ 'apiversion': s:vim_api_version,
         \ 'mode': mode(),
@@ -558,9 +581,9 @@ function! coc#util#vim_info()
         \ 'colorscheme': get(g:, 'colors_name', ''),
         \ 'workspaceFolders': get(g:, 'WorkspaceFolders', v:null),
         \ 'background': &background,
-        \ 'runtimepath': join(globpath(&runtimepath, '', 0, 1), ','),
+        \ 'runtimepath': l:runtimepath,
         \ 'locationlist': get(g:,'coc_enable_locationlist', 1),
-        \ 'progpath': v:progpath,
+        \ 'progpath': coc#util#path_conversion(v:progpath),
         \ 'guicursor': &guicursor,
         \ 'tabCount': tabpagenr('$'),
         \ 'updateHighlight': has('nvim-0.5.0') || has('patch-8.1.1719') ? v:true : v:false,

@ducklin5
Copy link

ducklin5 commented Sep 3, 2022

Yes! please can we do this. I've just realized that my cygwin coc-settings.json was not taking effect because although I was running vim from cygwin, (and :CocConfig opens up ~/.vim/coc-settings.json from cygwin); the config coc currently uses is athe the windows path: C:/Users/me/.vim/coc-settings.json. Msys and Cygwin have separated a home directory from the windows directory. I believe this change should fix the issue.

@q962
Copy link
Author

q962 commented Sep 4, 2022

Of course, it's just that I don't know if I have modified all the path-related functions (all in utils.vim), which needs to be confirmed by the developer. Although I use normal :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants