Giter Site home page Giter Site logo

dexianta / nvim-dap-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leoluz/nvim-dap-go

0.0 0.0 0.0 189 KB

An extension for nvim-dap providing configurations for launching go debugger (delve) and debugging individual tests

License: MIT License

Lua 100.00%

nvim-dap-go's Introduction

nvim-dap-go

An extension for nvim-dap providing configurations for launching go debugger (delve) and debugging individual tests.

Features

  • Auto launch Delve. No configuration needed. You just have to have dlv in your path.
  • Run just the closest test from the cursor in debug mode (uses treesitter). See debugging individual tests section below for more details.
  • Configuration to attach nvim-dap and Delve into a running process and start a debug session.
  • Configuration to start a debug session in the main function.
  • Configuration to run tests in a debug session.

Pre-reqs

This plugin extension make 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.

Installation

  • Install like any other neovim plugin:

Usage

Register the plugin

Call the setup function in your init.vim to register the go adapter and the configurations to debug go tests:

lua require('dap-go').setup()

Configuring

It is possible to customize nvim-dap-go by passing a config table in the setup function.

The example below shows all the possible configurations:

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
    port = "${port}",
    -- additional args to pass to dlv
    args = {}
  },
}

Use nvim-dap as usual

  • Call :lua require('dap').continue() to start debugging.
  • All pre-configured debuggers will be displayed for you to choose from.
  • See :help dap-mappings and :help dap-api.

Debugging individual tests

To debug the closest method above the cursor use you can run:

  • :lua require('dap-go').debug_test()

Once a test was run, you can simply run it again from anywhere:

  • :lua require('dap-go').debug_last_test()

It is better to define a mapping to invoke this command. See the mapping section below.

Debugging with command-line arguments

  1. Select the option Debug (Arguments)
  2. Enter each argument separated by a space (i.e. option1 option2 option3)
  3. Press enter

Start Debug Session with Arguments Enter Arguments Begin Debugging

Debugging with dlv in headless mode

  1. Register a new option to attach to a remote debugger:
lua require('dap-go').setup {
  dap_configurations = {
    {
      type = "go",
      name = "Attach remote",
      mode = "remote",
      request = "attach",
    },
  },
}
  1. Start dlv in headless mode. You can specify subcommands and flags after --, e.g.,
dlv debug -l 127.0.0.1:38697 --headless ./main.go -- subcommand --myflag=xyz
  1. Call :lua require('dap').continue() to start debugging.
  2. Select the new registered option Attach remote.

Mappings

nmap <silent> <leader>td :lua require('dap-go').debug_test()<CR>

Acknowledgement

Thanks to the nvim-dap-python for the inspiration.

nvim-dap-go's People

Contributors

leoluz avatar elianiva avatar granddave avatar elliottminns avatar freddiehaddad avatar gataky avatar kradalby avatar marcomayer avatar shihanng avatar dexianta avatar xuxinx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.