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

mingw: Resolve path issue, make gopls work on CYGWIN/MSYS2/GitBash (:GoDoc, :GoInfo and :GoDef) #3612

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autoload/go/def.vim
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ function! go#def#jump_to_declaration(out, mode, bin_name) abort

" strip line ending
let out = split(final_out, go#util#LineEnding())[0]

if go#util#IsWin()
let parts = split(out, '\(^[a-zA-Z]\)\@<!:')
elseif has('win32unix')
" remove comma in cygwin path e.g. '/c:/path'
if l:out[0:8] != '/cygdrive' && l:out[2:3] is# ':/'
let l:out = l:out[0:1] . l:out[3:]
endif
let parts = split(out, ':')
else
let parts = split(out, ':')
endif
Expand Down
18 changes: 16 additions & 2 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,27 @@ function! s:definitionHandler(next, msg) abort dict
" gopls returns a []Location; just take the first one.
let l:msg = a:msg[0]

let l:line = s:lineinfile(go#path#FromURI(l:msg.uri), l:msg.range.start.line+1)
let l:msguri = go#path#FromURI(l:msg.uri)

if has('win32unix')
" remove comma in cygwin path e.g. '/c:/path'
if l:msguri[2:3] is# ':/'
let l:msguri = l:msguri[0:1] . l:msguri[3:]
endif

" add 'cygdrive' for CYGWIN rather than MSYS2/GitBash
if system('uname') =~ 'CYGWIN'
let l:msguri = '/cygdrive' . l:msguri
endif
endif

let l:line = s:lineinfile(l:msguri, l:msg.range.start.line+1)
if l:line is -1
call go#util#EchoWarning('could not find definition')
return
endif

let l:args = [[printf('%s:%d:%d: %s', go#path#FromURI(l:msg.uri), l:msg.range.start.line+1, go#lsp#lsp#PositionOf(l:line, l:msg.range.start.character), 'lsp does not supply a description')]]
let l:args = [[printf('%s:%d:%d: %s', l:msguri, l:msg.range.start.line+1, go#lsp#lsp#PositionOf(l:line, l:msg.range.start.character), 'lsp does not supply a description')]]
call call(a:next, l:args)
endfunction

Expand Down
9 changes: 9 additions & 0 deletions autoload/go/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ function! go#path#ToURI(path)
let l:absolute = 1
let l:prefix = '/' . l:path[0:1]
let l:path = l:path[2:]
elseif has('win32unix')
let l:absolute = 1
if l:path[0:8] == '/cygdrive'
let l:prefix = l:path[9:10] . ':'
let l:path = l:path[11:]
else
let l:prefix = l:path[0:1] . ':'
let l:path = l:path[2:3] is# ':/' ? l:path[3:] : l:path[2:]
endif
endif

return substitute(
Expand Down
Loading