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 Suggestion: Fallback to Telescope Builtins when Omnisharp is not active #51

Open
maxrzaw opened this issue Jan 24, 2025 · 0 comments

Comments

@maxrzaw
Copy link

maxrzaw commented Jan 24, 2025

When using the telescope handlers I ran into the problem where my normal keybindings for other LSPs were no longer working. This makes sense because they have been replaced by the ones for omnisharp_extended. I ended up solving this by checking if there was an active omnisharp lsp client in the buffer when I execute my keymap and if there is not, use the Telescope Builtin.

Would it make sense to do something like this for the telescope handlers where they fallback to the corresponding telescope builtin when omnisharp extended is not active or has no results?

local telescope_builtin = require("telescope.builtin")
local M = {}

local function is_omnisharp_active_in_buffer()
    local lsp_clients = vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() })
    for _, c in pairs(lsp_clients) do
        if c.name == "omnisharp" then
            return true
        end
    end
    return false
end

function M.lsp_definitions()
    if is_omnisharp_active_in_buffer() then
        require("omnisharp_extended").telescope_lsp_definition()
    else
        telescope_builtin.lsp_definitions()
    end
end

function M.lsp_references()
    if is_omnisharp_active_in_buffer() then
        require("omnisharp_extended").telescope_lsp_references(require("telescope.themes").get_ivy({
            excludeDefinition = true,
            show_line = false,
            initial_mode = "normal",
        }))
    else
        telescope_builtin.lsp_references()
    end
end

function M.lsp_type_definitions()
    if is_omnisharp_active_in_buffer() then
        require("omnisharp_extended").telescope_lsp_type_definition()
    else
        telescope_builtin.lsp_type_definitions()
    end
end

function M.lsp_implementations()
    if is_omnisharp_active_in_buffer() then
        require("omnisharp_extended").telescope_lsp_implementation()
    else
        telescope_builtin.lsp_implementations()
    end
end

return M

This allows me to set my keymaps cleanly like this during lsp_attach:

            local get_opts = require("mzawisa.keymap").get_opts
            local omnisharp_custom = require("mzawisa.custom.omnisharp")

            vim.keymap.set(
                "n",
                "gt",
                omnisharp_custom.lsp_type_definitions,
                get_opts("LSP: [G]o to [T]ype Definitions")
            )
            vim.keymap.set("n", "gd", omnisharp_custom.lsp_definitions, get_opts("LSP: [G]o to [D]efinitions"))
            vim.keymap.set("n", "gr", omnisharp_custom.lsp_references, get_opts("LSP: [G]o to [R]eferences"))
            vim.keymap.set("n", "gi", omnisharp_custom.lsp_implementations, get_opts("LSP: [G]o to [I]mplementations"))
maxrzaw added a commit to maxrzaw/dotfiles that referenced this issue Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant