rcarriga / nvim-dap-ui

A UI for nvim-dap
MIT License
2.62k stars 96 forks source link

[Question] Constructing layouts for different use cases #252

Open akinsho opened 1 year ago

akinsho commented 1 year ago

Hi @rcarriga,

So I've been reading through previous issues and the docs and am trying to understand whether or not the nvim-dap-ui currently supports the functionality I'll describe.

I'm trying to setup a series of layouts for dap ui along the lines of a full multiwindow layout for deep debugging as well as more minimal setups since some filetypes I work with actually just run using the debugger and so during normal development I don't want loads of windows open.

I can jerryrig a version of the functionality I want using the existing elements key e.g.

    layouts = {
      {
        elements = {
          { id = 'scopes', size = 0.25 },
          { id = 'breakpoints', size = 0.25 },
          { id = 'stacks', size = 0.25 },
          { id = 'watches', size = 0.25 },
        },
        position = 'left',
        size = 20,
      },
      { elements = { { id = 'repl', size = 0.9 } }, position = 'bottom', size = 10 },
      -- { elements = { { id = 'console', size = 0.5 } }, position = 'bottom', size = 10 },
    },
  },

Using the above I can do something like

local ft_map = {dart = 2}

map(<blah>, function() dapui.open(ft_map[vim.bo.ft]) end)

With the above config I can ensure that only the REPL is opened in dart but I've noticed that this isn't really a "layout".

If I wanted for example to have a layout that showed just scopes but with the repl and console, or one with everything apart from the console etc. this doesn't work

e.g.

layouts = {
    { -- this level of nesting does not work so I cannot truly group layouts
        {
            "scopes"
            "breakpoints"
        }
        { "repl", "console"}
    }
}

Hopefully what I'm trying to achieve makes sense. Tbh I don't necessarily need a per filetype solution builtin to dap ui although that would be very cool, the main issue is how do I create multiple multiwindow layouts that include horizontal and vertical windows?

rcarriga commented 1 year ago

This is something I've been interested in implementing for a while, I just haven't had a chance. My current thinking is to scrap the existing layout code and replace it with nui.nvim because it is a plugin dedicated to this kind of thing rather than the janky code I've been tacking on functionality to for too long :sweat_smile:

You can access all of the buffers of the elements through require("dapui").elements, where each has a buffer() method. The buffer can change over time, which is why it's not a property. With this, you could manually create a nui.nvim setup to do what you're looking for

akinsho commented 1 year ago

I've had this exact thought re. nui.nvim @rcarriga 😆 (https://github.com/akinsho/flutter-tools.nvim/issues/219). My current solution works well enough for my current use case. It can easily wait till you get round to the refactor. Otherwise if I manage to do the one for my plugin and end up feeling like a nui expert and needing it, I might give it a go

RyanCarrier commented 1 year ago

I might be misunderstanding but can't you do it by just having different layouts open at the same time?

In dart/flutter I like to have repl and my diagnostic list so they open automatically, but then sometimes I'll also want the rest of the layout, so for that I have it set to F7 to toggle open the extra stuff, with my repl/trouble layout still open and it seems to work fine?

So in your case couldn't you just have the bottom multi window and left multi window in two different layouts then just open both of them with different listeners for different file types?

https://github.com/RyanCarrier/conf/blob/master/nvim/.config/nvim/lua/plugins/dap.lua#L140