Skip to content

Unable to rename and reference variables passed to a method that is roslyn source generated. #169

@Efaideleon

Description

@Efaideleon

Hi, I'm using the plugin for Unity Dots. A lot of the code there is source generated.
Whenever I try to rename a variable that is passed to one of the methods that is source generated,
I get the following error: (using vim.lsp.buf.rename)

[ERROR][2025-03-14 11:22:03] ...lsp/handlers.lua:623	
"[LanguageServerHost] System.InvalidOperationException: Unexpected null - file ConflictResolver.cs line 292\n   
at Microsoft.CodeAnalysis.Contract.Fail(String message, Int32 lineNumber, String filePath) in /_/src/Dependencies/Contracts/Contract.cs:line 159\n   
at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.AddDeclarationConflictsAsync(ISymbol renamedSymbol, ISymbol renameSymbol, IEnumerable`1 referencedSymbols, MutableConflictResolution conflictResolution, IDictionary`2 reverseMappedLocations, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.cs:line 292\n
at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.Session.IdentifyConflictsAsync(HashSet`1 documentIdsForConflictResolution, IEnumerable`1 allDocumentIdsInProject, ProjectId projectId, MutableConflictResolution conflictResolution, ImmutableHashSet`1 conflictLocations) in /_/src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.Session.cs:line 456\n
at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.Session.ResolveConflictsAsync() in /_/src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.Session.cs:line 145\n   
at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.ResolveSymbolicLocationConflictsInCurrentProcessAsync(SymbolicRenameLocations renameLocations, String replacementText, ImmutableArray`1 nonConflictSymbolKeys, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.cs:line 107\n
at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.ResolveLightweightConflictsAsync(ISymbol symbol, LightweightRenameLocations lightweightRenameLocations, String replacementText, ImmutableArray`1 nonConflictSymbolKeys, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.cs:line 85\n
at Microsoft.CodeAnalysis.LanguageServer.Handler.RenameHandler.GetRenameEditAsync(Document document, LinePosition linePosition, String newName, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/Rename/RenameHandler.cs:line 56\n
at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 191"

Also when I use the LSP to look up references (using vim.lsp.buf.references) for a variable passed to a method that is source generated I get the following error:

Error executing vim.schedule lua callback: BufReadCmd Autocommands for "roslyn-source-generated://*": Vim(append):Error executi
ng vim.schedule lua callback: ...on/.local/share/nvim/lazy/roslyn.nvim/lua/roslyn/lsp.lua:142: Vim:Error executing vim.schedule
 lua callback: ...vim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/handlers.lua:16: Vim:roslyn: -32000: Syntax tree doesn't belong t
o the underlying 'Compilation'. (Parameter 'model')
stack traceback:
        [C]: in function 'nvim_command'
        ...vim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/handlers.lua:16: in function 'err_message'
        ...vim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/handlers.lua:732: in function 'handler'
        ...eovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
        [C]: in function 'wait'
        ...on/.local/share/nvim/lazy/roslyn.nvim/lua/roslyn/lsp.lua:159: in function <...on/.local/share/nvim/lazy/roslyn.nvim/
lua/roslyn/lsp.lua:122>
        [C]: in function 'bufload'
        .../neovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/util.lua:276: in function 'get_lines'
        .../neovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/util.lua:1913: in function 'locations_to_items'
        ...vim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/handlers.lua:254: in function 'handler'
        ...eovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'nvim_buf_set_lines'
        ...on/.local/share/nvim/lazy/roslyn.nvim/lua/roslyn/lsp.lua:142: in function 'handler'
        ...eovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
        [C]: in function 'wait'
        ...on/.local/share/nvim/lazy/roslyn.nvim/lua/roslyn/lsp.lua:159: in function <...on/.local/share/nvim/lazy/roslyn.nvim/
lua/roslyn/lsp.lua:122>
        [C]: in function 'bufload'
        .../neovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/util.lua:276: in function 'get_lines'
        .../neovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/util.lua:1913: in function 'locations_to_items'
        ...vim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/handlers.lua:254: in function 'handler'
        ...eovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'bufload'
        .../neovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/util.lua:276: in function 'get_lines'
        .../neovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/util.lua:1913: in function 'locations_to_items'
        ...vim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/handlers.lua:254: in function 'handler'
        ...eovim/0.10.4_1/share/nvim/runtime/lua/vim/lsp/client.lua:687: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I'm using neovim 0.10.4 but the error also happens in neovim nightly.
I also tried both Microsoft.CodeAnalysis.LanguageServer v4 and v5 and .Net SDK 6, 7, 8, 9, and 10 preview and the error still happens.

I always make sure to save all the buffers and do domain reloading in Unity but I keep getting the same errors.

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