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

feat(cs): add csharpls-extended-lsp.nvim for better go to definition #1018

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

mehalter
Copy link
Member

Closes #951

📑 Description

This is untested because I don't have a C# environment. @Cretezy this is the correct way to set it up, it's the same way you mentioned you tried it. If it doesn't work it could just be the plugin is broken and we shouldn't add it. Could you give this a try?

ℹ Additional Information

Copy link

github-actions bot commented May 31, 2024

Review Checklist

Does this PR follow the [Contribution Guidelines](development guidelines)? Following is a partial checklist:

Proper conventional commit scoping:

  • If you are adding a new plugin, the scope would be the name of the category it is being added into. ex. feat(utility): added noice.nvim plugin

  • If you are modifying a pre-existing plugin or pack, the scope would be the name of the plugin folder. ex. fix(noice-nvim): fix LSP handler error

  • Pull request title has the appropriate conventional commit type and scope where the scope is the name of the pre-existing directory in the project as described above

  • README is properly formatted and uses fenced in links with <url> unless they are inside a [title](url)

  • Proper usage of opts table rather than setting things up with the config function.

@Uzaaft
Copy link
Member

Uzaaft commented May 31, 2024

testing this since I have a working dotnet env on my pc

@Cretezy
Copy link
Contributor

Cretezy commented May 31, 2024

I'm not going to be doing C# until next Tuesday, I can test and review then

@Uzaaft
Copy link
Member

Uzaaft commented May 31, 2024

Didnt work for me, the LSP in the pack is broken for Mac🥹

@ahmtsen
Copy link
Contributor

ahmtsen commented Jun 6, 2024

I think the problem is caused by telescope as mentioned here Decodetalkers/csharpls-extended-lsp.nvim#7. Maybe overriding gd to use vim.lsp.buf.definition() instead of telescope methods will solve the problem.

@ahmtsen
Copy link
Contributor

ahmtsen commented Jun 9, 2024

I think the problem is caused by telescope as mentioned here Decodetalkers/csharpls-extended-lsp.nvim#7. Maybe overriding gd to use vim.lsp.buf.definition() instead of telescope methods will solve the problem.

The following configuration works for me. The fix is to override gd to use vim.lsp.buf.definition.

  {
    "Decodetalkers/csharpls-extended-lsp.nvim",
    dependencies = {
      {
        "AstroNvim/astrolsp",
        opts = {
          config = {
            csharp_ls = {
              handlers = {
                ["textDocument/definition"] = function(...) require("csharpls_extended").handler(...) end,
                ["textDocument/typeDefinition"] = function(...) require("csharpls_extended").handler(...) end,
              },
            },
          },
          on_attach = function(client, bufnr)
            if client.name ~= "csharp_ls" then return end

            vim.keymap.set(
              "n",
              "gd",
              vim.lsp.buf.definition,
              { buffer = bufnr, noremap = true, silent = true, desc = "Go to definition" }
            )
          end,
        },
      },
    },
  },

@mehalter
Copy link
Member Author

Thanks for pointing this out @ahmtsen ! I am going to be removing the telescope LSP mappings in the next patch release of AstroNvim because apparently there are many problems with them. Also thanks for the workaround! Once the next release is made I'll go ahead and merge this in.

Also sidenote, you know you can also add on_attach functions to the config of language servers themselves to add settings for specific language servers. Rather than checking the client.name you can do something like this:

{
  "Decodetalkers/csharpls-extended-lsp.nvim",
  dependencies = {
    {
      "AstroNvim/astrolsp",
      opts = {
        config = {
          csharp_ls = {
            handlers = {
              ["textDocument/definition"] = function(...) require("csharpls_extended").handler(...) end,
              ["textDocument/typeDefinition"] = function(...) require("csharpls_extended").handler(...) end,
            },
            on_attach = function(_, bufnr)
              vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = bufnr, desc = "Go to definition" })
            end,
          },
        },
      },
    },
  },
},

@mehalter
Copy link
Member Author

This should work as intended now that AstroNvim v4.10.2 is released that doesn't use Telescope for LSP mappings out of the box.

@mehalter mehalter merged commit 2dd5c26 into main Jun 11, 2024
13 checks passed
@mehalter mehalter deleted the feat/csharpls_extended_lsp branch June 11, 2024 13:23
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

Successfully merging this pull request may close these issues.

Support csharpls-extended-lsp.nvim
4 participants