Skip to content

Commit

Permalink
allow godoc focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Nov 11, 2021
1 parent 0dc7b57 commit 165714c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lua/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _GO_NVIM_CFG = {
dap_debug_gui = true,
dap_vt = true, -- false, true and 'all frames'
gopls_cmd = nil, --- you can provide gopls path and cmd if it not in PATH, e.g. cmd = { "/home/ray/.local/nvim/data/lspinstall/go/gopls" }
build_tags = "", --- you can provide extra build tags for tests or debugger
build_tags = "" --- you can provide extra build tags for tests or debugger
}

local dap_config = function()
Expand Down Expand Up @@ -71,8 +71,11 @@ function go.setup(cfg)
-- vim.cmd(
-- [[command! -nargs=* GoTest :setl makeprg=go\ test\ -v\ ./...| lua require'go.asyncmake'.make(<f-args>)]])

local sep = require('go.utils').sep()
local cmd = [[command! -nargs=* GoTest :setl makeprg=go\ test\ -v\ .]] .. sep
.. [[...| lua require'go.runner'.make(<f-args>]]
-- example to running test in split buffer
vim.cmd([[command! -nargs=* GoTest :setl makeprg=go\ test\ -v\ ./...| lua require'go.runner'.make(<f-args>)]])
vim.cmd(cmd)

vim.cmd([[command! -nargs=* GoCoverage lua require'go.coverage'.run(<f-args>)]])
-- vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :GoMake]])
Expand Down
5 changes: 4 additions & 1 deletion lua/go/godoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ local run = function(func, ...)
if not data then
return
end
vim.lsp.util.open_floating_preview(data, 'go', {border = 'single'})

local close_events = {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre"}
local config = {close_events = close_events, focusable = true, border = 'single'}
vim.lsp.util.open_floating_preview(data, 'go', config)
end
})
end
Expand Down
48 changes: 48 additions & 0 deletions lua/go/gopls.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local utils = require 'go.utils'
local log = utils.log

local M = {}
-- https://go.googlesource.com/tools/+/refs/heads/master/gopls/doc/commands.md
-- "executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.workspace_metadata"]}

local gopls_cmds = {
"gopls.add_dependency", "gopls.add_import", "gopls.apply_fix", "gopls.check_upgrades",
"gopls.gc_details", "gopls.generate", "gopls.generate_gopls_mod", "gopls.go_get_package",
"gopls.list_known_packages", "gopls.regenerate_cgo", "gopls.remove_dependency", "gopls.run_tests",
"gopls.start_debugging", "gopls.test", "gopls.tidy", "gopls.toggle_gc_details",
"gopls.update_go_sum", "gopls.upgrade_dependency", "gopls.vendor", "gopls.workspace_metadata"
}

local function check_for_error(msg)
if msg ~= nil and type(msg[1]) == 'table' then
for k, v in pairs(msg[1]) do
if k == 'error' then
log.error('LSP', v.message)
break
end
end
end
end

for _, value in ipairs(gopls_cmds) do
local fname = string.sub(value, #'gopls.' + 1)
M[fname] = function(arg)
log(fname)
local b = vim.api.nvim_get_current_buf()
local uri = vim.uri_from_bufnr(b)
local arguments = {{URI = uri, URIs = {uri}}}
arguments = vim.tbl_extend('keep', arguments, arg or {})

local resp = vim.lsp.buf_request_sync(b, 'workspace/executeCommand', {
command = value,
arguments = arguments
})
check_for_error(resp)
log(resp)
return resp
end
end

-- check_for_upgrades({Modules = {'package'}})

return M

0 comments on commit 165714c

Please sign in to comment.