### packer.nvim Installation Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Instructions for installing the nvim-dap-go plugin using the packer.nvim plugin manager. ```lua use 'leoluz/nvim-dap-go' ``` -------------------------------- ### vim-plug Installation Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Instructions for installing the nvim-dap-go plugin using the vim-plug plugin manager. ```vimL Plug 'leoluz/nvim-dap-go' ``` -------------------------------- ### Setup nvim-dap-go Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Registers the nvim-dap-go plugin with default configurations. Customizations can be applied by passing a configuration table to the setup function, including additional DAP configurations, Delve settings, and test-related options. ```lua require('dap-go').setup() require('dap-go').setup { -- Additional dap configurations can be added. -- dap_configurations accepts a list of tables where each entry -- represents a dap configuration. For more details see: -- |dap-configuration| dap_configurations = { { -- Must be "go" or it will be ignored by the plugin type = "go", name = "Attach remote", mode = "remote", request = "attach", }, }, -- delve configurations delve = { -- the path to the executable dlv which will be used for debugging. -- by default, this is the "dlv" executable on your PATH. path = "dlv", -- time to wait for delve to initialize the debug session. -- default to 20 seconds initialize_timeout_sec = 20, -- a string that defines the port to start delve debugger. -- default to string "${port}" which instructs nvim-dap -- to start the process in a random available port. -- if you set a port in your debug configuration, its value will be -- assigned dynamically. port = "${port}", -- additional args to pass to dlv args = {}, -- the build flags that are passed to delve. -- defaults to empty string, but can be used to provide flags -- such as "-tags=unit" to make sure the test suite is -- compiled during debugging, for example. -- passing build flags using args is ineffective, as those are -- ignored by delve in dap mode. build_flags = "", -- whether the dlv process to be created detached or not. there is -- an issue on delve versions < 1.24.0 for Windows where this needs to be -- set to false, otherwise the dlv server creation will fail. detached = vim.fn.has("win32") == 0, }, -- options related to running closest test tests = { -- enables verbosity when running the test. verbose = false, }, } ``` -------------------------------- ### VSCode Launch Configuration for Remote Debugging Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Example VSCode launch.json configuration to attach to a remote Go process. ```json { "version": "0.2.0", "configurations": [ { "name": "Remote debug API server", "type": "go", "request": "attach", "mode": "remote", "port": 4444, "host": "127.0.0.1", "substitutePath": [ { "from": "${workspaceFolder}", "to": "/usr/src/app" } ] } ] } ``` -------------------------------- ### nvim-dap-go Keymap Configuration Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Example Lua configuration for setting up keymaps to trigger nvim-dap-go debugging functions. ```lua local dapgo = require('dap-go') vim.keymap.set("n", "dt", dapgo.debug_test) vim.keymap.set("n", "dl", dapgo.debug_last_test) ``` -------------------------------- ### Setup Debugger with Build Flags Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Configures nvim-dap-go to allow debugging with custom build flags, prompting the user for input. ```lua require('dap-go').setup { dap_configurations = { { type = "go", name = "Debug (Build Flags)", request = "launch", program = "${file}", buildFlags = require("dap-go").get_build_flags, }, }, } require("dap-go").setup({ dap_configurations = { { type = "go", name = "Debug (Build Flags & Arguments)", request = "launch", program = "${file}", args = require("dap-go").get_arguments, buildFlags = require("dap-go").get_build_flags, }, } }) ``` -------------------------------- ### Start Delve in Headless Mode Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Command to start the Delve debugger in headless mode, allowing remote connections. ```sh dlv debug -l 127.0.0.1:38697 --headless ./main.go -- subcommand --myflag=xyz ``` -------------------------------- ### Start Delve in Headless Mode Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Command to start the Delve debugger in headless mode, allowing it to listen for remote connections. Subcommands and flags can be passed after `--`. ```sh dlv debug -l 127.0.0.1:38697 --headless ./main.go -- subcommand --myflag=xyz ``` -------------------------------- ### Register nvim-dap-go Plugin Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Registers the Go adapter and configurations for debugging Go tests by calling the setup function. This is the primary step to enable the plugin's functionality within Neovim. ```lua require('dap-go').setup() ``` -------------------------------- ### Configure nvim-dap-go Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Provides comprehensive configuration options for nvim-dap-go, allowing customization of Delve settings, additional DAP configurations, and test execution verbosity. This example demonstrates all available parameters. ```lua require('dap-go').setup { -- Additional dap configurations can be added. -- dap_configurations accepts a list of tables where each entry -- represents a dap configuration. For more details do: -- :help dap-configuration dap_configurations = { { -- Must be "go" or it will be ignored by the plugin type = "go", name = "Attach remote", mode = "remote", request = "attach", }, }, -- delve configurations delve = { -- the path to the executable dlv which will be used for debugging. -- by default, this is the "dlv" executable on your PATH. path = "dlv", -- time to wait for delve to initialize the debug session. -- default to 20 seconds initialize_timeout_sec = 20, -- a string that defines the port to start delve debugger. -- default to string "${port}" which instructs nvim-dap -- to start the process in a random available port. -- if you set a port in your debug configuration, its value will be -- assigned dynamically. port = "${port}", -- additional args to pass to dlv args = {}, -- the build flags that are passed to delve. -- defaults to empty string, but can be used to provide flags -- such as "-tags=unit" to make sure the test suite is -- compiled during debugging, for example. -- passing build flags using args is ineffective, as those are -- ignored by delve in dap mode. -- avaliable ui interactive function to prompt for arguments get_arguments build_flags = {}, -- whether the dlv process to be created detached or not. there is -- an issue on delve versions < 1.24.0 for Windows where this needs to be -- set to false, otherwise the dlv server creation will fail. -- avaliable ui interactive function to prompt for build flags: get_build_flags detached = vim.fn.has("win32") == 0, -- the current working directory to run dlv from, if other than -- the current working directory. cwd = nil, }, -- options related to running closest test tests = { -- enables verbosity when running the test. verbose = false, }, } ``` -------------------------------- ### Setup Debugger for Remote Attach Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Configures nvim-dap-go to attach to a remote Go process using Delve in headless mode. ```lua require('dap-go').setup { dap_configurations = { { type = "go", name = "Attach remote", mode = "remote", request = "attach", }, }, } ``` -------------------------------- ### VSCode Launch Configuration for Remote Debugging Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Example VSCode `launch.json` configuration for attaching to a remote Go debugging session. It specifies the port, host, and path substitutions for the Delve debugger. ```json { "version": "0.2.0", "configurations": [ { "name": "Remote debug API server", "type": "go", "request": "attach", "mode": "remote", "port": 4444, "host": "127.0.0.1", "substitutePath": [ { "from": "${workspaceFolder}", "to": "/usr/src/app" } ] } ] } ``` -------------------------------- ### Debugging Individual Tests Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt This feature allows running the closest Go test to the cursor in debug mode. It leverages the Treesitter parser to identify the relevant test. Ensure the Go Treesitter parser is installed via `:TSInstall go`. ```go # This plugin makes usage of treesitter to find the nearest test to # debug. Make sure you have the Go treesitter parser installed. If using # |nvim-Treesitter| plugin you can install with `:TSInstall go`. ``` -------------------------------- ### Debug Go with Build Flags and Arguments Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Registers a debug configuration that prompts for both build flags and arguments when launching a Go debug session. It utilizes `get_build_flags` and `get_arguments` from the dap-go plugin. ```lua require("dap-go").setup({ dap_configurations = { { type = "go", name = "Debug (Build Flags & Arguments)", request = "launch", program = "${file}", args = require("dap-go").get_arguments, buildFlags = require("dap-go").get_build_flags, }, } }) ``` -------------------------------- ### Debug Go with Build Flags Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Registers a new debug configuration in nvim-dap to allow debugging Go programs with custom build flags. It uses the `get_build_flags` function from the dap-go plugin. ```lua require('dap-go').setup ({ dap_configurations = { { type = "go", name = "Debug (Build Flags)", request = "launch", program = "${file}", buildFlags = require("dap-go").get_build_flags, }, }, }) ``` -------------------------------- ### Debug Individual Go Test Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Executes the Go test closest to the cursor. Supports customization via a table argument for build flags. ```lua require('dap-go').debug_test() require("dap-go").debug_test({ buildFlags = "-tags=integration", }) ``` -------------------------------- ### Debug Last Go Test Source: https://github.com/leoluz/nvim-dap-go/blob/main/doc/nvim-dap-go.txt Re-runs the most recently executed Go test. ```lua require('dap-go').debug_last_test() ``` -------------------------------- ### Nvim Mapping for Debugging Tests Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Defines a Neovim mapping (`td`) to trigger the `debug_test` function from the dap-go plugin, facilitating quick debugging of Go tests. ```vimL nmap td :lua require('dap-go').debug_test() ``` -------------------------------- ### Attach to Remote Delve Debugger Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Configures nvim-dap to attach to a Go process running Delve in headless mode. This allows remote debugging sessions. ```lua require('dap-go').setup { dap_configurations = { { type = "go", name = "Attach remote", mode = "remote", request = "attach", }, }, } ``` -------------------------------- ### Debug Closest Test Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Initiates a debug session for the Go test closest to the current cursor position. This feature leverages treesitter to accurately identify the target test. ```lua require('dap-go').debug_test() ``` -------------------------------- ### Debug Last Test Source: https://github.com/leoluz/nvim-dap-go/blob/main/README.md Re-runs the last executed Go test in debug mode. This is useful for quickly iterating on a specific test without needing to locate it again. ```lua require('dap-go').debug_last_test() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.