diff --git a/lua/go/enum.lua b/lua/go/enum.lua new file mode 100644 index 0000000..c1fbe5a --- /dev/null +++ b/lua/go/enum.lua @@ -0,0 +1,36 @@ +local runner = require("go.runner") +local utils = require("go.utils") +local vfn = vim.fn +local M = {} + +function M.run(args) + args = args or {} + local row, col = unpack(vim.api.nvim_win_get_cursor(0)) + row, col = row - 1, col + + local line = vim.api.nvim_buf_get_lines(0, row, row + 1, true)[1] + line = line:gsub("^%s+", "") -- lstrip + line = line:gsub("%s+", " ") -- combine spaces + line = vim.split(line, " ") + utils.log(line) + local fn = vfn.expand('%:p:f') + local cmd = { "go-enum", '-f', fn } + local new_name = vfn.expand('%:p:r') .. "_enum.go" + + vim.list_extend(cmd, args) + local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd() + local opts = { + update_buffer = true, + on_exit = function() + vim.schedule(function() + -- utils.restart() + vim.cmd('e ' .. new_name) + + end) + end, + } + runner.run(cmd, opts) + return cmd, opts +end + +return M diff --git a/lua/go/gopls.lua b/lua/go/gopls.lua index 6b0b16c..f3117e8 100644 --- a/lua/go/gopls.lua +++ b/lua/go/gopls.lua @@ -191,84 +191,6 @@ local get_current_gomod = function() return mod_name end -local setups = { - capabilities = { - textDocument = { - completion = { - completionItem = { - commitCharactersSupport = true, - deprecatedSupport = true, - documentationFormat = { 'markdown', 'plaintext' }, - preselectSupport = true, - insertReplaceSupport = true, - labelDetailsSupport = true, - snippetSupport = true, - resolveSupport = { - properties = { - 'documentation', - 'details', - 'additionalTextEdits', - }, - }, - }, - contextSupport = true, - dynamicRegistration = true, - }, - }, - }, - filetypes = { 'go', 'gomod', 'gosum', 'gotmpl', 'gohtmltmpl', 'gotexttmpl' }, - message_level = vim.lsp.protocol.MessageType.Error, - cmd = { - 'gopls', -- share the gopls instance if there is one already - '-remote.debug=:0', - }, - root_dir = function(fname) - local has_lsp, lspconfig = pcall(require, 'lspconfig') - if has_lsp then - local util = lspconfig.util - return util.root_pattern('go.mod', '.git')(fname) or util.path.dirname(fname) - end - end, - flags = { allow_incremental_sync = true, debounce_text_changes = 500 }, - settings = { - gopls = { - -- more settings: https://github.com/golang/tools/blob/master/gopls/doc/settings.md - -- not supported - analyses = { - unreachable = true, - nilness = true, - unusedparams = true, - useany = true, - unusedwrite = true, - ST1003 = true, - undeclaredname = true, - fillreturns = true, - nonewvars = true, - fieldalignment = false, - shadow = true, - }, - codelenses = { - generate = true, -- show the `go generate` lens. - gc_details = true, -- Show a code lens toggling the display of gc's choices. - test = true, - tidy = true, - vendor = true, - regenerate_cgo = true, - upgrade_dependency = true, - }, - usePlaceholders = true, - completeUnimported = true, - staticcheck = true, - matcher = 'Fuzzy', - diagnosticsDelay = '500ms', - symbolMatcher = 'fuzzy', - ['local'] = get_current_gomod(), - gofumpt = _GO_NVIM_CFG.lsp_gofumpt or false, -- true|false, -- turn on for new repos, gofmpt is good but also create code turmoils - buildFlags = { '-tags', 'integration' }, - }, - }, -} - local function get_build_flags() local get_build_tags = require('go.gotest').get_build_tags local tags = get_build_tags() @@ -281,6 +203,83 @@ local function get_build_flags() end M.setups = function() + local setups = { + capabilities = { + textDocument = { + completion = { + completionItem = { + commitCharactersSupport = true, + deprecatedSupport = true, + documentationFormat = { 'markdown', 'plaintext' }, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + snippetSupport = true, + resolveSupport = { + properties = { + 'documentation', + 'details', + 'additionalTextEdits', + }, + }, + }, + contextSupport = true, + dynamicRegistration = true, + }, + }, + }, + filetypes = { 'go', 'gomod', 'gosum', 'gotmpl', 'gohtmltmpl', 'gotexttmpl' }, + message_level = vim.lsp.protocol.MessageType.Error, + cmd = { + 'gopls', -- share the gopls instance if there is one already + '-remote.debug=:0', + }, + root_dir = function(fname) + local has_lsp, lspconfig = pcall(require, 'lspconfig') + if has_lsp then + local util = lspconfig.util + return util.root_pattern('go.mod', '.git')(fname) or util.path.dirname(fname) + end + end, + flags = { allow_incremental_sync = true, debounce_text_changes = 500 }, + settings = { + gopls = { + -- more settings: https://github.com/golang/tools/blob/master/gopls/doc/settings.md + -- not supported + analyses = { + unreachable = true, + nilness = true, + unusedparams = true, + useany = true, + unusedwrite = true, + ST1003 = true, + undeclaredname = true, + fillreturns = true, + nonewvars = true, + fieldalignment = false, + shadow = true, + }, + codelenses = { + generate = true, -- show the `go generate` lens. + gc_details = true, -- Show a code lens toggling the display of gc's choices. + test = true, + tidy = true, + vendor = true, + regenerate_cgo = true, + upgrade_dependency = true, + }, + usePlaceholders = true, + completeUnimported = true, + staticcheck = true, + matcher = 'Fuzzy', + diagnosticsDelay = '500ms', + symbolMatcher = 'fuzzy', + ['local'] = get_current_gomod(), + gofumpt = _GO_NVIM_CFG.lsp_gofumpt or false, -- true|false, -- turn on for new repos, gofmpt is good but also create code turmoils + buildFlags = { '-tags', 'integration' }, + }, + }, + } local v = M.version() if v == nil then return diff --git a/lua/go/gotest.lua b/lua/go/gotest.lua index 9db9637..8857915 100644 --- a/lua/go/gotest.lua +++ b/lua/go/gotest.lua @@ -147,6 +147,7 @@ local function run_test(path, args) if next(reminder) then path = reminder[1] + table.remove(reminder, 1) end local test_runner = _GO_NVIM_CFG.go if _GO_NVIM_CFG.test_runner ~= test_runner then @@ -183,8 +184,8 @@ local function run_test(path, args) table.insert(cmd, '-v') end if not empty(reminder) then - log('****', reminder) cmd = vim.list_extend(cmd, reminder) + log('****', reminder, cmd) end if compile == true then