Shougo / ddu.vim

Dark deno-powered UI framework for Vim/Neovim
MIT License
294 stars 23 forks source link

`resum` doesn't work when I set custom column via dictionary style #101

Closed kamecha closed 9 months ago

kamecha commented 9 months ago

Warning: I will close the issue without the minimal init.vim and the reproduction instructions.

Problems summary

When I use ddu-column-custom via dictionary style ( in Neovim), resume option doesn't work.

Expected

it is work as I set ddu-column-custom without dictionary style.

Environment Information

Provide a minimal init.vim/vimrc without plugin managers (Required!)

" Your minimal init.vim/vimrc
set rtp+=~/.cache/dein/nvim/repos/github.com/vim-denops/denops.vim

set rtp+=~/.cache/dein/nvim/repos/github.com/Shougo/ddu.vim
set rtp+=~/.cache/dein/nvim/repos/github.com/Shougo/ddu-ui-filer
set rtp+=~/.cache/dein/nvim/repos/github.com/Shougo/ddu-source-file
set rtp+=~/.cache/dein/nvim/repos/github.com/Shougo/ddu-kind-file
set rtp+=~/.cache/dein/nvim/repos/github.com/kamecha/ddu-column-custom

nnoremap [ddu] <Nop>
nmap <Space>u [ddu]

lua << EOF
vim.keymap.set('n', '[ddu]e', function()

    local function getLengthCallback(args)
        local length = 0
        for _, item in ipairs(args.items) do
            local display = item["word"]
            if item["display"] ~= nil and item["display"] ~= "" then
                display = item["display"]
            end
            display = " " .. "+" .. display
            length = math.max(length, #display)
        end
        return length
    end

    local function getTextCallback(args)
        local display = args.item["word"]
        if args.item["display"] ~= nil and args.item["display"] ~= "" then
            display = args.item["display"]
        end
        local text = ""
        if args.item["__level"] == 0 then
            if args.item["__expanded"] then
                text = "-" .. display
            else
                text = "+" .. display
            end
        else
            text = " " .. "|" ..display
        end
        return { text = text }
    end

    vim.fn["ddu#start"]({
        ui = "filer",
        resume = true,
        sources = {
            {
                name = "file",
                options = {
                    columns = {
                        {
                            name = "custom",
                            params = {
                                getLengthCallbackId = vim.fn["denops#callback#register"](getLengthCallback),
                                getTextCallbackId = vim.fn["denops#callback#register"](getTextCallback),
                            }
                        }
                    }
                },
            },
        },
    })
end, { remap = true })

EOF

autocmd FileType ddu-filer call s:ddu_filer_my_settings()

function s:ddu_filer_my_settings() abort
    nnoremap <buffer> e
                \ <Cmd>call ddu#ui#do_action('expandItem', {'mode': 'toggle'})<CR>
    nnoremap <buffer> q
                \ <Cmd>call ddu#ui#do_action('quit')<CR>
endfunction

How to reproduce the problem from neovim/Vim startup (Required!)

to fire expandItem action, current working directory has directory item.

  1. type <Space> u e to start ddu
  2. type e on directory item to fire ecpandItem action
  3. type q to quit ddu
  4. type <Space> u e to start ddu <- in this, the tree (expanded) does not resume... :sob:

Screenshot (if possible)

hoge

Upload the log messages by :redir and :message (if errored)

Note

function GetLengthCallback(args) abort
    let length = 0
    for item in a:args->get("items")
        let display = item["word"]
        if item->get("display") != 0 && item["display"] != ""
            let display = item["display"]
        endif
        let display = " " .. "+" .. display
        let length = max([length, len(display)])
    endfor
    return length
endfunction

function GetTextCallback(args) abort
    let display = a:args->get("item")["word"]
    if a:args->get("item")->get("display") != 0 && a:args->get("item")->get("display") != ""
        let display = a:args->get("item")["display"]
    endif
    let text = ""
    if a:args->get("item")["__level"] == 0
        if a:args->get("item")["__expanded"]
            let text = "-" .. display
        else
            let text = "+" .. display
        endif
    else
        let text = " " .. "|" ..display
    endif
    return { "text": text }
endfunction

nmap <silent> [ddu]F <Cmd>call ddu#start(#{
            \ ui: 'filer',
            \ resume: v:true,
            \ sources: [
            \   #{
            \     name: 'file',
            \     options: #{
            \       columns: [
            \         #{
            \           name: 'custom',
            \           params: #{
            \             getLengthCallbackId: denops#callback#register(function('GetLengthCallback')),
            \             getTextCallbackId: denops#callback#register(function('GetTextCallback')),
            \           }
            \         }
            \       ]
            \     }
            \   }
            \ ],
            \ })<CR>

lua << EOF
vim.keymap.set('n', '[ddu]E', function()
    local function getLengthCallback(args)
        local length = 0
        for _, item in ipairs(args.items) do
            local display = item["word"]
            if item["display"] ~= nil and item["display"] ~= "" then
                display = item["display"]
            end
            display = " " .. "+" .. display
            length = math.max(length, #display)
        end
        return length
    end

    local function getTextCallback(args)
        local display = args.item["word"]
        if args.item["display"] ~= nil and args.item["display"] ~= "" then
            display = args.item["display"]
        end
        local text = ""
        if args.item["__level"] == 0 then
            if args.item["__expanded"] then
                text = "-" .. display
            else
                text = "+" .. display
            end
        else
            text = " " .. "|" .. display
        end
        return { text = text }
    end

    vim.fn["ddu#start"]({
        ui = "filer",
        resume = true,
        sources = {
            {
                name = "file",
                options = { columns = { "custom" } },
            },
        },
        columnParams = {
            custom = {
                getLengthCallbackId = vim.fn["denops#callback#register"](getLengthCallback),
                getTextCallbackId = vim.fn["denops#callback#register"](getTextCallback),
            }
        },
    })
end, { remap = true })
EOF

Shougo commented 9 months ago

Feature. denops#callback#register() is changed. You must save the value.

Shougo commented 9 months ago

To use resume feature, sources must be same.