Skip to content

Commit 802b460

Browse files
authored
Fix commentContinuationPatterns if they're a prefix of a later one. (#14082)
* Fix commentContinuationPatterns if they're a prefix of a later one.
1 parent 3a458aa commit 802b460

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Extension/src/LanguageServer/settings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ export class CppSettings extends Settings {
386386
public get commentContinuationPatterns(): (string | CommentPattern)[] {
387387
const value: any = super.Section.get<any>("commentContinuationPatterns");
388388
if (this.isArrayOfCommentContinuationPatterns(value)) {
389+
// Needs to be sorted with longer patterns first so it takes precedence and
390+
// doesn't apply the shorter pattern if it's a prefix (e.g. // matching ///).
391+
value.sort((a: string | CommentPattern, b: string | CommentPattern) => {
392+
const aStr: string = isString(a) ? a : a.begin;
393+
const bStr: string = isString(b) ? b : b.begin;
394+
return bStr.length - aStr.length;
395+
});
389396
return value;
390397
}
391398
const setting = getRawSetting("C_Cpp.commentContinuationPatterns", true);

0 commit comments

Comments
 (0)