AstroNvim / astrocommunity

A community repository of common plugin specifications
GNU General Public License v3.0
1.04k stars 214 forks source link

Support csharpls-extended-lsp.nvim #951

Closed CharlesCreteST closed 3 weeks ago

CharlesCreteST commented 1 month ago

Is your feature related to a problem?

I would like go to definition to work properly with C#, needs https://github.com/Decodetalkers/csharpls-extended-lsp.nvim.

Doing :lua require('csharpls_extended').lsp_definitions() on a symbol makes it go to the decompiled version.

Describe the new feature

Go to definition will work for non-project code in C#.

Additional context

I have tried setting it up to override the textDocument/definition lsp_handler like so:

{
  "Decodetalkers/csharpls-extended-lsp.nvim",
  lazy = false,
  dependencies = {
    "AstroNvim/astrolsp",
    opts = {
      config = {
        csharp_ls = {
          handlers = {
            ["textDocument/definition"] = function(...)
              require("csharpls_extended").handler(...)
            end,
            ["textDocument/typeDefinition"] = function(...)
              require("csharpls_extended").handler(...)
            end,
          },
        },
      },
    },
  },
},

However this isn't working. I've also tried this with no success:

opts = function(_, opts)
  if not opts.lsp_handlers then
    opts.lsp_handlers = {}
  end
  local definition_event = "textDocument/definition"
  local definition_event_original = opts.lsp_handlers[definition_event] or vim.lsp.handlers[definition_event]
  opts.lsp_handlers[definition_event] = function(err, result, ctx, config)
    print("Definition handler")
    local client = vim.lsp.get_client_by_id(ctx.client_id)
    if client and vim.tbl_contains({
          "csharp_ls",
        }, client.name) then
      require("csharpls_extended").handler(err, result, ctx, config)
    end
    definition_event_original(err, result, ctx, config)
  end

  local type_definition_event = "textDocument/typeDefinition"
  local type_definition_event_original = opts.lsp_handlers[type_definition_event]
      or vim.lsp.handlers[type_definition_event]
  opts.lsp_handlers[type_definition_event] = function(err, result, ctx, config)
    print("TypeDefinition handler")
    local client = vim.lsp.get_client_by_id(ctx.client_id)
    if client and vim.tbl_contains({
          "csharp_ls",
        }, client.name) then
      require("csharpls_extended").handler(err, result, ctx, config)
    end
    type_definition_event_original(err, result, ctx, config)
  end
end,