Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add option jump_to_single_result to lsp picker #978

Closed
2 tasks done
abeldekat opened this issue Jun 19, 2024 · 3 comments
Closed
2 tasks done

Feature: add option jump_to_single_result to lsp picker #978

abeldekat opened this issue Jun 19, 2024 · 3 comments
Labels
feature-request Request for a feature to existing module mini.extra mini.pick

Comments

@abeldekat
Copy link

Contributing guidelines

Module(s)

mini.pick, mini.extra

Description

Recently I started using mini.pick in my config. Thank you for this great plugin!

Regarding the lsp picker, I miss the ability to jump directly to a single result, bypassing the picker.
This is standard behavior in telescope, and can be configured in fzf-lua by supplying jump_to_single_result is true.

I frequently use goto definition. For now, fzf-lua provides the following lsp pickers in my config: "definition", "reference", "implementation", "type_definition".

Would it be possible to add this behavior to mini.pick?

@abeldekat abeldekat added the feature-request Request for a feature to existing module label Jun 19, 2024
@echasnovski
Copy link
Owner

Thanks for the suggestion!

This is, of course, possible. However, I don't think this is a good idea. My reasoning is that starting a picker should always result into showing a picker (as stated in #809 with a bit more thoughts in this comment).

Closing as not planned.

@abeldekat
Copy link
Author

Oops... I was just writing an apology for this duplicate issue...)

@metafates
Copy link

I've stumbled upon the same problem and implemented this function that does just that =) Hope it helps

-- Open LSP picker for the given scope
---@param scope "declaration" | "definition" | "document_symbol" | "implementation" | "references" | "type_definition" | "workspace_symbol"
---@param autojump boolean? If there is only one result it will jump to it.
function M.picker(scope, autojump)
	---@return string
	local function get_symbol_query()
		return vim.fn.input("Symbol: ")
	end

	if not autojump then
		local opts = { scope = scope }

		if scope == "workspace_symbol" then
			opts.symbol_query = get_symbol_query()
		end

		require("mini.extra").pickers.lsp(opts)
		return
	end

	---@param opts vim.lsp.LocationOpts.OnList
	local function on_list(opts)
		vim.fn.setqflist({}, " ", opts)

		if #opts.items == 1 then
			vim.cmd.cfirst()
		else
			require("mini.extra").pickers.list({ scope = "quickfix" }, { source = { name = opts.title } })
		end
	end

	if scope == "references" then
		vim.lsp.buf.references(nil, { on_list = on_list })
		return
	end

	if scope == "workspace_symbol" then
		vim.lsp.buf.workspace_symbol(get_symbol_query(), { on_list = on_list })
		return
	end

	vim.lsp.buf[scope]({ on_list = on_list })
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.extra mini.pick
Projects
None yet
Development

No branches or pull requests

3 participants