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

Edit and continue diagnostic source #72787

Merged
merged 12 commits into from
Apr 16, 2024

Conversation

tmat
Copy link
Member

@tmat tmat commented Mar 28, 2024

Directly hook EnC document analysis into pull diagnostic handler instead of going through legacy incremental analyzer system.

Since pull diagnostics ae implemented in the LSP layer we need to expose the EnC session state to this layer via a new MEF component (IEditAndContinueSessionTracker). Previously the state was directly on EditAndContinueLanguageService, which is in Editor Features layer. We also need the IActiveStatementSpanLocator, which reports the current locations of active statements to the EnC analysis, to be available in LSP layer.

There are three kinds of EnC diagnostics: 1) rude edits that are determined from document semantic analysis and 2) emit errors reported by the compiler when we try to emit deltas and 3) issues related to the current state of the debuggee.

When pull request for semantic diagnostics is processed and the EnC session is active we analyze the document for rude edits and report them. We don't attempt to emit the deltas at that point or check the debuggee status. Emitting deltas is expensive and the diagnostics that are only reported in emit phase are rare. The debuggee status may change at any point during the edit session and it might be confusing to report these diagnostics until the user is actually applying the change. Instead, we store emit and debuggee state relate diagnostics to the EnC session state and when we pull we simply include the stored diagnostics. We invalidate and refresh the pull diagnostics whenever the EnC session state changes (start session, enter/exit break state, end session).

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 28, 2024
@tmat tmat force-pushed the EditAndContinueDiagnosticSource branch from 1492505 to e828e3a Compare March 29, 2024 16:01
@tmat
Copy link
Member Author

tmat commented Mar 29, 2024

@tmat tmat marked this pull request as ready for review March 29, 2024 16:31
@tmat tmat requested a review from a team as a code owner March 29, 2024 16:31
@tmat
Copy link
Member Author

tmat commented Apr 5, 2024

@dibarbet @CyrusNajmabadi Updated per our discussion.

@tmat
Copy link
Member Author

tmat commented Apr 5, 2024

I did not need to add any special handling to clear diagnostics. Added a test to cover it. Seems to work.

return ValueTaskFactory.FromResult(DocumentPullDiagnosticHandler.GetDiagnosticSources(DiagnosticKind.All, nonLocalDocumentDiagnostics, taskList: false, context, GlobalOptions));
var source = nonLocalDocumentDiagnostics
? DocumentPullDiagnosticHandler.GetNonLocalDiagnosticSource(context, GlobalOptions)
: DocumentPullDiagnosticHandler.GetDiagnosticSource(DiagnosticKind.All, context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmat @dibarbet what is "DocumentNonLocalDiagnosticIdentifier"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh - we already create buckets in VSCode - I completely forgot about this. Its for diagnostics reported on the document during compilation end

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signing off on teh pull-diags changes. Just nits and small requests for explanations or docs. Glad it was so simple :)

return ValueTaskFactory.FromResult(DocumentPullDiagnosticHandler.GetDiagnosticSources(DiagnosticKind.All, nonLocalDocumentDiagnostics, taskList: false, context, GlobalOptions));
var source = nonLocalDocumentDiagnostics
? DocumentPullDiagnosticHandler.GetNonLocalDiagnosticSource(context, GlobalOptions)
: DocumentPullDiagnosticHandler.GetDiagnosticSource(DiagnosticKind.All, context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh - we already create buckets in VSCode - I completely forgot about this. Its for diagnostics reported on the document during compilation end

return new(GetDiagnosticSources(diagnosticKind: default, nonLocalDocumentDiagnostics: false, taskList: true, context, GlobalOptions));
return context.GetTrackedDocument<Document>() is { } document ? new TaskListDiagnosticSource(document, GlobalOptions) : null;

if (category == PullDiagnosticCategories.EditAndContinue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently these won't ever show in VSCode (because we only register the kind for VS diagnostics).

For VSCode, buckets are named 'identifiers', and they can only be registered dynamically like we do here -

And unfortunately it has a different field name. If you add add the identifier, in the Public doc pull handler, you'll also need to add the code to check for the identifier and create a source for it.

@tmat tmat force-pushed the EditAndContinueDiagnosticSource branch from 3a68276 to 5937238 Compare April 10, 2024 18:51
@tmat tmat force-pushed the EditAndContinueDiagnosticSource branch 2 times, most recently from 5983785 to 3e2e3ce Compare April 15, 2024 16:27
@tmat tmat enabled auto-merge (squash) April 15, 2024 16:35
@tmat tmat force-pushed the EditAndContinueDiagnosticSource branch from 3e2e3ce to 6a03c2a Compare April 16, 2024 17:43
@tmat tmat merged commit 699610e into dotnet:main Apr 16, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 16, 2024
@tmat tmat deleted the EditAndContinueDiagnosticSource branch April 16, 2024 23:05
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants