jmederosalvarado / roslyn.nvim

Roslyn LSP plugin for neovim
MIT License
203 stars 38 forks source link

Roslyn initialized but not working #19

Closed marvindore closed 9 months ago

marvindore commented 9 months ago

Hello thank you for taking the time to make this plugin. I have made progress installing the plugin but can’t seem to get any of the LSP functionality to work. Here are my steps and observations:

  1. I am running
  1. I installed the language sever using the :CSInstallRoslyn command which completed successful.
  2. My config file is as follows:
    require(“roslyn”).setup({
    on_attach = function()
    vim.keymap.set("n", "gd", vim.lsp.buf.definition, {buffer=0})
    end,
    capabilities = require(‘lsp-status’).capabilities
    }

    end

  3. When I open a C# project that has a .sln file at the root I get the following messages: Roslyn client initialized for target test.sln Roslyn project initialization complete.

When I type :LspInfo it says:

1 client(s) attached to this buffer:
Client: roslyn (id: 1, bufnr: [4]) 
filetypes: 
autostart: false
root directory: /home/tester/test
cmd: <function>
Configured servers list: lua_ls, jsonls, pyright, tsserver 

But there are no diagnostics, and goto definition is not working.

Edit: I also notice in init.lua the callback in M.setup_autocmds() is not firing. I added this print statement but it never executed:

function M.setup_autocmds()
    local lsp_group = vim.api.nvim_create_augroup("Roslyn", { clear = true })
    vim.api.nvim_create_autocmd("FileType", {
        pattern = { "cs" },
        callback = function(opt)
      print("init line 149 opt.buf ", opt.buf)
            M.init_buf_targets(opt.buf)
            M.attach_or_spawn(opt.buf)
        end,
        group = lsp_group,
        desc = "",
    })
end
[START][2023-12-11 23:50:50] LSP logging initiated
[DEBUG][2023-12-11 23:50:50] ...a/roslyn/lsp.lua:258    "rpc.send"  {  jsonrpc = "2.0",  method = "textDocument/didClose",  params = {    textDocument = {      uri = "file:///home/testuser/playground/itsSeven/Program.cs"    }  }}
[DEBUG][2023-12-11 23:51:08] ...a/roslyn/lsp.lua:258    "rpc.send"  {  jsonrpc = "2.0",  method = "textDocument/didOpen",  params = {    textDocument = {      languageId = "cs",      text = '// See https://aka.ms/new-console-template for more information\r\nConsole.WriteLine("Hello, World!");\r\n\r\nConsole.WriteLine("Hello again")\r\n\r\nSystem fd\r\nNow it seem like I got no diagnostics. test\r\n',      uri = "file:///home/testuser/playground/itsSeven/Program.cs",      version = 0    }  }}
[DEBUG][2023-12-11 23:51:11] .../lua/vim/lsp.lua:1507   "LSP[roslyn]"   "client.request"    1   "textDocument/diagnostic"   {  range = {    ["end"] = {      character = 0,      line = 7    },    start = {      character = 0,      line = 0    }  },  textDocument = {    uri = "file:///home/testuser/playground/itsSeven/Program.cs"  }}   <function 1>    1
[DEBUG][2023-12-11 23:51:11] ...a/roslyn/lsp.lua:258    "rpc.send"  {  id = 4,  jsonrpc = "2.0",  method = "textDocument/diagnostic",  params = {    range = {      ["end"] = {        character = 0,        line = 7      },      start = {        character = 0,        line = 0      }    },    textDocument = {      uri = "file:///home/testuser/playground/itsSeven/Program.cs"    }  }}
[DEBUG][2023-12-11 23:51:11] ...a/roslyn/lsp.lua:361    "rpc.receive"   {  id = 4,  jsonrpc = "2.0",  result = {    items = {},    kind = "full",    resultId = "PublicDocumentPullDiagnosticsHandler(category: , source: ):1"  }}
[TRACE][2023-12-11 23:51:11] ...lsp/handlers.lua:636    "default_handler"   "textDocument/diagnostic"   {  ctx = '{\n  bufnr = 1,\n  client_id = 1,\n  method = "textDocument/diagnostic",\n  params = {\n    range = {\n      ["end"] = {\n        character = 0,\n        line = 7\n      },\n      start = {\n        character = 0,\n        line = 0\n      }\n    },\n    textDocument = {\n      uri = "file:///home/testuser/playground/itsSeven/Program.cs"\n    }\n  },\n  version = 0\n}',  result = {    items = {},    kind = "full",    resultId = "PublicDocumentPullDiagnosticsHandler(category: , source: ):1"  }}
marvindore commented 9 months ago

Resolved, I got some assistance from @nilsgehlin where in his dotfiles I noticed I was not setting up capabilities correctly. I changed my capabilities to: local capabilies = vim.tbl_deep_extend("force", vim.lsp.protocol.make_client_capabilities(), require('cmp_nvim_lsp').default_capabilities() ) and it started to work.

marvindore commented 9 months ago

Weird turn of events from the weekend. I decided to reorganize all my plugins using the plugins folder like Lazy nvim suggests. I created a file for mason where I setup lsps and another for nvim-cmp. This change broke roslyn.nvim for me again. I suspected it had something to do with the capabilities again, maybe the way lazy vim loads Mason and nvm-cmp the ordering was wrong. As I was debugging I set capabilities to nil and everything started working again. I'm not sure if this is correct? but now my setup looks like this:

require("roslyn").setup({
   on_attach = _G.on_attach(lsp),
   capabilities = nil,
 })

DotFiles