tris203 / rzls.nvim

Hopefully, support for rzls in neovim
MIT License
49 stars 4 forks source link

Need help setting this up on Windows #14

Open kmoschcau opened 2 hours ago

kmoschcau commented 2 hours ago

Hi, I cloned and compiled dotnet/razor with dotnet build .\Razor.sln. Both .\build.ps1 and .\build.cmd give me errors. The build results in an artifacts\bin\rzls\Debug\net8.0\rzls.dll. When I use that as a path with rzls.nvim, I get this lsp.log entry:

[ERROR][2024-11-05 08:37:13] .../vim/lsp/rpc.lua:764    "rpc"   "C:/Users/KaiMoschcau/Code/razor/artifacts/bin/rzls/Debug/net8.0/rzls.dll"  "stderr"    "\nUnhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.\n"

I also tried manually to run the DLL like so: dotnet rzls.dll That at least does not produce any errors and just keeps running until terminate it with Ctrl-C.

I also tried to set path to just C:/Users/KaiMoschcau/Code/razor/artifacts/bin/rzls/Debug/net8.0/, which results in a warning notification, that the language server is not installed.

Lastly I also tried to write a pwsh wrapper script, which just does dotnet "$HOME\Code\razor\artifacts\bin\rzls\Debug\net8.0\rzls.dll". That gives me the following notification:

...gram Files/Neovim/share/nvim/runtime/lua/vim/lsp/rpc.lua:794: Spawning language server with cmd: `{ "C:/Users/KaiMoschcau/bin/rzls.ps1", "--logLevel", "0", "--DelegateToCSharpOnDiagnosticsPublish", "true", "--UpdateBuffersForClosedDocuments", "true" }` failed with error message: ...gram Files\Neovim\share\nvim\runtime/lua/vim/_system.lua:244: EFTYPE: inappropriate file type or format

Any help would be appreciated.

tris203 commented 2 hours ago

Do you use Mason normally for LSP installs?

kmoschcau commented 1 hour ago

I do, but there is no Mason install for rzls yet as far as I know.

tris203 commented 1 hour ago
        registries = {
          'github:mason-org/mason-registry',
          'github:Crashdummyy/mason-registry',
        }

Pass this to your mason setup and you should be able to install rzls and Roslyn via mason

tris203 commented 1 hour ago

Ps, this is all experimental at the moment. So it isn't documented yet

I also haven't done any testing on windows so there might be some more to do

kmoschcau commented 45 minutes ago

OK I was able to install it and it seems to start when I open a .razor file with it. Then I get this message:

[REDACTED]/Components/App.razor__virtual.cs
Error executing vim.schedule lua callback: ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:40: Failed to rename buffer
stack traceback:
        [C]: in function 'nvim_buf_set_name'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:40: in function 'get_or_create_buffer_for_filepath'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:60: in function 'register_vbufs_by_path'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:76: in function 'update_vbuf'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/handlers/init.lua:41: in function 'handler'
        ...m Files/Neovim/share/nvim/runtime/lua/vim/lsp/client.lua:998: in function 'fn'
        vim/_editor.lua:359: in function <vim/_editor.lua:358>

I get this twice for every razor file in the project as far as I can tell. Opening these files in the background also triggers diagnostic checks from none-ls on each file, which slows things down a bit.

I then get a bunch of other messages, some looking like they are for debugging.

Triggering completion after an @ gives:

nil
LSP[rzls]: Error SERVER_REQUEST_HANDLER_ERROR: "...vim-data/lazy/rzls.nvim/lua/rzls/handlers/completion.lua:15: No virtual document found"

Triggering hover gives:

Error executing vim.schedule lua callback: ...im-data/lazy/rzls.nvim/lua/rzls/clienthandlers/hover.lua:33: assertion failed!
stack traceback:
        [C]: in function 'assert'
        ...im-data/lazy/rzls.nvim/lua/rzls/clienthandlers/hover.lua:33: in function 'handler'
        ...m Files/Neovim/share/nvim/runtime/lua/vim/lsp/client.lua:681: in function 'fn'
        vim/_editor.lua:359: in function <vim/_editor.lua:358>

And editing the buffer in any way gives:

[REDACTED]/Components/Pages/LandingPage.razor__virtual.cs
Error executing vim.schedule lua callback: ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:40: Failed to rename buffer
stack traceback:
        [C]: in function 'nvim_buf_set_name'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:40: in function 'get_or_create_buffer_for_filepath'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:60: in function 'register_vbufs_by_path'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:76: in function 'update_vbuf'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/handlers/init.lua:41: in function 'handler'
        ...m Files/Neovim/share/nvim/runtime/lua/vim/lsp/client.lua:998: in function 'fn'
        vim/_editor.lua:359: in function <vim/_editor.lua:358>
kmoschcau commented 44 minutes ago

Oh and writing the buffer gives:

file modified:[REDACTED]\Components\Pages\LandingPage.razor
Error executing luv callback:
...l/nvim-data/lazy/rzls.nvim/lua/rzls/virtual_document.lua:19: E5560: Vimscript function must not be called in a lua loop callback
stack traceback:
        [C]: in function 'uri_to_bufnr'
        ...l/nvim-data/lazy/rzls.nvim/lua/rzls/virtual_document.lua:19: in function 'new'
        ...ocal/nvim-data/lazy/rzls.nvim/lua/rzls/documentstore.lua:56: in function 'register_vbufs_by_path'
        ...AppData/Local/nvim-data/lazy/rzls.nvim/lua/rzls/init.lua:172: in function <...AppData/Local/nvim-data/lazy/rzls.nvim/lua/rzls/init.lua:168>
tris203 commented 40 minutes ago

Can you run :checkheath rzls

kmoschcau commented 38 minutes ago

Sure, that gives me:

rzls:                                           require("rzls.health").check()

rzls.nvim report ~
- ERROR roslyn pipe not connected
tris203 commented 29 minutes ago

So you have no documentstore, and its not connecting to roslyn

Can you share your config for roslyn.nvim and rzls.nvim

kmoschcau commented 24 minutes ago

Sure. Here's roslyn:

--- @param client vim.lsp.Client the LSP client
local function monkey_patch_semantic_tokens(client)
  -- NOTE: Super hacky... Don't know if I like that we set a random variable on
  -- the client Seems to work though ~seblj
  if client.is_hacked then
    return
  end
  client.is_hacked = true

  -- let the runtime know the server can do semanticTokens/full now
  client.server_capabilities =
    vim.tbl_deep_extend("force", client.server_capabilities, {
      semanticTokensProvider = {
        full = true,
      },
    })

  -- monkey patch the request proxy
  local request_inner = client.request
  client.request = function(method, params, handler, req_bufnr)
    if method ~= vim.lsp.protocol.Methods.textDocument_semanticTokens_full then
      return request_inner(method, params, handler)
    end

    local target_bufnr = vim.uri_to_bufnr(params.textDocument.uri)
    local line_count = vim.api.nvim_buf_line_count(target_bufnr)
    local last_line = vim.api.nvim_buf_get_lines(
      target_bufnr,
      line_count - 1,
      line_count,
      true
    )[1]

    return request_inner("textDocument/semanticTokens/range", {
      textDocument = params.textDocument,
      range = {
        ["start"] = {
          line = 0,
          character = 0,
        },
        ["end"] = {
          line = line_count - 1,
          character = string.len(last_line) - 1,
        },
      },
    }, handler, req_bufnr)
  end
end

require("roslyn").setup {
  config = {
    capabilities = require("lsp.common").capabilities,
    handlers = require "rzls.roslyn_handlers",
    on_attach = function(client, bufnr)
      require "lsp.attach"(client, bufnr)

      monkey_patch_semantic_tokens(client)
    end,
  },
}

And here's rzls:

require("rzls").setup {
  capabilities = require("lsp.common").capabilities,
  on_attach = require "lsp.attach",
  path = "rzls.cmd",
}
tris203 commented 16 minutes ago
  1. you shouldnt need a path field to the rzls set up with a mason installation, it should be detected automatically.

  2. If you run :LspInfo or :checkhealth lsp can you see you should see rzls and roslyn running