Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early request to /highlight endpoint throws NullReferenceException #1521

Closed
nickspoons opened this issue Jun 7, 2019 · 2 comments
Closed

Comments

@nickspoons
Copy link
Member

nickspoons commented Jun 7, 2019

I am trying to work out when the server is ready to receive requests from OmniSharp-vim, using the Stdio version of OmniSharp-roslyn.

My latest attempt is to listen to log events for "Queue project ..." followed by "Successfully loaded project ...", and consider the server "loaded" once all "queued" projects are loaded. At this time we request diagnostics and highlighting.

In a tiny demo project this works correctly. However, in a larger project such as OmniSharp-roslyn, each of these requests fails in a different way.

The "/highlight" request receives a NullReferenceException in the response "Message":

System.NullReferenceException: Object reference not set to an instance of an object.
   at OmniSharp.Roslyn.CSharp.Services.Highlighting.HighlightingService.<Handle>d__1.MoveNext() in C:\code\external\omnisharp-roslyn\src\OmniSharp.Roslyn.CSharp\Services\Highlighting\HighlightingService.cs:line 45
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OmniSharp.Endpoint.EndpointHandler`2.<HandleSingleRequest>d__18.MoveNext() in C:\code\external\omnisharp-roslyn\src\OmniSharp.Host\Endpoint\EndpointHandler.cs:line 156
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OmniSharp.Endpoint.EndpointHandler`2.<Process>d__16.MoveNext() in C:\code\external\omnisharp-roslyn\src\OmniSharp.Host\Endpoint\EndpointHandler.cs:line 127
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OmniSharp.Stdio.Host.<HandleRequest>d__13.MoveNext() in C:\code\external\omnisharp-roslyn\src\OmniSharp.Stdio\Host.cs:line 215

Line 45 of "HighlightingService.cs" is:

var project = document.Project.Name;

So it appears that my current document has not yet been correctly attached to a Project? Subsequent "/highlight" requests work correctly.


I believe the diagnostic issue is similar, but it doesn't return an error. Instead, diagnostics are returned indicating that all classes/methods are duplicates: The namespace '...' already contains a definition for '...'.

This is not resolved by subsequent requests - this buffer will continue to report that it contains duplicate definitions until the server is restarted.

Possibly related to dotnet/vscode-csharp/issues/785 and a few other vscode issues? Although the ones I've found all seem to be related to renaming files, which doesn't occur here.


So I'm submitting this issue since at least the NullReferenceException should be fixable and shouldn't be being returned from the server to the client.

But what I really want to know is when is the server ready to receive requests? There don't seem to be any endpoints which should be polled ("/checkreadystatus" returns true long before the "Successfully loaded project" logs are received), and I can't find any log events to listen for, which make more sense than the ones described above.

Edit: I forgot to explicitly state that in my current setup, adding a short wait (500-1000ms) after all projects are logged as "Successfully loaded" works - no highlighting or diagnostic errors. So I can use this as a workaround if necessary, but I don't know for sure how long this wait period should be (it might need much longer on slow computers?).

@razzmatazz
Copy link
Contributor

razzmatazz commented Dec 7, 2019

Omnisharp-roslyn has the same problem in LSP mode (e.g. when used with emacs/lsp-mode). There is no way to detect "when omnisharp has finished loading all project" and various intermittent requests fail with NREs.

Related issues are:

@nickspoons
Copy link
Member Author

I have discovered what the problem is here - at least the essence of it. Pretty much all requests from OmniSharp-vim include the full buffer contents - even when the buffer is unmodified. When a single request like this is received before the project is loaded, the buffer is added as a "miscellaneous" file, and promoted to to a "project" file once the file is loaded.

However when multiple requests are sent simultaneously (e.g. requests for highlighting and diagnostics) then two miscellaneous files are added in the server - but only one of them is subsequently promoted to a project file. Any later requests for this buffer result in duplicate issues with the remaining miscellaneous file.

I have come up with a work-around system in OmniSharp-vim #598, where any buffer must be "initialized" with an /updatebuffer request. The response must be received before any further requests are made for the buffer, and in this way the server can create a single miscellaneous file which is then used for later requests - and it is correctly promoted to a project file once the server is loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants