Giter VIP home page Giter VIP logo

Comments (1)

asmodeus812 avatar asmodeus812 commented on June 16, 2024

Probably not worth the effort, one could simply fetch the symbol ranges and do something simple like that, for future reference to whoever comes around this issue of moving to next/prev usage in the buffer

local function lsp_moveto_usage(dir, pin)
    usages = vim.tbl_map(function(r)
        return {
            start = { row = r.start.line, col = r.start.character },
            finish = { row = r["end"].line, col = r["end"].character },
        }
    end, vim.fn.CocAction("symbolRanges") or {})

    local cursor = vim.api.nvim_win_get_cursor(0)
    local row = cursor[1] - 1; local col = cursor[2]

    local oldignore = vim.o.eventignore
    vim.o.eventignore = "CursorMoved"

    usages = usages.result -- usages
    for idx, pos in ipairs(usages) do
        local new_position = nil
        if dir > 0 and pin == 1 then
            new_position = usages[#usages]
        elseif dir < 0 and pin == 1 then
            new_position = usages[1]
        elseif row >= pos.start.row and row <= pos.finish.row and col >= pos.start.col and col <= pos.finish.col then
            if dir < 0 and idx == 1 then
                new_position = usages[#usages]
            elseif dir > 0 and idx == #usages then
                new_position = usages[1]
            else
                new_position = usages[idx + dir]
            end
        end

        if type(new_position) == "table" then
            vim.cmd.normal({ args = { "m'" } }) -- remember pos into the jumplist
            local new_cursor = { new_position.start.row, new_position.start.col }
            vim.api.nvim_win_set_cursor(0, { new_cursor[1] + 1, new_cursor[2] })
            vim.cmd.normal({ args = { "m'" } }) -- remember pos into the jumplist
            break
        end
    end

    vim.schedule(function()
        -- optionally highight also
        vim.o.eventignore = oldignore
    end)
end

from coc.nvim.

Related Issues (20)

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.