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

lsp: add :GoLSPDebugBrowser #2436

Merged
merged 1 commit into from
Aug 1, 2019
Merged
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
24 changes: 21 additions & 3 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ function! s:newlsp() abort
endfunction

function! l:lsp.err_cb(ch, msg) dict abort
if a:msg =~ '^\tPort = \d\+$' && !get(self, 'debugport', 0)
let self.debugport = substitute(a:msg, '^\tPort = \(\d\+\).*$', '\1', '')
endif

call s:debug('stderr', a:msg)
endfunction

Expand All @@ -337,9 +341,12 @@ function! s:newlsp() abort
return
endif

" TODO(bc): output a message indicating which directory lsp is going to
" start in.
let l:lsp.job = go#job#Start([l:bin_path], l:opts)
let l:cmd = [l:bin_path]
if go#util#HasDebug('lsp')
let l:cmd = extend(l:cmd, ['-debug', 'localhost:0'])
endif

let l:lsp.job = go#job#Start(l:cmd, l:opts)

return l:lsp
endfunction
Expand Down Expand Up @@ -759,6 +766,17 @@ function! go#lsp#ResetWorkspaceDirectories() abort
return 0
endfunction

function! go#lsp#DebugBrowser() abort
let l:lsp = s:lspfactory.get()
let l:port = get(l:lsp, 'debugport', 0)
if !l:port
call go#util#EchoError("gopls was not started with debugging enabled. See :help g:go_debug.")
return
endif

call go#util#OpenBrowser(printf('http://localhost:%d', l:port))
endfunction

function! s:debug(event, data) abort
if !go#util#HasDebug('lsp')
return
Expand Down
17 changes: 12 additions & 5 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,16 @@ CTRL-t
tries to preserve cursor position and avoids replacing the buffer with
stderr output.

*:GoAddWorkspace*
*:GoAddWorkspace*
:GoAddWorkspace [dir] ...

Add directories to the `gopls` workspace.

*:GoLSPDebugBrowser*
:GoLSPDebugBrowser

Open a browser to see gopls debugging information.

==============================================================================
MAPPINGS *go-mappings*

Expand Down Expand Up @@ -1241,9 +1246,9 @@ set to 10 seconds . >
<
*'g:go_play_browser_command'*

Browser to use for |:GoPlay| or |:GoDocBrowser|. The url must be added with
`%URL%`, and it's advisable to include `&` to make sure the shell returns. For
example:
Browser to use for |:GoPlay|, |:GoDocBrowser|, and |:GoLSPDebugBrowser|. The
url must be added with `%URL%`, and it's advisable to include `&` to make sure
the shell returns. For example:
>
let g:go_play_browser_command = 'firefox-developer %URL% &'
<
Expand Down Expand Up @@ -1817,7 +1822,9 @@ Currently accepted values:
debugger-commands Echo communication between vim-go and `dlv`; requests and
responses are recorded in `g:go_debug_commands`.
lsp Echo communication between vim-go and `gopls`. All
communication is shown in a dedicated window.
communication is shown in a dedicated window. When
enabled before gopls is started, `:GoLSPDebugBrowser` can
be used to open a browser window to help debug gopls.
>
let g:go_debug = []
<
Expand Down
1 change: 1 addition & 0 deletions ftplugin/go/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ command! -nargs=0 GoIfErr call go#iferr#Generate()

" -- lsp
command! -nargs=+ -complete=dir GoAddWorkspace call go#lsp#AddWorkspaceDirectory(<f-args>)
command! -nargs=0 GoLSPDebugBrowser call go#lsp#DebugBrowser()

" -- term
command! GoToggleTermCloseOnExit call go#term#ToggleCloseOnExit()
Expand Down