rcarriga / nvim-dap-ui

A UI for nvim-dap
MIT License
2.69k stars 102 forks source link

(feautre)expand all #151

Open yyy33 opened 2 years ago

yyy33 commented 2 years ago

hello rcarriga ,can you add expand all and un expand all, It will be very convenient that , thankyou

rcarriga commented 2 years ago

Can you elaborate on what you mean by expand all?

yyy33 commented 2 years ago

Can you elaborate on what you mean by expand all?

For example, when I'm debugging lua, I'm looking at the local variables of a function and it has a table in it, but there are so many levels that it would be nice to be able to expand it all

mwcz commented 1 year ago

If folding could be leveraged, the commands & logic already exist for that, like zo and zO to open one or all folds under the cursor. Maybe a custom fold method could be added to the scopes pane?

tabboud commented 1 year ago

Recursively expanding the "Locals" buffer would be super helpful, especially if we leveraged the existing unfold commands like zR. Here's a screenshot of one such example where I had to press Enter for every nested level

Screenshot 2023-03-23 at 1 38 31 PM
phcerdan commented 1 year ago

It will be super helpful indeed. Even if vim folds are not implemented, any hacky workaround would be good too. Thanks for nvim-dap-ui!

fira42073 commented 7 months ago

Any updates on this issue? C:

D00mch commented 3 weeks ago

Any updates? How do you guys live without this? For example, when I want to expand a list of 100 elements, what do I do to find what I want? My idea was to expand all and search what I need, but it's impossible.

fira42073 commented 3 weeks ago

@D00mch I use https://github.com/kevinhwang91/nvim-ufo

D00mch commented 3 weeks ago

@fira42073 I am using it as well, maybe some bindings are in conflict. For example, I can't expand/fold locals with zR, zO, zM. My z* are remaped this way:

zR ufo.openAllFolds
zM ufo.closeAllFolds
phcerdan commented 1 week ago

@fira42073 What provider are you using in ufo? I am using treesitter and it doesn't seem to work for nvim-dap-ui.

fira42073 commented 1 week ago

My ufo config:

local tables = require("action.tables")
local ufo = require("ufo")

local opts = { noremap = true }

-- folding options
vim.o.foldenable = true
vim.o.foldcolumn = "1" -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldmethod = "expr"

-- folding keymaps
vim.keymap.set("n", "zR", ufo.openAllFolds, tables.merge(opts, { desc = "Open all folds" }))
vim.keymap.set("n", "zM", ufo.closeAllFolds, tables.merge(opts, { desc = "Close all folds" }))
vim.keymap.set("n", "zr", ufo.openFoldsExceptKinds, tables.merge(opts, { desc = "Open folds except kinds" }))
vim.keymap.set("n", "zm", ufo.closeFoldsWith, tables.merge(opts, { desc = "Close folds with" }))

-- peek under the fold (scroll using ctrl+u, ctrl+d)
vim.keymap.set("n", "<leader>F", function()
    local winid = ufo.peekFoldedLinesUnderCursor()
    if not winid then
        -- choose one of coc.nvim and nvim lsp
        vim.lsp.buf.hover()
    end
end, tables.merge(opts, { desc = "Peek under the fold" }))

-- folding renderer
local fold_virt_text_handler = function(virtText, lnum, endLnum, width, truncate)
    local newVirtText = {}
    local suffix = (" 󰁂 %d "):format(endLnum - lnum)
    local sufWidth = vim.fn.strdisplaywidth(suffix)
    local targetWidth = width - sufWidth
    local curWidth = 0
    for _, chunk in ipairs(virtText) do
        local chunkText = chunk[1]
        local chunkWidth = vim.fn.strdisplaywidth(chunkText)
        if targetWidth > curWidth + chunkWidth then
            table.insert(newVirtText, chunk)
        else
            chunkText = truncate(chunkText, targetWidth - curWidth)
            local hlGroup = chunk[2]
            table.insert(newVirtText, { chunkText, hlGroup })
            chunkWidth = vim.fn.strdisplaywidth(chunkText)
            -- str width returned from truncate() may less than 2nd argument, need padding
            if curWidth + chunkWidth < targetWidth then
                suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
            end
            break
        end
        curWidth = curWidth + chunkWidth
    end
    table.insert(newVirtText, { suffix, "MoreMsg" })
    return newVirtText
end

-- folding setup
ufo.setup({
    open_fold_hl_timeout = 150,
    preview = {
        win_config = {
            border = { "", "─", "", "", "", "─", "", "" },
            winhighlight = "Normal:Folded",
            winblend = 0,
        },
        mappings = {
            scrollU = "<C-u>",
            scrollD = "<C-d>",
            jumpTop = "[",
            jumpBot = "]",
        },
    },
    provider_selector = function(_, _, _)
        -- Treesitter as a main provider instead
        -- (Note: the `nvim-treesitter` plugin is *not* needed.)
        -- ufo uses the same query files for folding (queries/<lang>/folds.scm)
        -- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()`
        return { "treesitter", "indent" }
    end,
    fold_virt_text_handler = fold_virt_text_handler,
    close_fold_kinds_for_ft = { "comment", "imports", "region" },
    enable_get_fold_virt_text = true,
})
phcerdan commented 1 week ago

Do I need to install a specific treesitter parser for nvim-dap-ui? i see that the filetype for the buffer is: 'dapui_scopes'

fira42073 commented 1 week ago

I only have these

            { "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" },
            { "nvim-treesitter/nvim-treesitter-context" },
            { "nvim-treesitter/nvim-treesitter-textobjects" },
phcerdan commented 1 week ago

Umm, still don't get it.

If I do :InspectTree (nvim >=0.9) I got:

Error executing Lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/dev.lua:336: No parser available for the given buffer:
/usr/share/nvim/runtime/lua/vim/treesitter.lua:97: There is no parser available for buffer 12 and one could not be created because lang could not be determined. Either pass lang or set the buffer filetype
stack traceback:
        [C]: in function 'assert'
        /usr/share/nvim/runtime/lua/vim/treesitter/dev.lua:336: in function 'inspect_tree'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:454: in function 'inspect_tree'
        vim/_defaults.lua: in function <vim/_defaults.lua:0>

Which honestly, makes sense, how would Treesitter know how to parse a dapui_scopes filetype?

Are you sure you don't have an extra mapping or something related to Treesitter and nvim-dap-ui?

D00mch commented 1 week ago

I tried everything (even copy pasted your config), it doesn't work within dapui_scopes window.