feat(nvim): Add golang support

This commit is contained in:
Pratik Tripathy
2025-11-23 00:08:09 +05:30
parent 2321cdbb60
commit 595858ba25
6 changed files with 188 additions and 171 deletions

View File

@@ -0,0 +1,5 @@
return {
cmd = { "gopls", "--stdio" },
filetypes = { "go" },
settings = {},
}

View File

@@ -12,6 +12,7 @@ vim.lsp.enable({
"cssls", "cssls",
"docker_compose_language_service", "docker_compose_language_service",
"dockerls", "dockerls",
"gopls",
"html", "html",
"jsonls", "jsonls",
"lua_ls", "lua_ls",

View File

@@ -1,4 +1,5 @@
return { return {
{
"mfussenegger/nvim-dap", "mfussenegger/nvim-dap",
dependencies = { dependencies = {
"rcarriga/nvim-dap-ui", "rcarriga/nvim-dap-ui",
@@ -6,7 +7,75 @@ return {
"mason-org/mason.nvim", "mason-org/mason.nvim",
"jay-babu/mason-nvim-dap.nvim", "jay-babu/mason-nvim-dap.nvim",
"theHamsta/nvim-dap-virtual-text", "theHamsta/nvim-dap-virtual-text",
"leoluz/nvim-dap-go",
}, },
config = function()
local dap = require("dap")
local dapui = require("dapui")
require("dap-go").setup()
-- optional
require("mason-nvim-dap").setup({
automatic_installation = true,
handlers = {},
ensure_installed = {
"codelldb",
},
})
-- Dap UI setup
dapui.setup({
icons = { expanded = "", collapsed = "", current_frame = "*" },
controls = {
icons = {
pause = "",
play = "",
step_into = "",
step_over = "",
step_out = "",
step_back = "b",
run_last = "▶▶",
terminate = "",
disconnect = "",
},
},
})
-- Automatically open/close DAP UI
dap.listeners.before.attach["dapui_config"] = dapui.open
dap.listeners.before.launch["dapui_config"] = dapui.open
dap.listeners.before.event_terminated["dapui_config"] = dapui.close
dap.listeners.before.event_exited["dapui_config"] = dapui.close
dap.listeners.after.event_initialized["dapui_config"] = dapui.open
-- Setup virtual text to show variable values inline
require("nvim-dap-virtual-text").setup()
-- Setup Rust & React DAPs here
dap.adapters.codelldb = {
type = "server",
port = "${port}",
executable = {
command = vim.fn.exepath("codelldb"),
args = { "--port", "${port}" },
},
}
dap.configurations.rust = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
},
}
end,
keys = { keys = {
{ {
"<F5>", "<F5>",
@@ -100,66 +169,5 @@ return {
desc = "Debug: Run Last Configuration", desc = "Debug: Run Last Configuration",
}, },
}, },
config = function()
local dap = require("dap")
local dapui = require("dapui")
-- optional
require("mason-nvim-dap").setup({
automatic_installation = true,
handlers = {},
ensure_installed = {
"codelldb",
},
})
-- Dap UI setup
dapui.setup({
icons = { expanded = "", collapsed = "", current_frame = "*" },
controls = {
icons = {
pause = "",
play = "",
step_into = "",
step_over = "",
step_out = "",
step_back = "b",
run_last = "▶▶",
terminate = "",
disconnect = "",
},
},
})
-- Automatically open/close DAP UI
dap.listeners.after.event_initialized["dapui_config"] = dapui.open
dap.listeners.before.event_terminated["dapui_config"] = dapui.close
dap.listeners.before.event_exited["dapui_config"] = dapui.close
-- Setup virtual text to show variable values inline
require("nvim-dap-virtual-text").setup()
-- Setup Rust & React DAPs here
dap.adapters.codelldb = {
type = "server",
port = "${port}",
executable = {
command = vim.fn.exepath("codelldb"),
args = { "--port", "${port}" },
}, },
} }
dap.configurations.rust = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
},
}
end,
}

View File

@@ -211,29 +211,27 @@ return {
vim.defer_fn(function() vim.defer_fn(function()
require("nvim-treesitter.configs").setup({ require("nvim-treesitter.configs").setup({
ensure_installed = { ensure_installed = {
"regex", "bash",
"css",
"dockerfile",
"go",
"html",
"javascript",
"json5",
"jsonc",
"lua",
"markdown", "markdown",
"markdown_inline", "markdown_inline",
"lua",
"rust",
"typescript",
"javascript",
"bash",
"html",
"css",
"json5",
"yaml",
"sql",
"bash",
"jsonc",
"python", "python",
"dockerfile", "regex",
"latex", "rust",
"scss", "scss",
"tsx", "sql",
"vue",
"svelte", "svelte",
"typst", "tsx",
"typescript",
"vue",
"yaml",
}, },
auto_install = true, auto_install = true,

View File

@@ -25,6 +25,7 @@ return {
xml = { "xmllint" }, xml = { "xmllint" },
yaml = { "yamlfmt" }, yaml = { "yamlfmt" },
go = { "gofmt" },
rust = { "rustfmt" }, rust = { "rustfmt" },
["_"] = { "trim_whitespace" }, ["_"] = { "trim_whitespace" },

View File

@@ -7,7 +7,11 @@ clang
cmake cmake
code code
codespell codespell
delve
gitleaks gitleaks
go
golang
gopls
hadolint hadolint
html html
jq jq