From 595858ba253ce4b086e13585a86e0a21bd7b0002 Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Sun, 23 Nov 2025 00:08:09 +0530 Subject: [PATCH] feat(nvim): Add golang support --- common/.config/nvim/lsp/gopls.lua | 5 + common/.config/nvim/lua/core/lsp.lua | 1 + .../.config/nvim/lua/plugins/code-debug.lua | 314 +++++++++--------- .../.config/nvim/lua/plugins/code-generic.lua | 34 +- .../.config/nvim/lua/plugins/formatting.lua | 1 + scripts/package-list-os | 4 + 6 files changed, 188 insertions(+), 171 deletions(-) create mode 100644 common/.config/nvim/lsp/gopls.lua diff --git a/common/.config/nvim/lsp/gopls.lua b/common/.config/nvim/lsp/gopls.lua new file mode 100644 index 0000000..5399439 --- /dev/null +++ b/common/.config/nvim/lsp/gopls.lua @@ -0,0 +1,5 @@ +return { + cmd = { "gopls", "--stdio" }, + filetypes = { "go" }, + settings = {}, +} diff --git a/common/.config/nvim/lua/core/lsp.lua b/common/.config/nvim/lua/core/lsp.lua index 5c3deda..2e3d6a3 100644 --- a/common/.config/nvim/lua/core/lsp.lua +++ b/common/.config/nvim/lua/core/lsp.lua @@ -12,6 +12,7 @@ vim.lsp.enable({ "cssls", "docker_compose_language_service", "dockerls", + "gopls", "html", "jsonls", "lua_ls", diff --git a/common/.config/nvim/lua/plugins/code-debug.lua b/common/.config/nvim/lua/plugins/code-debug.lua index 94cc22e..b7c1b17 100644 --- a/common/.config/nvim/lua/plugins/code-debug.lua +++ b/common/.config/nvim/lua/plugins/code-debug.lua @@ -1,165 +1,173 @@ return { - "mfussenegger/nvim-dap", - dependencies = { - "rcarriga/nvim-dap-ui", - "nvim-neotest/nvim-nio", - "mason-org/mason.nvim", - "jay-babu/mason-nvim-dap.nvim", - "theHamsta/nvim-dap-virtual-text", - }, - keys = { - { - "", - function() - require("dap").continue() - end, - desc = "Debug: Start/Continue", - }, - { - "Ds", - function() - require("dap").continue() - end, - desc = "Debug: Start/Continue", - }, - { - "", - function() - require("dap").step_into() - end, - desc = "Debug: Step Into", - }, - { - "Di", - function() - require("dap").step_into() - end, - desc = "Debug: Step Into", - }, - { - "", - function() - require("dap").step_over() - end, - desc = "Debug: Step Over", - }, - { - "Do", - function() - require("dap").step_over() - end, - desc = "Debug: Step Over", - }, - { - "", - function() - require("dap").step_out() - end, - desc = "Debug: Step Out", - }, - { - "DO", - function() - require("dap").step_out() - end, - desc = "Debug: Step Out", - }, - { - "", - function() - require("dap").toggle_breakpoint() - end, - desc = "Debug: Toggle Breakpoint", - }, - { - "Db", - function() - require("dap").toggle_breakpoint() - end, - desc = "Debug: Toggle Breakpoint", - }, - { - "DB", - function() - require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) - end, - desc = "Debug: Set Conditional Breakpoint", - }, - { - "Dt", - function() - require("dapui").toggle() - end, - desc = "Debug: Toggle UI", - }, - { - "Dl", - function() - require("dap").run_last() - end, - desc = "Debug: Run Last Configuration", - }, - }, - config = function() - local dap = require("dap") - local dapui = require("dapui") + { + "mfussenegger/nvim-dap", + dependencies = { + "rcarriga/nvim-dap-ui", + "nvim-neotest/nvim-nio", + "mason-org/mason.nvim", + "jay-babu/mason-nvim-dap.nvim", + "theHamsta/nvim-dap-virtual-text", - -- optional - require("mason-nvim-dap").setup({ - automatic_installation = true, - handlers = {}, - ensure_installed = { - "codelldb", - }, - }) + "leoluz/nvim-dap-go", + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") - -- 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 = "⏏", + require("dap-go").setup() + + -- optional + require("mason-nvim-dap").setup({ + automatic_installation = true, + handlers = {}, + ensure_installed = { + "codelldb", }, - }, - }) + }) - -- 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 + -- 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 = "⏏", + }, + }, + }) - -- Setup virtual text to show variable values inline - require("nvim-dap-virtual-text").setup() + -- 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 Rust & React DAPs here - dap.adapters.codelldb = { - type = "server", - port = "${port}", - executable = { - command = vim.fn.exepath("codelldb"), - args = { "--port", "${port}" }, - }, - } + -- Setup virtual text to show variable values inline + require("nvim-dap-virtual-text").setup() - dap.configurations.rust = { + -- 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 = { { - name = "Launch file", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file") + "", + function() + require("dap").continue() end, - cwd = "${workspaceFolder}", - stopOnEntry = false, + desc = "Debug: Start/Continue", }, - } - end, + { + "Ds", + function() + require("dap").continue() + end, + desc = "Debug: Start/Continue", + }, + { + "", + function() + require("dap").step_into() + end, + desc = "Debug: Step Into", + }, + { + "Di", + function() + require("dap").step_into() + end, + desc = "Debug: Step Into", + }, + { + "", + function() + require("dap").step_over() + end, + desc = "Debug: Step Over", + }, + { + "Do", + function() + require("dap").step_over() + end, + desc = "Debug: Step Over", + }, + { + "", + function() + require("dap").step_out() + end, + desc = "Debug: Step Out", + }, + { + "DO", + function() + require("dap").step_out() + end, + desc = "Debug: Step Out", + }, + { + "", + function() + require("dap").toggle_breakpoint() + end, + desc = "Debug: Toggle Breakpoint", + }, + { + "Db", + function() + require("dap").toggle_breakpoint() + end, + desc = "Debug: Toggle Breakpoint", + }, + { + "DB", + function() + require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) + end, + desc = "Debug: Set Conditional Breakpoint", + }, + { + "Dt", + function() + require("dapui").toggle() + end, + desc = "Debug: Toggle UI", + }, + { + "Dl", + function() + require("dap").run_last() + end, + desc = "Debug: Run Last Configuration", + }, + }, + }, } diff --git a/common/.config/nvim/lua/plugins/code-generic.lua b/common/.config/nvim/lua/plugins/code-generic.lua index a7d5a8f..dbc1da6 100644 --- a/common/.config/nvim/lua/plugins/code-generic.lua +++ b/common/.config/nvim/lua/plugins/code-generic.lua @@ -211,29 +211,27 @@ return { vim.defer_fn(function() require("nvim-treesitter.configs").setup({ ensure_installed = { - "regex", + "bash", + "css", + "dockerfile", + "go", + "html", + "javascript", + "json5", + "jsonc", + "lua", "markdown", "markdown_inline", - "lua", - "rust", - "typescript", - "javascript", - "bash", - "html", - "css", - "json5", - "yaml", - "sql", - "bash", - "jsonc", "python", - "dockerfile", - "latex", + "regex", + "rust", "scss", - "tsx", - "vue", + "sql", "svelte", - "typst", + "tsx", + "typescript", + "vue", + "yaml", }, auto_install = true, diff --git a/common/.config/nvim/lua/plugins/formatting.lua b/common/.config/nvim/lua/plugins/formatting.lua index 893f29a..8bbec49 100644 --- a/common/.config/nvim/lua/plugins/formatting.lua +++ b/common/.config/nvim/lua/plugins/formatting.lua @@ -25,6 +25,7 @@ return { xml = { "xmllint" }, yaml = { "yamlfmt" }, + go = { "gofmt" }, rust = { "rustfmt" }, ["_"] = { "trim_whitespace" }, diff --git a/scripts/package-list-os b/scripts/package-list-os index f3216cf..0e09dd9 100644 --- a/scripts/package-list-os +++ b/scripts/package-list-os @@ -7,7 +7,11 @@ clang cmake code codespell +delve gitleaks +go +golang +gopls hadolint html jq