GithubHelp home page GithubHelp logo

jbyuki / one-small-step-for-vimkind Goto Github PK

View Code? Open in Web Editor NEW
362.0 9.0 11.0 132 KB

Debug adapter for Neovim plugins

License: MIT License

Lua 100.00%
nvim nvim-dap lua neovim dap-server debugging

one-small-step-for-vimkind's Introduction

one-small-step-for-vimkind

one-small-step-for-vimkind is an adapter for the Neovim lua language. See the DAP protocol to know more about adapters. It allows you to debug any lua code running in a Neovim instance.

Install

Install using your prefered method for example using vim-plug

Plug 'jbyuki/one-small-step-for-vimkind'

" You will also need a comptabile DAP client

Plug 'mfussenegger/nvim-dap'

After installing one-small-step-for-vimkind, you will also need a DAP plugin which will allow you to interact with the adapter. There are mainly two available:

Configuration

Add these lines to work with nvim-dap.

local dap = require"dap"
dap.configurations.lua = { 
  { 
    type = 'nlua', 
    request = 'attach',
    name = "Attach to running Neovim instance",
  }
}

dap.adapters.nlua = function(callback, config)
  callback({ type = 'server', host = config.host or "127.0.0.1", port = config.port or 8086 })
end

Set keybindings to interact with the nvim-dap client.

vim.api.nvim_set_keymap('n', '<F8>', [[:lua require"dap".toggle_breakpoint()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F9>', [[:lua require"dap".continue()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F10>', [[:lua require"dap".step_over()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<S-F10>', [[:lua require"dap".step_into()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F12>', [[:lua require"dap.ui.widgets".hover()<CR>]], { noremap = true })
vim.api.nvim_set_keymap('n', '<F5>', [[:lua require"osv".launch({port = 8086})<CR>]], { noremap = true })

Quickstart

  • Launch the server in the debuggee using F5
  • Open another Neovim instance with the source file
  • Place breakpoint with F8
  • Connect using the DAP client with F9
  • Run your script/plugin in the debuggee

Alternaltively you can:

  • Open a lua file
  • Place breakpoint
  • Invoke require"osv".run_this()

See osv.txt for more detailed instructions.

Troubleshoot

flatten.nvim

Set nest_if_no_args to true. See this issue for more informations.

Debugging plugins

Breakpoints are path-sensitive so they should always be set in the executed file even though they might be multiple copies on the system.

This is the case for packer.nvim when developing local plugins. packer.nvim will create a symlink to the plugins files in the nvim-data directory ( it can be located using :echo stdpath('data')). Make sure to set the breakpoints inside the source files in the nvim-data directory and not the local copy. The plugin directory can be found in nvim-data/site/pack/packer/start/YOUR_PLUGIN.

See osv.txt for more detailed instructions.

Dropbox

If you're using a service like Dropbox to share your plugin file, there might be some issue arising with osv. The reason is that the path executed within Neovim and the path opened in dap doesn't match. Consequently, osv has no way to know if the current running script is the same file as the file opened inside the dap client. Try falling back to a local folder to see if this is the cause.

Neovim is waiting for input at startup. Aborting

This appears when the osv's spawned headless neovim instance has an error at startup. Vim will usually wait for an user input but in case of osv, the instance is simply blocked. Resolve any errors that you see at startup. If there are none, the error might be due to the "headlessness". Start using nvim --headless to see if there are any errors.

Breakpoint is not hit

Important : Make sure osv is not running.

  1. Start tracing with :lua require"osv".start_trace()
  2. Perform the action that should be debugged (for ex. calling a function in your plugin)
  3. Stop tracing and display the results with :lua =require"osv".stop_trace() , the = will pretty print the resulting lua table.

Make sure that the path is correct and the breakpoint is set to a line which effectively gets executed.

Status

Handlers:

  • attach
  • scope
  • setBreakpoints
  • stackTrace
  • threads
  • variables
  • stepIn
  • next
  • stepOut
  • continue
  • evaluate
  • pause
  • terminate
  • disconnect
  • setVariable
  • setFunctionBreakpoints
  • setExceptionBreakpoints
  • breakpointLocations

Events:

  • initialized
  • stopped
  • terminated
  • exited
  • output

Capabilities:

  • supportsConditionalBreakpoints
  • supportsHitConditionalBreakpoints
  • supportsSetVariable
  • supportTerminateDebuggee

Name

it's a debugger for the moon language. - @tjdevries

Plugin architecture

Please refer to ARCHITECTURE.md.

Credits

Contribute

See here.

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.