Skip to content

Commit

Permalink
Don't show "make suggestion" when there's already a suggestion in the…
Browse files Browse the repository at this point in the history
… editor (#6202)

Fixes #6195
  • Loading branch information
alexr00 committed Sep 6, 2024
1 parent fcdb14f commit f685eaf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,7 @@
{
"command": "pr.makeSuggestion",
"group": "inline@3",
"when": "commentController =~ /^github-(browse|review)/"
"when": "commentController =~ /^github-(browse|review)/ && !github:activeCommentHasSuggestion"
}
],
"comments/commentThread/additionalActions": [
Expand Down
1 change: 1 addition & 0 deletions src/common/executeCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export namespace contexts {
export const CREATE_PR_PERMISSIONS = 'github:createPrPermissions';
export const RESOLVING_CONFLICTS = 'github:resolvingConflicts';
export const PULL_REQUEST_DESCRIPTION_VISIBLE = 'github:pullRequestDescriptionVisible';
export const ACTIVE_COMMENT_HAS_SUGGESTION = 'github:activeCommentHasSuggestion';
}

export namespace commands {
Expand Down
26 changes: 26 additions & 0 deletions src/view/reviewCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CommentHandler, registerCommentHandler, unregisterCommentHandler } from
import { DiffSide, IReviewThread, SubjectType } from '../common/comment';
import { getCommentingRanges } from '../common/commentingRanges';
import { mapNewPositionToOld, mapOldPositionToNew } from '../common/diffPositionMapping';
import { commands, contexts } from '../common/executeCommands';
import { GitChangeType } from '../common/file';
import Logger from '../common/logger';
import { PR_SETTINGS_NAMESPACE, PULL_BRANCH, PULL_PR_BRANCH_BEFORE_CHECKOUT, PullPRBranchVariants } from '../common/settingKeys';
Expand All @@ -37,6 +38,7 @@ import { RemoteFileChangeModel } from './fileChangeModel';
import { ReviewManager } from './reviewManager';
import { ReviewModel } from './reviewModel';
import { GitFileChangeNode, gitFileChangeNodeFilter, RemoteFileChangeNode } from './treeNodes/fileChangeNode';
import { IDisposable } from 'cockatiel';

export interface SuggestionInformation {
originalStartLine: number;
Expand Down Expand Up @@ -357,6 +359,30 @@ export class ReviewCommentController extends CommentControllerBase
this.updateResourcesWithCommentingRanges();
}),
);
this._localToDispose.push(vscode.window.onDidChangeActiveTextEditor(e => this.onDidChangeActiveTextEditor(e)));
}

private _commentContentChangedListner: IDisposable | undefined;
private onDidChangeActiveTextEditor(editor: vscode.TextEditor | undefined) {
this._commentContentChangedListner?.dispose();
this._commentContentChangedListner = undefined;
if (editor?.document.uri.scheme !== Schemes.Comment) {
return;
}
const updateHasSuggestion = () => {
if (editor.document.getText().includes('```suggestion')) {
commands.setContext(contexts.ACTIVE_COMMENT_HAS_SUGGESTION, true);
} else {
commands.setContext(contexts.ACTIVE_COMMENT_HAS_SUGGESTION, false);
}
};
this._commentContentChangedListner = vscode.workspace.onDidChangeTextDocument(e => {
if (e.document.uri.toString() !== editor.document.uri.toString()) {
return;
}
updateHasSuggestion();
});
updateHasSuggestion();
}

public updateCommentExpandState(expand: boolean) {
Expand Down

0 comments on commit f685eaf

Please sign in to comment.