Skip to content

Commit 75baa7d

Browse files
authored
Move markdown/plaintext check into completion providers (#8049)
1 parent ca34c00 commit 75baa7d

5 files changed

Lines changed: 12 additions & 98 deletions

File tree

src/issues/issueCompletionProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ export class IssueCompletionProvider implements vscode.CompletionItemProvider {
100100
return [];
101101
}
102102

103-
if ((document.languageId !== 'scminput') && (document.languageId !== 'git-commit') && !(await isComment(document, position))) {
103+
const isPositionComment = document.languageId === 'plaintext' || document.languageId === 'markdown' || await isComment(document, position);
104+
105+
if ((document.languageId !== 'scminput') && (document.languageId !== 'git-commit') && !isPositionComment) {
104106
return [];
105107
}
106108

src/issues/issueLinkProvider.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/issues/issueTodoProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class IssueTodoProvider implements vscode.CodeActionProvider, vscode.Code
120120
if (!todoInfo) {
121121
continue;
122122
}
123-
if (!(await isComment(document, new vscode.Position(lineNumber, firstNonWhitespaceCharacterIndex), []))) {
123+
if (!(await isComment(document, new vscode.Position(lineNumber, firstNonWhitespaceCharacterIndex)))) {
124124
continue;
125125
}
126126
const { match, search, insertIndex } = todoInfo;

src/issues/userCompletionProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export class UserCompletionProvider implements vscode.CompletionItemProvider {
7777
return [];
7878
}
7979

80-
if (!this.isCodeownersFiles(document.uri) && (document.languageId !== 'scminput') && (document.languageId !== 'git-commit') && !(await isComment(document, position))) {
80+
const isPositionComment = document.languageId === 'plaintext' || document.languageId === 'markdown' || await isComment(document, position);
81+
82+
if (!this.isCodeownersFiles(document.uri) && (document.languageId !== 'scminput') && (document.languageId !== 'git-commit') && !isPositionComment) {
8183
return [];
8284
}
8385

src/issues/util.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,12 @@ export async function pushAndCreatePR(
516516
}
517517
}
518518

519-
export async function isComment(document: vscode.TextDocument, position: vscode.Position, excludedLanguageIds = ['markdown', 'plaintext']): Promise<boolean> {
520-
if (!excludedLanguageIds.includes(document.languageId)) {
521-
const tokenInfo = await vscode.languages.getTokenInformationAtPosition(document, position);
522-
if (tokenInfo.type !== vscode.StandardTokenType.Comment) {
523-
return false;
524-
}
519+
export async function isComment(document: vscode.TextDocument, position: vscode.Position): Promise<boolean> {
520+
const tokenInfo = await vscode.languages.getTokenInformationAtPosition(document, position);
521+
if (tokenInfo.type !== vscode.StandardTokenType.Comment) {
522+
return false;
525523
}
524+
526525
return true;
527526
}
528527

0 commit comments

Comments
 (0)