-
Notifications
You must be signed in to change notification settings - Fork 417
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
Comments
We don't know exactly when the server is fully initialised, and sending requests too early can cause issues, see: OmniSharp/omnisharp-roslyn#1521
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: |
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 |
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":Line 45 of "HighlightingService.cs" is:
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?).
The text was updated successfully, but these errors were encountered: