SofusA / roslyn-language-server

A wrapper around Roslyn language server which makes compatible with editors other than VSCode
MIT License
32 stars 4 forks source link

NPE in RangeToLinePositionSpan #38

Closed milhnl closed 3 weeks ago

milhnl commented 1 month ago

Hi! I keep getting this error. It's obviously not in the Rust code, but maybe you can point me in a useful direction for debugging.

[LanguageServerHost] System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToLinePositionSpan(Range range) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 322
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 326
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.ContentChangeEventToTextChange(TextDocumentContentChangeEvent changeEvent, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 367
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.<>c__DisplayClass8_0.<GetUpdatedSourceText>b__0(TextDocumentContentChangeEvent change) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)
   at Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/Dependencies/PooledObjects/ArrayBuilder.cs:line 624
   at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable`1 source, Func`2 selector) in /_/src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs:line 356
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33
   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 187

[LanguageServerHost] System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToLinePositionSpan(Range range) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 322
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 326
   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.ContentChangeEventToTextChange(TextDocumentContentChangeEvent changeEvent, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 367
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.<>c__DisplayClass8_0.<GetUpdatedSourceText>b__0(TextDocumentContentChangeEvent change) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)
   at Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/Dependencies/PooledObjects/ArrayBuilder.cs:line 624
   at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable`1 source, Func`2 selector) in /_/src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs:line 356
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70
   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33
   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 187
   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 241
   at Microsoft.CodeAnalysis.LanguageServer.RoslynRequestExecutionQueue.WrapStartRequestTaskAsync(Task nonMutatingRequestTask, Boolean rethrowExceptions) in /_/src/LanguageServer/Protocol/RoslynRequestExecutionQueue.cs:line 40
   at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue`1.ProcessQueueCoreAsync[TRequest,TResponse](IQueueItem`1 work, IMethodHandler handler, RequestHandlerMetadata metadata, ConcurrentDictionary`2 concurrentlyExecutingTasks, CancellationTokenSource currentWorkCts, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 349
   at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue`1.InvokeProcessCoreAsync(IQueueItem`1 work, RequestHandlerMetadata metadata, IMethodHandler handler, MethodInfo methodInfo, ConcurrentDictionary`2 concurrentlyExecutingTasks, CancellationTokenSource currentWorkCts, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 302
   at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue`1.ProcessQueueAsync() in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 254

It might be the LSP plugin I'm using, but I have not seen something break like this with ranges before. It is in response to a didChange request. Do you have any ideas?

SofusA commented 1 month ago

This one is new :smile:

Are you using neovim?

milhnl commented 1 month ago

I'm using vis, with the vis-lspc plugin. Certainly possible that there's something going on there, but I haven't noticed it with any other LS, including csharp-ls.

SofusA commented 1 month ago

Ah okay. Cool.

My guess would be, that the language server is expecting a certain capability from the language client (editor), which it tries to take from a parsed list. It then throws an exception.

You could try neovim or helix to double check. For neovim you would need the change I pushed today.

milhnl commented 3 weeks ago

I'll have a look. Closing for now. Thanks! :)