Skip to content

Commit 5f9929b

Browse files
authored
Can't add comments on added lines (#3558)
Fixes #3556
1 parent b1d8928 commit 5f9929b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/github/utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,15 @@ export function parseGraphQLViewerPermission(
909909
return ViewerPermission.Unknown;
910910
}
911911

912+
export function isFileInRepo(repository: Repository, file: vscode.Uri): boolean {
913+
return file.path.toLowerCase() === repository.rootUri.path.toLowerCase() ||
914+
(file.path.toLowerCase().startsWith(repository.rootUri.path.toLowerCase()) &&
915+
file.path.substring(repository.rootUri.path.length).startsWith('/'));
916+
}
917+
912918
export function getRepositoryForFile(gitAPI: GitApiImpl, file: vscode.Uri): Repository | undefined {
913919
for (const repository of gitAPI.repositories) {
914-
if (
915-
file.path.toLowerCase() === repository.rootUri.path.toLowerCase() ||
916-
(file.path.toLowerCase().startsWith(repository.rootUri.path.toLowerCase()) &&
917-
file.path.substring(repository.rootUri.path.length).startsWith('/'))
918-
) {
920+
if (isFileInRepo(repository, file)) {
919921
return repository;
920922
}
921923
}

src/view/reviewCommentController.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { PullRequestOverviewPanel } from '../github/pullRequestOverview';
2121
import {
2222
CommentReactionHandler,
2323
createVSCodeCommentThreadForReviewThread,
24+
isFileInRepo,
2425
threadRange,
2526
updateCommentReviewState,
2627
updateCommentThreadLabel,
@@ -378,15 +379,12 @@ export class ReviewCommentController
378379
return true;
379380
}
380381

381-
const currentWorkspace = vscode.workspace.getWorkspaceFolder(thread.uri);
382-
if (!currentWorkspace) {
382+
383+
if (!isFileInRepo(this._repository, thread.uri)) {
383384
return false;
384385
}
385386

386-
if (
387-
thread.uri.scheme === currentWorkspace.uri.scheme &&
388-
thread.uri.fsPath.startsWith(this._repository.rootUri.fsPath)
389-
) {
387+
if (thread.uri.scheme === this._repository.rootUri.scheme) {
390388
return true;
391389
}
392390

@@ -408,12 +406,11 @@ export class ReviewCommentController
408406
}
409407
}
410408

411-
const currentWorkspace = vscode.workspace.getWorkspaceFolder(document.uri);
412-
if (!currentWorkspace) {
409+
if (!isFileInRepo(this._repository, document.uri)) {
413410
return;
414411
}
415412

416-
if (document.uri.scheme === currentWorkspace.uri.scheme) {
413+
if (document.uri.scheme === this._repository.rootUri.scheme) {
417414
if (!this._reposManager.activePullRequest!.isResolved()) {
418415
return;
419416
}

0 commit comments

Comments
 (0)