allow ui.input/ui.select to be configurable issue #444

pull/450/head
ray-x 1 month ago
parent 8b28f98877
commit 4d3fa34df0

@ -788,6 +788,9 @@ require('go').setup({
signs = true,
update_in_insert = false,
},
-- if you need to setup your ui for input and select, you can do it here
-- go_input = require('guihua.input').input -- set to vim.ui.input to disable guihua input
-- go_select = require('guihua.select').select -- vim.ui.select to disable guihua select
lsp_document_formatting = true,
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)

@ -50,6 +50,18 @@ _GO_NVIM_CFG = {
update_in_insert = false,
signs = true,
},
go_input = function()
if require('go.utils').load_plugin('guihua.lua', 'guihua.gui') then
return require('guihua.input').input
end
return vim.ui.input
end,
go_select = function()
if require('go.utils').load_plugin('guihua.lua', 'guihua.gui') then
return require('guihua.gui').select
end
return vim.ui.select
end,
-- deprecated setups
-- lsp_diag_hdlr = true, -- hook lsp diag handler
-- lsp_diag_underline = true,
@ -58,7 +70,7 @@ _GO_NVIM_CFG = {
-- lsp_diag_signs = true,
lsp_inlay_hints = {
enable = true,
style = 'inlay', -- 'default: inlay', 'eol': show at end of line, 'inlay': show in the middle of the line
style = 'inlay', -- 'default: inlay', 'eol': show at end of line, 'inlay': show in the middle of the line
-- Note: following setup only for for style == 'eol'
-- Only show inlay hints for the current line

@ -14,11 +14,8 @@ function M.run_range_code_action(t)
local original_select = vim.ui.select
local original_input = vim.ui.input
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
if guihua then
vim.ui.select = require('guihua.gui').select
vim.ui.input = require('guihua.input').input
end
vim.ui.select = _GO_NVIM_CFG.go_select()
vim.ui.input = _GO_NVIM_CFG.go_input()
vim.lsp.buf.code_action({
context = context,
range = t.range,
@ -30,14 +27,10 @@ function M.run_range_code_action(t)
end
function M.run_code_action()
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
local original_select = vim.ui.select
local original_input = vim.ui.input
if guihua then
vim.ui.select = require('guihua.gui').select
vim.ui.input = require('guihua.input').input
end
vim.ui.select = _GO_NVIM_CFG.go_select()
vim.ui.input = _GO_NVIM_CFG.go_input()
log('codeaction')
if vim.api.nvim_get_mode().mode ~= 'v' then

@ -24,12 +24,9 @@ function M.setup()
end
function M.run_action()
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
local original_select = vim.ui.select
if guihua then
vim.ui.select = require('guihua.gui').select
end
vim.ui.select = _GO_NVIM_CFG.go_select()
codelens.run()
vim.defer_fn(function()
@ -50,20 +47,12 @@ function M.toggle()
end
function M.refresh()
local gopls = require('go.lsp').client()
log('refresh codelens')
if not gopls then -- and gopls.server_capabilities.codeLensProvider then
return
end
if _GO_NVIM_CFG.lsp_codelens == true then
local found = false
if not found then
for _, lsp in pairs(vim.lsp.get_active_clients()) do
if lsp.name == 'gopls' then
found = true
break
end
end
end
if not found then
return
end
log('refresh codelens')
vim.lsp.codelens.refresh()
else
log('refresh codelens')

@ -314,12 +314,8 @@ M.run = function(...)
return require('dap').toggle_breakpoint()
end
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
local original_select = vim.ui.select
if guihua then
vim.ui.select = require('guihua.gui').select
end
vim.ui.select = _GO_NVIM_CFG.go_select()
-- testopts = {"test", "nearest", "file", "stop", "restart"}
log('plugin loaded', mode, optarg)

@ -9,10 +9,7 @@ function M.run(args)
local input = vim.ui.input
local guihua = utils.load_plugin("guihua.lua", "guihua.input")
if guihua then
input = guihua.input
end
vim.ui.input = _GO_NVIM_CFG.go_input()
local cmd = { "gomvp" }
local old_mod = require('go.ts.go').get_module_at_pos()
if old_mod == nil then

@ -719,12 +719,9 @@ end
-- GUI to select test?
M.select_tests = function()
local guihua = utils.load_plugin('guihua.lua', 'guihua.gui')
local original_select = vim.ui.select
if guihua then
vim.ui.select = require('guihua.gui').select
end
vim.ui.select = _GO_NVIM_CFG.go_select()
vim.defer_fn(function()
vim.ui.select = original_select

@ -305,7 +305,6 @@ function M.disable_inlay_hints(update, bufnr)
end
end
local found = false
-- Sends the request to gopls to get the inlay hints and handle them
function M.set_inlay_hints()
if vim.wo.diff then
@ -313,16 +312,7 @@ function M.set_inlay_hints()
end
local bufnr = vim.api.nvim_get_current_buf()
-- check if lsp is ready
if not found then
for _, lsp in pairs(vim.lsp.get_active_clients({ bufnr = bufnr })) do
if lsp.name == 'gopls' then
found = true
break
end
end
end
if not found then
log('gopls not found')
if not require('go.lsp').client() then
return
end
local fname = fn.expand('%:p')

@ -179,12 +179,11 @@ end
local M = {}
function M.client()
local clients = vim.lsp.get_active_clients()
for _, cl in pairs(clients) do
if cl.name == 'gopls' then
return cl
end
end
local clients = vim.lsp.get_active_clients({
bufnr = vim.api.nvim_get_current_buf(),
name = 'gopls',
}) or {}
return clients[1]
end
function M.config()
@ -266,16 +265,7 @@ M.codeaction = function(gopls_cmd, only, hdlr)
params.context = { only = { only } }
end
local bufnr = vim.api.nvim_get_current_buf()
local clients = vim.lsp.get_active_clients()
local gopls
-- find gopls client
for cid, c in pairs(clients) do
if c.name == 'gopls' then
log('gopls found', cid)
gopls = c
break
end
end
local gopls = M.client()
if gopls == nil then
log('gopls not found')
return hdlr()
@ -530,14 +520,15 @@ function M.document_symbols(opts)
params.context = { includeDeclaration = true }
params.query = opts.prompt or ''
local symbols
vim.lsp.for_each_buffer_client(bufnr, function(client, _, _bufnr)
if client.name == 'gopls' then
symbols =
client.request_sync('textDocument/documentSymbol', params, opts.timeout or 1000, _bufnr)
return symbols
end
end)
return symbols
local c = M.client()
if c ~= nil then
return c.request_sync(
'textDocument/documentSymbol',
params,
opts.timeout or 1000,
vim.api.nvim_get_current_buf()
)
end
end
local change_type = {

@ -1,42 +1,37 @@
local utils = require("go.utils")
local utils = require('go.utils')
local gorename = "gorename"
local gorename = 'gorename'
local vfn = vim.fn
local lsprename = function()
local guihua = utils.load_plugin("guihua.lua", "guihua.floating")
local input = vim.ui.input
if guihua then
vim.ui.input = require('guihua.input').input
end
vim.ui.input = _GO_NVIM_CFG.go_input()
vim.lsp.buf.rename()
return vim.defer_fn(function()
vim.ui.input = input
end, 1000)
end
local run = function(to_identifier, ...)
require("go.install").install(gorename)
local fname = vfn.expand("%:p") -- %:p:h ? %:p
require('go.install').install(gorename)
local fname = vfn.expand('%:p') -- %:p:h ? %:p
local old_identifier = vfn.expand("<cword>")
local old_identifier = vfn.expand('<cword>')
local prompt = vfn.printf("GoRename '%s' to (may take a while) :", old_identifier)
to_identifier = to_identifier or vfn.input(prompt, old_identifier)
local byte_offset = vfn.wordcount().cursor_bytes
local clients = vim.lsp.get_active_clients() or {}
if #clients > 0 then
local client = require('go.lsp').client()
if client then
-- TODO check gopls?
return lsprename()
end
local offset = string.format("%s:#%i", fname, byte_offset)
local offset = string.format('%s:#%i', fname, byte_offset)
local setup = { gorename, "-offset", offset, "-to", to_identifier }
local setup = { gorename, '-offset', offset, '-to', to_identifier }
vfn.jobstart(setup, {
on_stdout = function(_, data, _)
@ -46,10 +41,15 @@ local run = function(to_identifier, ...)
end
-- local result = vfn.json_decode(data)
local result = vim.json.decode(data)
if result.errors ~= nil or result.lines == nil or result["start"] == nil or result["start"] == 0 then
vim.notify("failed to rename" .. vim.inspect(result), vim.log.levels.ERROR)
if
result.errors ~= nil
or result.lines == nil
or result['start'] == nil
or result['start'] == 0
then
vim.notify('failed to rename' .. vim.inspect(result), vim.log.levels.ERROR)
end
vim.notify("renamed to " .. to_identifier, vim.log.levels.DEBUG)
vim.notify('renamed to ' .. to_identifier, vim.log.levels.DEBUG)
end,
})
end

@ -618,12 +618,10 @@ function util.read_file(path)
end
function util.restart(cmd_args)
local old_lsp_clients = vim.lsp.get_active_clients()
local old_lsp_client = require('go.lsp').client()
local configs = require('lspconfig.configs')
for _, client in pairs(old_lsp_clients) do
if client.name == 'gopls' then
vim.lsp.stop_client(client.id)
end
if old_lsp_client then
vim.lsp.stop_client(old_lsp_client.id)
end
if configs['gopls'] ~= nil then

Loading…
Cancel
Save