ThePrimeagen / harpoon

MIT License
6.25k stars 348 forks source link

API Docs Are Wrong #608

Open dragonlobster opened 2 weeks ago

dragonlobster commented 2 weeks ago

The API docs state that you can customize your add function by using the following line of code:

local harpoon = require("harpoon")

harpoon:setup({
    -- Setting up custom behavior for a list named "cmd"
    "cmd" = {

        -- When you call list:add() this function is called and the return
        -- value will be put in the list at the end.
        --
        -- which means same behavior for prepend except where in the list the
        -- return value is added
        --
        -- @param possible_value string only passed in when you alter the ui manual
        add = function(possible_value)
            -- get the current line idx
            local idx = vim.fn.line(".")

            -- read the current line
            local cmd = vim.api.nvim_buf_get_lines(0, idx - 1, idx, false)[1]
            if cmd == nil then
                return nil
            end

            return {
                value = cmd,
                context = { ... any data you want ... },
            }
        end,

        --- This function gets invoked with the options being passed in from
        --- list:select(index, <...options...>)
        --- @param list_item {value: any, context: any}
        --- @param list { ... }
        --- @param option any
        select = function(list_item, list, option)
            -- WOAH, IS THIS HTMX LEVEL XSS ATTACK??
            vim.cmd(list_item.value)
        end

    }
})

Firstly this is not proper lua code, the dictionary key should be ["cmd"].

Secondly, the function you're supposed to customize is create_list_item, not add. Just look at config.lua line 188:

---@param config HarpoonPartialConfigItem
            ---@param name? any
            ---@return HarpoonListItem
            create_list_item = function(config, name)
                name = name
                    or normalize_path(
                        vim.api.nvim_buf_get_name(
...

I would create a PR but it seems like PRs on docs don't get merged. The fact the only example of API in the README doesn't even work is frustrating.