Skip to content

Commit 5a8659a

Browse files
authored
local usage of _chatAccessibilityService, don't spread it around the state machine (microsoft#196737)
microsoft#194424
1 parent 7eec26f commit 5a8659a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
4343
import { IModelDeltaDecoration } from 'vs/editor/common/model';
4444
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
4545
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
46+
import { renderMarkdownAsPlaintext } from 'vs/base/browser/markdownRenderer';
4647

4748
export const enum State {
4849
CREATE_SESSION = 'CREATE_SESSION',
@@ -564,6 +565,7 @@ export class InlineChatController implements IEditorContribution {
564565
private async [State.MAKE_REQUEST](): Promise<State.APPLY_RESPONSE | State.PAUSE | State.CANCEL | State.ACCEPT> {
565566
assertType(this._editor.hasModel());
566567
assertType(this._activeSession);
568+
assertType(this._strategy);
567569
assertType(this._activeSession.lastInput);
568570

569571
const requestCts = new CancellationTokenSource();
@@ -586,7 +588,6 @@ export class InlineChatController implements IEditorContribution {
586588
wholeRange: this._activeSession.wholeRange.value,
587589
live: this._activeSession.editMode !== EditMode.Preview // TODO@jrieken let extension know what document is used for previewing
588590
};
589-
this._chatAccessibilityService.acceptRequest();
590591

591592
const modelAltVersionIdNow = this._activeSession.textModelN.getAlternativeVersionId();
592593
const progressEdits: TextEdit[][] = [];
@@ -646,6 +647,11 @@ export class InlineChatController implements IEditorContribution {
646647
this._zone.value.widget.updateMarkdownMessage(markdownContents);
647648
}
648649
});
650+
651+
let a11yResponse: string | undefined;
652+
const a11yVerboseInlineChat = this._configurationService.getValue<boolean>('accessibility.verbosity.inlineChat') === true;
653+
this._chatAccessibilityService.acceptRequest();
654+
649655
const task = this._activeSession.provider.provideResponse(this._activeSession.session, request, progress, requestCts.token);
650656
this._log('request started', this._activeSession.provider.debugName, this._activeSession.session, request);
651657

@@ -666,24 +672,32 @@ export class InlineChatController implements IEditorContribution {
666672
if (reply?.type === InlineChatResponseType.Message) {
667673
markdownContents.appendMarkdown(reply.message.value);
668674
response = new MarkdownResponse(this._activeSession.textModelN.uri, reply, markdownContents);
675+
a11yResponse = renderMarkdownAsPlaintext(markdownContents);
669676
} else if (reply) {
670677
const editResponse = new EditResponse(this._activeSession.textModelN.uri, modelAltVersionIdNow, reply, progressEdits);
671678
for (let i = progressEdits.length; i < editResponse.allLocalEdits.length; i++) {
672679
await this._makeChanges(editResponse.allLocalEdits[i], undefined);
673680
}
674681
response = editResponse;
682+
a11yResponse = this._strategy.checkChanges(editResponse) && a11yVerboseInlineChat
683+
? localize('editResponseMessage', "Review proposed changes in the diff editor.")
684+
: '';
675685
} else {
676686
response = new EmptyResponse();
687+
a11yResponse = localize('empty', "No results, please refine your input and try again");
677688
}
678689

679690
} catch (e) {
680691
response = new ErrorResponse(e);
692+
a11yResponse = (<ErrorResponse>response).message;
693+
681694
} finally {
682695
this._ctxHasActiveRequest.set(false);
683696
this._zone.value.widget.updateProgress(false);
684697
this._zone.value.widget.updateInfo('');
685698
this._zone.value.widget.updateToolbar(true);
686699
this._log('request took', requestClock.elapsed(), this._activeSession.provider.debugName);
700+
this._chatAccessibilityService.acceptResponse(a11yResponse);
687701
}
688702

689703
progressiveEditsCts.dispose(true);
@@ -760,8 +774,6 @@ export class InlineChatController implements IEditorContribution {
760774

761775
const { response } = this._activeSession.lastExchange!;
762776

763-
let status: string | undefined;
764-
765777
this._ctxLastResponseType.set(response instanceof EditResponse || response instanceof MarkdownResponse
766778
? response.raw.type
767779
: undefined);
@@ -785,27 +797,22 @@ export class InlineChatController implements IEditorContribution {
785797

786798
if (response instanceof EmptyResponse) {
787799
// show status message
788-
status = localize('empty', "No results, please refine your input and try again");
800+
const status = localize('empty', "No results, please refine your input and try again");
789801
this._zone.value.widget.updateStatus(status, { classes: ['warn'] });
790-
this._chatAccessibilityService.acceptResponse(status);
791802
return State.WAIT_FOR_INPUT;
792803

793804
} else if (response instanceof ErrorResponse) {
794805
// show error
795806
if (!response.isCancellation) {
796-
status = response.message;
797-
this._zone.value.widget.updateStatus(status, { classes: ['error'] });
807+
this._zone.value.widget.updateStatus(response.message, { classes: ['error'] });
798808
}
799809

800810
} else if (response instanceof MarkdownResponse) {
801811
// clear status, show MD message
802812

803813
this._zone.value.widget.updateStatus('');
804-
const content = this._zone.value.widget.updateMarkdownMessage(response.mdContent);
814+
this._zone.value.widget.updateMarkdownMessage(response.mdContent);
805815
this._zone.value.widget.updateToolbar(true);
806-
if (content) {
807-
status = localize('markdownResponseMessage', "{0}", content);
808-
}
809816
this._activeSession.lastExpansionState = this._zone.value.widget.expansionState;
810817

811818
} else if (response instanceof EditResponse) {
@@ -815,13 +822,10 @@ export class InlineChatController implements IEditorContribution {
815822

816823
const canContinue = this._strategy.checkChanges(response);
817824
if (!canContinue) {
818-
this._chatAccessibilityService.acceptResponse();
819825
return State.CANCEL;
820826
}
821-
status = this._configurationService.getValue('accessibility.verbosity.inlineChat') === true ? localize('editResponseMessage', "Review proposed changes in the diff editor.") : '';
822827
await this._strategy.renderChanges(response);
823828
}
824-
this._chatAccessibilityService.acceptResponse(status);
825829
this._showWidget(false);
826830

827831
return State.WAIT_FOR_INPUT;

0 commit comments

Comments
 (0)