Skip to content

Commit

Permalink
Merge branch 'fatih:master' into gopls-gitbash-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxguo authored Dec 27, 2023
2 parents e9c2dc3 + e2e7ad7 commit 22b54ff
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 69 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ IMPROVEMENTS:
[[GH-3504]](https://github.com/fatih/vim-go/pull/3504)
* Add `:GoExtract` command and related mapping.
[[GH-3506]](https://github.com/fatih/vim-go/pull/3506)
[[GH-3617]](https://github.com/fatih/vim-go/pull/3617)
* Halt the debugger after a connection is establish with `:GoDebugConnect`.
[[GH-3514]](https://github.com/fatih/vim-go/pull/3514)
[[GH-3520]](https://github.com/fatih/vim-go/pull/3520)
Expand Down Expand Up @@ -62,6 +63,12 @@ BUG FIXES:
[[GH-3603]](https://github.com/fatih/vim-go/pull/3603)
* Fix sameids highlighting when identifier immediately precedes newline.
[[GH-3606]](https://github.com/fatih/vim-go/pull/3606)
* Fix Python escape sequence in UltiSnips/go.snippets.
[[GH-3614]](https://github.com/fatih/vim-go/pull/3614)
* Do not attempt to use gopls for documentation when gopls is disabled.
[[GH-3610]](https://github.com/fatih/vim-go/pull/3610)
* Fix spelling of go#util#EchoWarning in a few calls.
[[GH-3613]](https://github.com/fatih/vim-go/pull/3613)

## v1.28 - (December 17, 2022)

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update -y --allow-insecure-repositories && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pip3 install vim-vint
RUN pip3 install vim-vint --break-system-packages

RUN useradd -ms /bin/bash -d /vim-go vim-go
USER vim-go
Expand Down
4 changes: 4 additions & 0 deletions autoload/go/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ function! go#config#Debug() abort
return get(g:, 'go_debug', [])
endfunction

function! go#config#DebugLogDelay() abort
return get(g:, 'go_debug_log_delay', 10)
endfunction

function! go#config#DebugWindows() abort
return get(g:, 'go_debug_windows', {
\ 'vars': 'leftabove 30vnew',
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ endfunction
function! go#debug#TestFunc(...) abort
let l:test = go#util#TestName()
if l:test is ''
call go#util#Warn("vim-go: [debug] no test found immediate to cursor")
call go#util#EchoWarning("vim-go: [debug] no test found immediate to cursor")
return
endif
call call('go#debug#Start', extend(['test', '.', '-test.run', printf('%s$', l:test)], a:000))
Expand Down
6 changes: 3 additions & 3 deletions autoload/go/doc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function! go#doc#OpenBrowser(...) abort
endfunction

function! s:docURL() abort
if len(a:000) == 0
if len(a:000) == 0 && go#config#GoplsEnabled()
" call go#lsp#DocLink directly instead of s:docURLFor, because s:docURLFor
" will strip any version information from the URL.
let [l:out, l:err] = go#lsp#DocLink()
Expand Down Expand Up @@ -64,7 +64,7 @@ function! go#doc#Open(newmode, mode, ...) abort
let l:package = l:words[0]
endif

if a:0 is 0 && &filetype == 'go'
if a:0 is 0 && &filetype == 'go' && go#config#GoplsEnabled()
" use gopls to get documentation for go files
let [l:out, l:err] = go#lsp#Doc()
else
Expand Down Expand Up @@ -239,7 +239,7 @@ endfunction
function! s:godocWord(...) abort
let l:words = a:000
if a:0 is 0
if &filetype isnot 'godoc'
if &filetype isnot 'godoc' && go#config#GoplsEnabled()
let [l:out, l:err] = go#lsp#DocLink()
if !(l:err || len(l:out) is 0)
" strip out any version string in the doc link path.
Expand Down
10 changes: 2 additions & 8 deletions autoload/go/extract.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
let s:cpo_save = &cpo
set cpo&vim

function! go#extract#Extract(selected) abort
function! go#extract#Extract(line1, line2) abort
if !go#config#GoplsEnabled()
call go#util#EchoError('GoExtract requires gopls, but gopls is disabled')
return
endif

" Extract requires a selection
if a:selected == -1
call go#util#EchoError('GoExtract requires a selection (range) of code')
return
endif

call go#lsp#Extract(a:selected)
call go#lsp#Extract(a:line1, a:line2)
return
endfunction

Expand Down
2 changes: 1 addition & 1 deletion autoload/go/extract_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func! Test_Extract() abort

silent! execute "normal vj$\<Esc>"

call go#extract#Extract(line('.'))
call go#extract#Extract(line("'<"), line("'>"))

let start = reltime()
while &modified == 0 && reltimefloat(reltime(start)) < 10
Expand Down
52 changes: 26 additions & 26 deletions autoload/go/fillstruct_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,32 @@ func! Test_gopls_fillstruct() abort
endtry
endfunc

func! Test_gopls_fillstruct_line() abort
let l:wd = getcwd()
try
let g:go_fillstruct_mode = 'gopls'
let l:tmp = gotest#write_file('a/a.go', [
\ 'package a',
\ 'import "net/mail"',
\ "\x1f" . 'var addr = mail.Address{}'])

call go#fillstruct#FillStruct()

let start = reltime()
while &modified == 0 && reltimefloat(reltime(start)) < 10
sleep 100m
endwhile

call gotest#assert_buffer(1, [
\ 'var addr = mail.Address{',
\ '\tName: "",',
\ '\tAddress: "",',
\ '}'])
finally
call go#util#Chdir(l:wd)
call delete(l:tmp, 'rf')
endtry
endfunc
"func! Test_gopls_fillstruct_line() abort
" let l:wd = getcwd()
" try
" let g:go_fillstruct_mode = 'gopls'
" let l:tmp = gotest#write_file('a/a.go', [
" \ 'package a',
" \ 'import "net/mail"',
" \ "\x1f" . 'var addr = mail.Address{}'])
"
" call go#fillstruct#FillStruct()
"
" let start = reltime()
" while &modified == 0 && reltimefloat(reltime(start)) < 10
" sleep 100m
" endwhile
"
" call gotest#assert_buffer(1, [
" \ 'var addr = mail.Address{',
" \ '\tName: "",',
" \ '\tAddress: "",',
" \ '}'])
" finally
" call go#util#Chdir(l:wd)
" call delete(l:tmp, 'rf')
" endtry
"endfunc

func! Test_gopls_fillstruct_two_cursor_first() abort
let l:wd = getcwd()
Expand Down
70 changes: 47 additions & 23 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ function! s:definitionHandler(next, msg) abort dict

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

Expand Down Expand Up @@ -665,7 +665,7 @@ function! s:typeDefinitionHandler(next, msg) abort dict

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

Expand Down Expand Up @@ -1351,6 +1351,22 @@ function! s:debugasync(timer) abort
return
endif

" set the timer to try again if Vim is in a state where we don't want to
" change the window.
if exists('*state')
let l:state = state('a')
else
let l:state = mode(1)
if !(l:state == 'ic' || l:state == 'Rc' || l:state == 'Rvc')
let l:state = ''
endif
endif
let l:mode = mode(1)
if len(l:state) > 0 || l:mode[0] == 'v' || l:mode[0] == 'V' || l:mode[0] == 's' || l:mode =~ 'CTRL-V'
let s:logtimer = timer_start(go#config#DebugLogDelay(), function('s:debugasync', []))
return
endif

try
let l:winid = win_getid()

Expand All @@ -1361,34 +1377,39 @@ function! s:debugasync(timer) abort
silent file `='__GOLSP_LOG__'`
setlocal buftype=nofile bufhidden=wipe nomodified nobuflisted noswapfile nowrap nonumber nocursorline
setlocal filetype=golsplog
else
call win_gotoid(l:log_winid)
call win_gotoid(l:winid)
endif

let l:logwinid = bufwinid(l:name)

try
setlocal modifiable
call setbufvar(l:name, '&modifiable', 1)
for [l:event, l:data] in s:log
call remove(s:log, 0)
if getline(1) == ''
call setline('$', printf('===== %s =====', l:event))
if getbufline(l:name, 1)[0] == ''
call setbufline(l:name, '$', printf('===== %s =====', l:event))
else
call append('$', printf('===== %s =====', l:event))
call appendbufline(l:name, '$', printf('===== %s =====', l:event))
endif
call append('$', split(l:data, "\r\n"))
call appendbufline(l:name, '$', split(l:data, "\r\n"))
endfor

" TODO(bc): how to move the window's cursor position without switching
" to the window?
call win_gotoid(l:logwinid)
normal! G
setlocal nomodifiable
finally
call win_gotoid(l:winid)
call setbufvar(l:name, '&modifiable', 0)
finally
endtry
catch
call go#util#EchoError(v:exception)
call go#util#EchoError(printf('at %s: %s', v:throwpoint, v:exception))
finally
" retry in when there's an exception. This can happen when trying to do
" retry when there's an exception. This can happen when trying to do
" completion, because the window can not be changed while completion is in
" progress.
if len(s:log) != 0
let s:logtimer = timer_start(10, function('s:debugasync', []))
let s:logtimer = timer_start(go#config#DebugLogDelay(), function('s:debugasync', []))
endif
endtry
endfunction
Expand All @@ -1398,7 +1419,7 @@ function! s:debug(event, data) abort
let s:log = add(s:log, [a:event, a:data])

if l:shouldStart
let s:logtimer = timer_start(10, function('s:debugasync', []))
let s:logtimer = timer_start(go#config#DebugLogDelay(), function('s:debugasync', []))
endif
endfunction

Expand Down Expand Up @@ -1678,7 +1699,7 @@ endfunction
" Extract executes the refactor.extract code action for the current buffer
" and configures the handler to only apply the fillstruct command for the
" current location.
function! go#lsp#Extract(selected) abort
function! go#lsp#Extract(line1, line2) abort
let l:fname = expand('%:p')
" send the current file so that TextEdits will be relative to the current
" state of the buffer.
Expand All @@ -1692,13 +1713,16 @@ function! go#lsp#Extract(selected) abort
let l:state.error = l:handler.wrapper
let l:state.handleError = function('s:handleCodeActionError', [l:fname], l:state)

if a:selected == -1
call go#util#EchoError('no range selected')
return
if a:line1 == -1
let [l:startline, l:startcol] = go#lsp#lsp#Position(line('.'), 1)
else
let [l:startline, l:startcol] = go#lsp#lsp#Position(a:line1, 1)
endif
if a:line2 == -1
let [l:endline, l:endcol] = go#lsp#lsp#Position(line('.'), col('$'))
else
let [l:endline, l:endcol] = go#lsp#lsp#Position(a:line2, col([a:line2, '$']))
endif

let [l:startline, l:startcol] = go#lsp#lsp#Position(line("'<"), col("'<"))
let [l:endline, l:endcol] = go#lsp#lsp#Position(line("'>"), col("'>"))

let l:msg = go#lsp#message#CodeActionRefactorExtract(l:fname, l:startline, l:startcol, l:endline, l:endcol)
call l:lsp.sendMessage(l:msg, l:state)
Expand Down Expand Up @@ -1880,7 +1904,7 @@ function s:applyDocumentChanges(changes)

let l:editbufnr = bufnr(l:bufname)
if l:editbufnr == -1
call go#util#EchoWarn(printf('could not apply changes to %s', l:fname))
call go#util#EchoWarning(printf('could not apply changes to %s', l:fname))
continue
endif

Expand Down
3 changes: 1 addition & 2 deletions autoload/go/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ function! go#lsp#lsp#Position(...)
let l:line = a:1
let l:col = a:2
endif
let l:content = getline(l:line)

" LSP uses 0-based lines.
return [l:line - 1, s:character(l:line, l:col-1)]
return [l:line - 1, s:character(l:line, l:col)]
endfunction

function! s:strlen(str) abort
Expand Down
4 changes: 2 additions & 2 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,9 @@ CTRL-t

Open a browser to see gopls debugging information.
*:GoExtract*
:GoExtract
:[range]GoExtract

Extract the code fragment in the selected range to a new function and
Extract the code fragment in the selected line range to a new function and
replace the fragment with call to the function.


Expand Down
2 changes: 1 addition & 1 deletion ftplugin/go/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ command! -nargs=? GoModReload call go#lsp#ModReload()
command! GoToggleTermCloseOnExit call go#term#ToggleCloseOnExit()

" -- extract
command! -range=% GoExtract call go#extract#Extract(<count>)
command! -range GoExtract call go#extract#Extract(<line1>, <line2>)

" vim: sw=2 ts=2 et
2 changes: 1 addition & 1 deletion gosnippets/UltiSnips/go.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ import re
def return_values(s):
# remove everything wrapped in parentheses
s = re.sub("\(.*?\)|\([^)]*$", "", s)
s = re.sub(r"\(.*?\)|\([^)]*$", "", s)
return len(s.split(","))
def opening_par(snip, pos):
Expand Down

0 comments on commit 22b54ff

Please sign in to comment.