Skip to content

Language server cannot find Unity csproj files with when using new vim.lsp.enable API #272

@g-371

Description

@g-371

Hi. I'm using csharp_ls for unity development.

I initially was enabling the server with the old-style
require('lspconfig').csharp_ls.setup {}

This works correctly the LSP starts and I am able to get completions with blink.cmp

However when I changed the config to
vim.lsp.enable('csharp_ls')

The LSP fails and there is the following error when i check :LspLog

[ERROR][2025-09-23 19:09:18] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"info: Initialization[0]\r\n      initializing, csharp-ls version 0.19.0.0\r\n"
[ERROR][2025-09-23 19:09:18] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"info: Initialization[0]\r\n      csharp-ls is released under MIT license and is not affiliated with Microsoft Corp.; see https://github.com/razzmatazz/csharp-language-server\r\n"
[ERROR][2025-09-23 19:09:18] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	'info: Initialization[0]\r\n      MSBuildLocator: will register ".NET Core SDK", Version=9.0.305 as default instance\r\n'
[ERROR][2025-09-23 19:09:19] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"fail: serverEventLoop[0]\r\n      serverEventLoop: crashed with System.Exception: no or .csproj/.fsproj or sln files found on D:\\unity-project-name\\Assets\\Scripts\\Input\r\n  
[ERROR][2025-09-23 19:09:19] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"fail: serverEventLoop[0]\r\n      serverEventLoop: crashed with System.Exception: no or .csproj/.fsproj or sln files found on D:\\unity-project-name\\Assets\\Scripts\\Input\r\n  
[ERROR][2025-09-23 19:09:19] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"fail: serverEventLoop[0]\r\n      serverEventLoop: crashed with System.Exception: no or .csproj/.fsproj or sln files found on D:\\unity-project-name\\Assets\\Scripts\\Input\r\n  
[ERROR][2025-09-23 19:09:19] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"fail: serverEventLoop[0]\r\n      serverEventLoop: crashed with System.Exception: no or .csproj/.fsproj or sln files found on D:\\unity-project-name\\Assets\\Scripts\\Input\r\n  
[ERROR][2025-09-23 19:09:19] ...p/_transport.lua:36	"rpc"	"csharp-ls"	"stderr"	"fail: serverEventLoop[0]\r\n      serverEventLoop: crashed with System.Exception: no or .csproj/.fsproj or sln files found on D:\\unity-project-name\\Assets\\Scripts\\Input\r\n  

I can confirm that there are in fact .csproj and sln files in the project, and like i said when configuring it the old way everything works. So suspect this has something to do with the default configs being different.

running :LspInfo in a working session produces this:

==============================================================================
vim.lsp:                                                                    ✅

- LSP log level : WARN
- Log path: C:/Users/gwen/AppData/Local/nvim-data/lsp.log
- Log size: 3490 KB

vim.lsp: Active Clients ~
- csharp_ls (id: 1)
  - Version: 0.19.0.0
  - Root directory: D:/unity-project-name
  - Command: { "C:\\Users\\gwen\\.dotnet\\tools\\csharp-ls.EXE" }
  - Settings: vim.empty_dict()
  - Attached buffers: 1

vim.lsp: Enabled Configurations ~

vim.lsp: File Watcher ~
- File watch backend: libuv-watch

vim.lsp: Position Encodings ~
- No buffers contain mixed position encodings

where as the same :LspInfo in the non-working config produces

==============================================================================
vim.lsp:                                                                    ✅

- LSP log level : WARN
- Log path: C:/Users/gwen/AppData/Local/nvim-data/lsp.log
- Log size: 3559 KB

vim.lsp: Active Clients ~
- csharp_ls (id: 1)
  - Version: 0.19.0.0
  - Root directory: D:\unity-project-name
  - Command: { "csharp-ls" }
  - Settings: {}
  - Attached buffers: 1

vim.lsp: Enabled Configurations ~
- csharp_ls:
  - capabilities: {
      textDocument = {
        completion = {
          completionItem = {
            commitCharactersSupport = false,
            deprecatedSupport = true,
            documentationFormat = { "markdown", "plaintext" },
            insertReplaceSupport = true,
            insertTextModeSupport = {
              valueSet = { 1 }
            },
            labelDetailsSupport = true,
            preselectSupport = false,
            resolveSupport = {
              properties = { "documentation", "detail", "additionalTextEdits", "command", "data" }
            },
            snippetSupport = true,
            tagSupport = {
              valueSet = { 1 }
            }
          },
          completionList = {
            itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" }
          },
          contextSupport = true,
          insertTextMode = 1
        }
      }
    }
  - cmd: { "csharp-ls" }
  - filetypes: cs
  - init_options: {
      AutomaticWorkspaceInit = true
    }
  - root_dir: <function @C:/Users/gwen/AppData/Local/nvim-data/lazy/nvim-lspconfig/lsp/csharp_ls.lua:16>

vim.lsp: File Watcher ~
- File watch backend: libuv-watch

vim.lsp: Position Encodings ~
- No buffers contain mixed position encodings

Other System Info:

  • OS: Windows 11
  • nvim v0.11.4

For now I'm just using the deprecated API but I'd love any advice on fixing it correctly.
Thanks all!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions