Skip to content

Commit

Permalink
fix broken regex on src/services/completions.ts#840
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffy-g committed Mar 30, 2020
1 parent 11043b0 commit 5b9da77
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,32 +814,33 @@ namespace ts.Completions {
let isInSnippetScope = false;
if (insideComment) {
if (hasDocComment(sourceFile, position)) {
if (sourceFile.text.charCodeAt(position - 1) === CharacterCodes.at) {
// The current position is next to the '@' sign, when no tag name being provided yet.
// Provide a full list of tag names
return { kind: CompletionDataKind.JsDocTagName };
}
else {
// When completion is requested without "@", we will have check to make sure that
// there are no comments prefix the request position. We will only allow "*" and space.
// e.g
// /** |c| /*
//
// /**
// |c|
// */
//
// /**
// * |c|
// */
//
// /**
// * |c|
// */
const lineStart = getLineStartPositionForPosition(position, sourceFile);
if (!(sourceFile.text.substring(lineStart, position).match(/[^\*|\s|(/\*\*)]/))) {
return { kind: CompletionDataKind.JsDocTag };
}
// When completion is requested without "@", we will have check to make sure that
// there are no comments prefix the request position. We will only allow "*" and space.
// e.g
// /** |c| /*
//
// /**
// |c|
// */
//
// /**
// * |c|
// */
//
// /**
// * |c|
// */
const lineStart = getLineStartPositionForPosition(position, sourceFile);
// jsdoc tag will be listed if there is more than one whitespace after "*"
const match = /^\s*(?:[*\s]+(?=\s)|\/\*\*)?\s+(@)?$/.exec(
sourceFile.text.substring(lineStart, position)
);
if (match) {
return {
// The current position is next to the '@' sign, when no tag name being provided yet.
// Provide a full list of tag names
kind: match[1] ? CompletionDataKind.JsDocTagName: CompletionDataKind.JsDocTag
};
}
}

Expand Down
49 changes: 49 additions & 0 deletions tests/cases/fourslash/completionsJsdocTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,53 @@
//// * /**/
//// */

/////**
//// +/*1*/
//// */
////function a0(s: string) {}
////

verify.completions({ marker: "", includes: { name: "@property", text: "@property", kind: "keyword" } });


//
// test for src/services/completions.ts#getCompletionData.insideComment.hasDocComment (#37546)
//
// line 2: [ +|c|]
verify.completions({
marker: "1",
exact: []
});
// line 2: [ +|c|] -> [ +@|c|]
// before the fix, jsdoc tag names was listed but no longer appears
edit.insert("@");
verify.completions({
marker: "1",
exact: []
});
// line 2: [ +@|c|] -> [ *|c|]
// before the fix, jsdoc tags was listed but no longer appears
edit.replaceLine(1, " *");
verify.completions({
exact: []
});
// line 2: [ *|c|] -> [ *@|c|]
// this behavior does not by getCompletionData.insideComment.hasDocComment section
edit.insert("@");
verify.completions({
triggerCharacter: "@",
includes: ["abstract", "access"]
});
// line 2: [ *@|c|] -> [ * |c|]
// jsdoc tags are listed when there is more than one whitespace after "*"
edit.replaceLine(1, " * ");
verify.completions({
includes: ["@abstract", "@access"]
});
// line 2: [ * |c|] -> [ * @|c|]
// jsdoc tag names will be listed
edit.insert("@");
verify.completions({
triggerCharacter: "@",
includes: ["abstract", "access"]
});

0 comments on commit 5b9da77

Please sign in to comment.