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 1 commit
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
Prev Previous commit
Next Next commit
update
  • Loading branch information
rwxguo committed Dec 25, 2023
commit adc17518ae5838f7a1734d12d1b17903f2168eba
11 changes: 7 additions & 4 deletions autoload/go/def.vim
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +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 system('uname') =~ 'MINGW' || system('uname') =~ 'CYGWIN'
" remove comma from path before split. e.g. /c:/path to /c/path
if l:out[2:3] is# ':/'
let l:out = l:out[0:1] . l:out[3:]
elseif has('win32unix')
" remove comma in cygwin path e.g. '/c:/path'
if l:out[0:8] != '/cygdrive'
if l:out[2:3] is# ':/'
let l:out = l:out[0:1] . l:out[3:]
endif
endif
let parts = split(out, ':')
else
Expand Down
13 changes: 9 additions & 4 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,17 @@ function! s:definitionHandler(next, msg) abort dict
let l:msg = a:msg[0]

let l:msguri = go#path#FromURI(l:msg.uri)
" remove the comma in cygwin unix-like windwos path
" e.g. '/c:/path' to '/c/path'
if has('win32unix') && (system('uname') =~ 'MINGW' || system('uname') =~ 'CYGWIN')

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)
Expand All @@ -631,7 +636,7 @@ function! s:definitionHandler(next, msg) abort dict
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