add initial golang stuff

This commit is contained in:
Gered 2024-10-20 20:55:35 -04:00
parent 6eb11e5566
commit f0d56bebd2
12 changed files with 164 additions and 1 deletions

2
bashrc.d/go.bashrc Executable file
View file

@ -0,0 +1,2 @@
export GOPATH=${HOME}/go
export PATH=${PATH}:${GOPATH}/bin

View file

@ -0,0 +1,17 @@
local function map(mode, lhs, rhs, desc)
local opts = { silent = true, noremap = true, desc = desc or '' }
vim.keymap.set(mode, lhs, rhs, opts)
end
map('n', '<leader>ga', '<Cmd>GoCodeAction<CR>', 'Go: Code [A]ction')
map('n', '<leader>gA', '<Cmd>GoCodeLenAct<CR>', 'Go: Code Lens [A]ction')
map('n', '<leader>gb', '<Cmd>GoBuild<CR>', 'Go: [B]uild')
map('n', '<leader>gr', '<Cmd>GoRun<CR>', 'Go: [R]un')
map('n', '<leader>gd', '<Cmd>GoDebug<CR>', 'Go: [D]ebug')
map('n', '<leader>gt', '<Cmd>GoTest<CR>', 'Go: [T]est')
map('n', '<leader>gf', '<Cmd>GoFmt<CR>', 'Go: [F]ormat')
map('n', '<leader>gi', '<Cmd>GoImports<CR>', 'Go: [I]mports')
map('n', '<leader>gg', '<Cmd>GoGet<CR>', 'Go: [G]et')
map('n', '<leader>gN', '<Cmd>GoInstallBinaries<CR>', 'Go: I[N]stall Dependent Tools')
map('n', '<leader>gU', '<Cmd>GoUpdateBinaries<CR>', 'Go: [U]pdate Dependent Tools')

View file

@ -0,0 +1 @@
vim.cmd.runtime { 'after/ftplugin/go.lua', bang = true }

View file

@ -5,7 +5,8 @@ sudo emerge -av --noreplace \
x11-misc/xclip \
sys-apps/ripgrep \
net-libs/nodejs \
sys-devel/clang
sys-devel/clang \
dev-lang/go
# don't want to be root for this, rustup is typically installed by non-root users and won't be
# present for root at all.

View file

@ -11,6 +11,8 @@
"dashboard-nvim": { "branch": "master", "commit": "fabf5feec96185817c732d47d363f34034212685" },
"fidget.nvim": { "branch": "main", "commit": "d855eed8a06531a7e8fd0684889b2943f373c469" },
"gitsigns.nvim": { "branch": "main", "commit": "863903631e676b33e8be2acb17512fdc1b80b4fb" },
"go.nvim": { "branch": "master", "commit": "51676b430fc9288073769319ba0ccb2a3bcd79c9" },
"guihua.lua": { "branch": "master", "commit": "225db770e36aae6a1e9e3a65578095c8eb4038d3" },
"indent-blankline.nvim": { "branch": "master", "commit": "e7a4442e055ec953311e77791546238d1eaae507" },
"lazy.nvim": { "branch": "main", "commit": "1159bdccd8910a0fd0914b24d6c3d186689023d9" },
"lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" },
@ -29,6 +31,7 @@
"nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" },
"nvim-dap": { "branch": "master", "commit": "7ff6936010b7222fea2caea0f67ed77f1b7c60dd" },
"nvim-dap-ui": { "branch": "master", "commit": "ffa89839f97bad360e78428d5c740fdad9a0ff02" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "52638640ae309cacdaff785fdbb854437bd1ee5c" },
"nvim-lspconfig": { "branch": "master", "commit": "04680101ff79e99b4e33a4386ec27cbd0d360c75" },
"nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
"nvim-notify": { "branch": "master", "commit": "fbef5d32be8466dd76544a257d3f3dce20082a07" },

View file

@ -20,6 +20,12 @@ function M.in_git_project()
return vim.fn.finddir('.git', '.;') ~= ''
end
-- TODO: is there some better way to do this?
-- TODO: also add `in_golang_project()` function to detect based on presence of go.mod file?
function M.is_golang_filetype()
return M.contains({ 'go', 'gomod', 'gosum', 'gotmpl' }, vim.bo.filetype)
end
function M.contains(tbl, v)
for i, value in ipairs(tbl) do
if value == v then

26
nvim/lua/plugins/go.lua Normal file
View file

@ -0,0 +1,26 @@
return {
{
'ray-x/go.nvim',
dependencies = {
'ray-x/guihua.lua',
'neovim/nvim-lspconfig',
'nvim-treesitter/nvim-treesitter',
},
config = function()
require('go').setup {
dap_debug_keymap = false,
}
vim.api.nvim_create_autocmd('BufWritePre', {
group = vim.api.nvim_create_augroup('gered-gofmt-goimports', {}),
pattern = '*.go',
callback = function()
require('go.format').goimports()
end,
})
end,
event = { 'CmdlineEnter' },
ft = { 'go', 'gomod' },
build = ':lua require("go.install").update_all_sync()',
},
}

View file

@ -21,6 +21,7 @@ return {
'css-lsp',
'docker-compose-language-service',
'dockerfile-language-server',
'gopls',
'html-lsp',
'jdtls',
'json-lsp',

View file

@ -73,6 +73,15 @@ function get_default_menu()
})
end
if helper.is_golang_filetype() then
table.insert(menu, 1, {
name = '󰟓 Golang Actions',
hl = 'ExBlue',
items = get_golang_menu(),
rtxt = '<leader>g',
})
end
if helper.in_git_project() then
table.insert(menu, 1, {
name = ' Git Actions',
@ -398,6 +407,95 @@ function get_cmake_menu()
}
end
function get_golang_menu()
return {
{
name = 'Code Actions',
cmd = function()
vim.cmd 'GoCodeAction'
end,
rtxt = '<leader>ga',
},
{
name = 'Code Lens Actions',
cmd = function()
vim.cmd 'GoCodeLenAct'
end,
rtxt = '<leader>gA',
},
{ name = 'separator' },
{
name = 'Build',
hl = 'ExRed',
cmd = function()
vim.cmd 'GoBuild'
end,
rtxt = '<leader>gb',
},
{
name = ' Run',
hl = 'ExGreen',
cmd = function()
vim.cmd 'GoRun'
end,
rtxt = '<leader>gr',
},
{
name = '󰃤 Debug',
hl = 'ExBlue',
cmd = function()
vim.cmd 'GoDebug'
end,
rtxt = '<leader>gd',
},
{
name = '󰸞 Test',
hl = 'ExRed',
cmd = function()
vim.cmd 'GoTest'
end,
rtxt = '<leader>gt',
},
{ name = 'separator' },
{
name = 'Format',
cmd = function()
vim.cmd 'GoFmt'
end,
rtxt = '<leader>gf',
},
{
name = 'Imports',
cmd = function()
vim.cmd 'GoImports'
end,
rtxt = '<leader>gi',
},
{
name = 'Get',
cmd = function()
vim.cmd 'GoGet'
end,
rtxt = '<leader>gg',
},
{ name = 'separator' },
{
name = 'Install Dependent Tools',
cmd = function()
vim.cmd 'GoInstallBinaries'
end,
rtxt = '<leader>gN',
},
{
name = 'Update Dependent Tools',
cmd = function()
vim.cmd = 'GoUpdateBinaries'
end,
rtxt = '<leader>gU',
},
}
end
function get_git_menu()
local gitsigns = require 'gitsigns'
return {

View file

@ -14,6 +14,9 @@ return {
'williamboman/mason.nvim',
'jay-babu/mason-nvim-dap.nvim',
-- mainly added for go.nvim
'theHamsta/nvim-dap-virtual-text',
-- Add your own debuggers here
--'leoluz/nvim-dap-go',
},

View file

@ -13,6 +13,10 @@ return {
'csv',
'diff',
'dockerfile',
'go',
'gomod',
'gosum',
'gotmpl',
'html',
'ini',
'java',

View file

@ -49,6 +49,7 @@ return {
{ '<leader>b', group = '[B]uffer' },
{ '<leader>r', group = '[R]ust' },
{ '<leader>c', group = '[C]Make' },
{ '<leader>g', group = '[G]o', icon = { icon = '󰟓' } },
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
},
},