seblj / roslyn.nvim

Roslyn LSP plugin for neovim
MIT License
225 stars 22 forks source link

"Roslyn server stopped" when the file doesn't have a new line at EOF #27

Open tuliopaim opened 3 months ago

tuliopaim commented 3 months ago

In the company where I work, they have this weird lint rule of not allowing any file to have an empty line at the end of the file.

Every time I go to the end of the file and add a new line, the LSP server crashes, and as :LspRestart doesn't work, I have to quit and re-open neovim.

To reproduce:

Stopping roslyn process Roslyn server stopped

seblj commented 3 months ago

I can't reproduce. What is the log from the server? :LspLog

tuliopaim commented 3 months ago

I can't reproduce. What is the log from the server? :LspLog

Ok, I tried to reproduce it in a personal project just by removing the last line, but I couldn't. So I created this .editorconfig file in the root of the project:

root = true

[*.cs]

# New line preferences
insert_final_newline = false

Then after running the dotnet format command, you can then see in the git diff:

image

The LspLog:

[ERROR][2024-08-02 12:00:53] ...lsp/handlers.lua:623    "[LanguageServerHost] System.ArgumentException: Range={ Start={ Line=11, Character=1 }, End={ Line=12, Character=0 } }. text.Length=209. text.Lines.Count=12\n ---> System.ArgumentOutOfRangeException: The requested line number 12 must be less than the number of lines 12. (Parameter 'Line')\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 330\n   --- End of inner exception stack trace ---\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 335\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.ContentChangeEventToTextChange(TextDocumentContentChangeEvent changeEvent, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 365\n   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()\n   at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)\n   at Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/Dependencies/PooledObjects/ArrayBuilder.cs:line 624\n   at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable`1 source, Func`2 selector) in /_/src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs:line 355\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33\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 187"
[ERROR][2024-08-02 12:00:53] ...lsp/handlers.lua:623    "[LanguageServerHost] System.ArgumentException: Range={ Start={ Line=11, Character=1 }, End={ Line=12, Character=0 } }. text.Length=209. text.Lines.Count=12\n ---> System.ArgumentOutOfRangeException: The requested line number 12 must be less than the number of lines 12. (Parameter 'Line')\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 330\n   --- End of inner exception stack trace ---\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 335\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.ContentChangeEventToTextChange(TextDocumentContentChangeEvent changeEvent, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 365\n   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()\n   at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)\n   at Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/Dependencies/PooledObjects/ArrayBuilder.cs:line 624\n   at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable`1 source, Func`2 selector) in /_/src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs:line 355\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33\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 187\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 241\n   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\n   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\n   at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue`1.ProcessQueueAsync() in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 254"
tuliopaim commented 3 months ago

@seblj I found out about this fork yesterday, thanks a lot for it.

One other issue, I'm using the latest LanguageServer version, and the diagnostics are not showing, should I open another issue? What version should I use?

$ dotnet Microsoft.CodeAnalysis.LanguageServer.dll --version
4.12.0-2.24401.2+eafb7892671c3917bc1c060c185211740eeb55ce

Saw this error in LspLog:

[ERROR][2024-08-02 12:08:39] ...lsp/handlers.lua:623    "[LanguageServerProjectSystem] Error while loading /home/tuliopaim/dev/tb/ems/AM-13809-scheduled-lambda/src/WebApi/WebAPI.csproj: Exception thrown: StreamJsonRpc.RemoteMethodNotFoundException: MethodNotFound\n   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.RazorDynamicFileInfoProvider.GetDynamicFileInfoAsync(ProjectId projectId, String projectFilePath, String filePath, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs:line 63\n   at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs:line 56\n   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.AddDynamicSourceFile(String dynamicFilePath, ImmutableArray`1 folders) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 826\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.<>c__DisplayClass15_0.<UpdateWithNewProjectInfoAsync>g__UpdateProjectSystemProjectCollection|16[T](IEnumerable`1 loadedCollection, IEnumerable`1 oldLoadedCollection, IEqualityComparer`1 comparer, Action`1 addItem, Action`1 removeItem, String logMessage) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 215\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo, ILogger logger) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 179\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo, ILogger logger) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 196\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, ToastErrorReporter toastErrorReporter, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 284"
seblj commented 3 months ago

Okay I was able to reproduce with the .editorconfig, so I can look into that. Cannot reproduce no diagnostics with the newest server. Make sure you actually make some edits in the buffer first. The diagnostics does not appear before this: https://github.com/seblj/roslyn.nvim/issues/13

seblj commented 3 months ago

This is probably a bug in neovim as I cannot reproduce this in vscode, and this plugin is mostly just a thin wrapper to be able to start the server (and a couple of extra handlers implemented). It looks like neovim is sending a didChange request with a range that causes the server to crash. It would probably help to debug what vscode is sending as a request. However, I tried to figure out a way to debug that a while ago, and I had no idea how to get the logs from vscode.

It might also be that neovim is behaving correctly (I am not sure), and the server just not adhering to the LSP spec. Wouldn't be the first time if so.

tuliopaim commented 3 months ago

This is probably a bug in neovim as I cannot reproduce this in vscode, and this plugin is mostly just a thin wrapper to be able to start the server (and a couple of extra handlers implemented). It looks like neovim is sending a didChange request with a range that causes the server to crash. It would probably help to debug what vscode is sending as a request. However, I tried to figure out a way to debug that a while ago, and I had no idea how to get the logs from vscode.

It might also be that neovim is behaving correctly (I am not sure), and the server just not adhering to the LSP spec. Wouldn't be the first time if so.

Got it, I imagined that this was not an issue with this plugin... thanks for the investigation anyways.

Would be good if the :LspRestart worked tho.

seblj commented 3 months ago

Yeah I agree, but I think that only works with language servers setup via nvim-lspconfig...

I think we can just leave this issue open if it's okay for you? Then I can potentially investigate it more if I get time at some point, and then potentially at least raise an issue where it belongs. Or maybe someone else notices the same thing, and they can easily see it, and maybe help if they want

tuliopaim commented 3 months ago

@seblj sure, I'd appreciate that.

About that other error:

https://github.com/user-attachments/assets/333ad926-17c8-46ed-a4b9-f5dcce4bd502

[ERROR][2024-08-02 13:08:40] ...lsp/handlers.lua:623    "[LanguageServerProjectSystem] Error while loading /home/tuliopaim/dev/personal/TradingChat/main/src/TradingChat.WebApp/TradingChat.WebApp.csproj: Exception thrown: StreamJsonRpc.RemoteMethodNotFoundException: MethodNotFound\n   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.RazorDynamicFileInfoProvider.GetDynamicFileInfoAsync(ProjectId projectId, String projectFilePath, String filePath, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/RazorDynamicFileInfoProvider.cs:line 63\n   at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task, CancellationToken cancellationToken) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs:line 56\n   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.AddDynamicSourceFile(String dynamicFilePath, ImmutableArray`1 folders) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 826\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.<>c__DisplayClass15_0.<UpdateWithNewProjectInfoAsync>g__UpdateProjectSystemProjectCollection|16[T](IEnumerable`1 loadedCollection, IEnumerable`1 oldLoadedCollection, IEqualityComparer`1 comparer, Action`1 addItem, Action`1 removeItem, String logMessage) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 215\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo, ILogger logger) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 179\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo, ILogger logger) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 196\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, ToastErrorReporter toastErrorReporter, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 284"
[ERROR][2024-08-02 13:08:54] ...lsp/handlers.lua:623    "[LanguageServerProjectSystem] Error while loading /home/tuliopaim/dev/personal/TradingChat/main/src/TradingChat.WebApp/TradingChat.WebApp.csproj: Exception thrown: System.InvalidOperationException: We haven't been given a loaded project yet, so we can't provide the existing TFM. - file LoadedProject.cs line 69\n   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber, String filePath) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 157\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.GetTargetFramework() in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 69\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.<>c__DisplayClass19_1.<LoadOrReloadProjectAsync>b__3(LoadedProject p) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 256\n   at System.Collections.Generic.List`1.Find(Predicate`1 match)\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, ToastErrorReporter toastErrorReporter, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 256"
[ERROR][2024-08-02 13:09:00] ...lsp/handlers.lua:623    "[LanguageServerProjectSystem] Error while loading /home/tuliopaim/dev/personal/TradingChat/main/src/TradingChat.WebApp/TradingChat.WebApp.csproj: Exception thrown: System.InvalidOperationException: We haven't been given a loaded project yet, so we can't provide the existing TFM. - file LoadedProject.cs line 69\n   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber, String filePath) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 157\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.GetTargetFramework() in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 69\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.<>c__DisplayClass19_1.<LoadOrReloadProjectAsync>b__3(LoadedProject p) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 256\n   at System.Collections.Generic.List`1.Find(Predicate`1 match)\n   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, ToastErrorReporter toastErrorReporter, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 256"
seblj commented 3 months ago

Hmm, that is weird because it works in my projects at work🤔 it looks like the project is public, so I can have a look at testing it with that project. Could you could open another issue, attach the video and the output of the entire lsp log?

tuliopaim commented 3 months ago

Hmm, that is weird because it works in my projects at work🤔 it looks like the project is public, so I can have a look at testing it with that project. Could you could open another issue, attach the video and the output of the entire lsp log?

Sure, Ill do it in a sec, but that's happening for all my projects, not just that one.

Just to be sure I'm not doing something completely stupid, that's all I did when moving from the other repo to this fork (+ upgrading to the latest CodeAnalysis.LanguageServer):

image

I'll also try to downgrade the CodeAnalysis.LanguageServer version.

seblj commented 3 months ago

Ahaaaaa, I know what is wrong... To fix this in no time for you, you can just remove capabilities from the setup. I am already setting capabilities with cmp correctly, so no need to pass them in.

However, this really is a bug in my plugin though. No need to create a new issue if you haven't already. I will fix this right away.

UPDATE: Fixed in the latest commit

tuliopaim commented 3 months ago

@seblj Thanks a lot man, now everything is perfect! Keep it up with the good work!

kmoschcau commented 3 weeks ago

Hi, I am also experiencing the server crashing when adding an empty line to the end of the file. This happens with server version 4.13.0-2.24554.8. Here are the relevant LSP logs:

[ERROR][2024-11-05 10:24:18] ...lsp/handlers.lua:590    "[LanguageServerHost] System.ArgumentException: Range={ Start={ Line=22, Character=1 }, End={ Line=23, Character=0 } }. text.Length=872. text.Lines.Count=23\r\n ---> System.ArgumentOutOfRangeException: The requested line number 23 must be less than the number of lines 23. (Parameter 'Line')\r\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67\r\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78\r\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 306\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 311\r\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.ContentChangeEventToTextChange(TextDocumentContentChangeEvent changeEvent, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 341\r\n   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()\r\n   at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)\r\n   at Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/Dependencies/PooledObjects/ArrayBuilder.cs:line 624\r\n   at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable`1 source, Func`2 selector) in /_/src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs:line 356\r\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70\r\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33\r\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"
[ERROR][2024-11-05 10:24:18] ...lsp/handlers.lua:590    "[LanguageServerHost] System.ArgumentException: Range={ Start={ Line=22, Character=1 }, End={ Line=23, Character=0 } }. text.Length=872. text.Lines.Count=23\r\n ---> System.ArgumentOutOfRangeException: The requested line number 23 must be less than the number of lines 23. (Parameter 'Line')\r\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetPosition(LinePosition position) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 67\r\n   at Microsoft.CodeAnalysis.Text.TextLineCollection.GetTextSpan(LinePositionSpan span) in /_/src/Compilers/Core/Portable/Text/TextLineCollection.cs:line 78\r\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 306\r\n   --- End of inner exception stack trace ---\r\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.RangeToTextSpan(Range range, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 311\r\n   at Microsoft.CodeAnalysis.LanguageServer.ProtocolConversions.ContentChangeEventToTextChange(TextDocumentContentChangeEvent changeEvent, SourceText text) in /_/src/LanguageServer/Protocol/Extensions/ProtocolConversions.cs:line 341\r\n   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()\r\n   at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)\r\n   at Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/Dependencies/PooledObjects/ArrayBuilder.cs:line 624\r\n   at Roslyn.Utilities.EnumerableExtensions.SelectAsArray[TSource,TResult](IEnumerable`1 source, Func`2 selector) in /_/src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs:line 356\r\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.GetUpdatedSourceText(TextDocumentContentChangeEvent[] contentChanges, SourceText text) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 70\r\n   at Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges.DidChangeHandler.HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/DocumentChanges/DidChangeHandler.cs:line 33\r\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\r\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 245\r\n   at Microsoft.CodeAnalysis.LanguageServer.RoslynRequestExecutionQueue.WrapStartRequestTaskAsync(Task nonMutatingRequestTask, Boolean rethrowExceptions) in /_/src/LanguageServer/Protocol/RoslynRequestExecutionQueue.cs:line 40\r\n   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 367\r\n   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 320\r\n   at Microsoft.CommonLanguageServerProtocol.Framework.RequestExecutionQueue`1.ProcessQueueAsync() in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/RequestExecutionQueue.cs:line 272"
seblj commented 3 weeks ago

Haven't had any time/prioritized to look into this yet as there is nothing I can do in this repo. The issue must be in either neovim or roslyn.

kmoschcau commented 1 week ago

I did some more testing and I think we can rule out neovim's relevant options. The error seems to happen regardless of their value. I tested 'endofline', 'fixendofline', 'fileformat' and 'bomb'. Since this is the only LSP so far that shows this problem, I would bet on roslyn being off-spec. Might be we could file an issue on their repo or we just handle this case in roslyn.nvim.

seblj commented 1 week ago

Yeah I think an issue to roslyn would be great. The issue should have some details in it though.

For example, the logs for the request, what neovims response is, and such.

It would also be interesting to see the logs of the communication between vscode and roslyn, to see how they deal with this. However, I don't know vscode well enough to configure it to see the logs for requests and response.

I could also be open to a PR with a hacky fix, if it is very self container, doesn't break anything, and does not require a lot of code. I have no idea how it could look like though