-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Generate Documentation - Add loading state #77718
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
Changes from 1 commit
a6cb468
2ec7d20
d3285bd
4940645
460d59f
2d4ba87
1131a6f
d7fac19
911112a
f9d1800
4f7499b
0fc6c8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ public override async Task OnAcceptedAsync(SuggestionSessionBase session, Propos | |
| var threadingContext = providerInstance.ThreadingContext; | ||
|
|
||
| await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancel); | ||
| await DisposeAsync().ConfigureAwait(false); | ||
| await DisposeIntelliCodeCompletionsDisposableAsync().ConfigureAwait(false); | ||
| Logger.Log(FunctionId.Copilot_Generate_Documentation_Accepted, logLevel: LogLevel.Information); | ||
| } | ||
|
|
||
|
|
@@ -66,14 +66,33 @@ public override Task OnProposalUpdatedAsync(SuggestionSessionBase session, Propo | |
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| public async Task StartSuggestionSessionWithProposalAsync( | ||
| Func<CancellationToken, Task<ProposalBase?>> generateProposal, CancellationToken cancellationToken) | ||
| { | ||
| var sessionStarted = await StartSuggestionSessionAsync(cancellationToken).ConfigureAwait(false); | ||
| if (!sessionStarted) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var proposal = await generateProposal(cancellationToken).ConfigureAwait(false); | ||
| if (proposal is null) | ||
| { | ||
| await DismissSuggestionSessionAsync(cancellationToken).ConfigureAwait(false); | ||
| return; | ||
| } | ||
|
|
||
| await TryDisplayDocumentationSuggestionAsync(proposal, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Starts the Suggestion Session. The TryDisplaySuggestion call doesn't display any grey text, but starts the session such that we have the | ||
| /// exclusive right to display grey text later. | ||
| /// </summary> | ||
| /// <returns>If true, user will see the thinking state as long as the Suggestion Session is active and replace with grey text if a call to DisplayProposal succeeds. | ||
| /// If unable to retrieve the session, the caller should bail out. | ||
| /// </returns> | ||
| public async Task<bool> StartSuggestionSessionAsync(CancellationToken cancellationToken) | ||
| private async Task<bool> StartSuggestionSessionAsync(CancellationToken cancellationToken) | ||
| { | ||
| _suggestionSession = await RunWithEnqueueActionAsync( | ||
| "StartWork", | ||
|
|
@@ -82,13 +101,17 @@ public async Task<bool> StartSuggestionSessionAsync(CancellationToken cancellati | |
|
|
||
| if (_suggestionSession is null) | ||
akhera99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| await DisposeAsync().ConfigureAwait(false); | ||
| await DisposeIntelliCodeCompletionsDisposableAsync().ConfigureAwait(false); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This is where we actually try to display the grey-text from the proposal | ||
| /// we created. | ||
| /// </summary> | ||
| public async Task TryDisplayDocumentationSuggestionAsync(ProposalBase proposal, CancellationToken cancellationToken) | ||
| { | ||
| try | ||
|
|
@@ -112,10 +135,12 @@ await RunWithEnqueueActionAsync<bool>( | |
|
|
||
| /// <summary> | ||
| /// Dismisses the session if the proposal we generated was invalid. | ||
| /// Needs to dispose of the IntelliCodeCompletionsDisposable so we no longer have exclusive right to | ||
| /// display any grey text. | ||
| /// </summary> | ||
| public async Task DismissSuggestionSessionAsync(CancellationToken cancellationToken) | ||
| private async Task DismissSuggestionSessionAsync(CancellationToken cancellationToken) | ||
| { | ||
| await DisposeAsync().ConfigureAwait(false); | ||
| await DisposeIntelliCodeCompletionsDisposableAsync().ConfigureAwait(false); | ||
| await RunWithEnqueueActionAsync<bool>( | ||
| "DismissSuggestionSession", | ||
| async () => | ||
|
|
@@ -141,7 +166,6 @@ private async Task<T> RunWithEnqueueActionAsync<T>(string description, Func<Task | |
| await providerInstance.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe so based on the pattern in the platform, but @dpugh would know more about this particular requirement. |
||
| SuggestionManager.EnqueueAction(description, async () => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is super weird. they expect you to pass in an async function. but then they dont' make this function itself task-returning so you can track it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. talked offline |
||
| { | ||
| var task = action(); | ||
| try | ||
| { | ||
| var result = await action().ConfigureAwait(false); | ||
|
||
|
|
@@ -168,14 +192,14 @@ private async Task ClearSuggestionAsync(ReasonForDismiss reason, CancellationTok | |
| } | ||
|
|
||
| _suggestionSession = null; | ||
| await DisposeAsync().ConfigureAwait(false); | ||
| await DisposeIntelliCodeCompletionsDisposableAsync().ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The IntelliCodeLineCompletionDisposable needs to be disposed any time we exit the SuggestionSession so that | ||
| /// line completions can be shown again. | ||
| /// </summary> | ||
| private async Task DisposeAsync() | ||
| private async Task DisposeIntelliCodeCompletionsDisposableAsync() | ||
| { | ||
| if (IntelliCodeLineCompletionsDisposable != null) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.