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

Support csharpls-extended-lsp.nvim #951

Closed
CharlesCreteST opened this issue May 9, 2024 · 0 comments · Fixed by #1018
Closed

Support csharpls-extended-lsp.nvim #951

CharlesCreteST opened this issue May 9, 2024 · 0 comments · Fixed by #1018
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@CharlesCreteST
Copy link
Contributor

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,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants