-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
vscode.languages.getDiagnostics appears to return old diagnostics in some circumstances #54359
Comments
(Experimental duplicate detection)
|
So, if these extension always create a new collection, with disposing the old one it's likely that. The UI is likely deduping makers but the model won't. So, with the sample above, you are always adding new diagnostics but never removing them. Calling So, please check with your extension(s). |
Sorry, only saw that now. Yeah, we don't dedupe in the model and I don't think it's the correct thing to do. |
We have a great developer community over on slack where extension authors help each other. This is a great place for you to ask questions and find support. Happy Coding! |
@jrieken Apologies. My original repro was probably too simple. If I modify the diagnostic message like the following: let num = 0;
...
// Notice that I'm changing the error message each time to prevent de-duplication
errors.set(d.uri, [new vscode.Diagnostic(new vscode.Range(0, 0, 0, 0), `Failure${num++}`)]); And save the document a few times, I see the following in the And I see the following output from calling Are you saying that the Even further, if I call the |
Sure about that? Both methods loop over the same collection of DiagnosticsCollections... Be aware of the different return types.
As long as you create more and more collections without disposing old ones, diagnostics pile up and the
Fair question. Taking another look and turns out that the |
@jrieken Ah yeah, you're right. Both overloads of |
I have now added a warning when a diagnostic collection with the same name is created (and it will use a different owner). Interestingly, TypeScript triggers this warning because for JS and TS the same name/owner is being used. According to @mjbvz this is because of tasks and problem matching. @dbaeumer can you provide insights. |
Using a different owner for TypeScript and JavaScript works as long as users don't use a TSC task to check JS code. If they do the best we can do is to have different problem matchers with different IDs. I would suggest we simply make the change in the TS extension and then see if users get hit by tasks on pure JS projects (which I think is a very limited number of users in total). |
Ok. Alternatively, TypeScript can use one diagnostics collection (named typescript) for both languages |
I leave my change as it and leaving up to you two to fix this |
+1 for @jrieken suggestion since it is the right fix to do since JS and TS will not overlap. |
Here's the change that unified the diagnostics in the first place b945973 which was made to fix #48709. It was done for exactly the reason you detailed: using tsc to check javascript code. Using a single collection will require work since we make some assumptions about having separate ones for JS and TS (it lets us handle the |
@mjbvz thanks! |
A user reported an issue with VS Live Share, about diagnostics not being synchronized properly between participants in a session. After looking into it a bit, it appears like the issue may be with the
vscode.languages.getDiagnostics
method returning "stale"Diagnostics
, depending on how the lifetime of theDiagnosticCollection
is managed by extensions.For example, take the following code (which is representative of what the Elm and Flow extensions are currently doing):
If you debug that, and edit/save a document a couple times, you'll see the following in the
Problems
pane, which is the expected behavior:However, if you look in the
Debug Console
, you'll see the following printed, which is the output of thelanguages.getDiagnostics
method:So for some reason, the
Problems
pane is displaying the expected diagnostics. However, thegetDiagnostics
method is returning stale diagnostics. Ultimately, this results in errors never going away, since the result of callinggetDiagnostics
becomes purely additive. This is problematic for Live Share, since we use the results of thegetDiagnostics
method to sync diagnostics with guests.If you modify the above code, to create a single
DiagnosticCollection
for the lifetime of the extension (as opposed to re-creating it over and over again), then things behave as expected:Overall, the above code seems to make sense, and I submitted a PR to the Elm extension to refactor their code as such. However, it would be ideal if the
vscode.languages.getDiagnostics
method was resilient to this situation, and returned the sameDiagnostics
that are being displayed in theProblems
pane.The text was updated successfully, but these errors were encountered: