mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
1.09k stars 62 forks source link

Using pick_one instead inputlist in java_generate_to_string_prompt method #460

Closed JarKz closed 1 year ago

JarKz commented 1 year ago

Problem Statement

Some peoples can use custom jdtls.ui.pick_one() method using other plugins like telescope, fzf or vim.ui.select. I use too, but one method have unmodified selection: java_generate_to_string_prompt have vim.fn.inputlist and from outside I can't customize it.

replace_to_string_prompt

Ideas or possible solutions

Replace vim.fn.inputlist() method to jdtls.ui.pick_one(). Must be no negative effects because in sources method pick_one look like inputlist. Also I checked other places for the presence of inputlist and found it in two: jdtls.lua (choice in java_generate_to_string_promt()) and ui.lua (pick_one()).

Also with custom pick_one method (modified by users) works, because method java_generate_to_string_prompt wraps by coroutine.

Code will be like:

local selection = ui.pick_one({
        "Replace",
        "Cancel",
    },
    string.format("Method 'toString()' already exists in '%s'. Do you want to replace it?", result.type),
    function(x)
        return x
    end)
if selection ~= "Replace" then
    return
end

With my telescope plugin result like:

telescope_replace_to_string_prompt

mfussenegger commented 1 year ago

Makes sense. Changed it with https://github.com/mfussenegger/nvim-jdtls/pull/461

mikehaertl commented 1 year ago

Can someone explain a bit more what is the idea here? jdtls.ui.pick_one does not use vim.ui.select. I thought the latter is like a de-facto standard for selecting from a list. Some plugins like fzf-lua even provide utilities to register their own handler for that method. But this doesn't work with nvim-jdtls.

Is this meant to be modified manually? If so, why not also use vim.ui.select in jdtls.ui.pick_one?