diff --git a/src/services/completions.ts b/src/services/completions.ts index 55c78b3d5aeb0..a3845bf3ece03 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -852,34 +852,32 @@ namespace ts.Completions { let isInSnippetScope = false; if (insideComment) { if (hasDocComment(sourceFile, position)) { - // 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); - const jsdocFragment = sourceFile.text.substring(lineStart, position); - const reJSDocFragment = /^(?:\s*\/\*\*\s+|\s+\*?\s+)(@(?:\w+)?)?/g; - const match = reJSDocFragment.exec(jsdocFragment); - if (match && reJSDocFragment.lastIndex === jsdocFragment.length) { - return { - kind: match[1] - // The current position is next to the '@' sign, when no tag name being provided yet. - // Provide a full list of tag names - ? CompletionDataKind.JsDocTagName - : CompletionDataKind.JsDocTag - }; + 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 (!/[^\*|\s(/)]/.test(sourceFile.text.substring(lineStart, position))) { + return { kind: CompletionDataKind.JsDocTag }; + } } } diff --git a/tests/cases/fourslash/completionInJsDoc.ts b/tests/cases/fourslash/completionInJsDoc.ts index 8b3338fcbfc0c..d30a92fe114ba 100644 --- a/tests/cases/fourslash/completionInJsDoc.ts +++ b/tests/cases/fourslash/completionInJsDoc.ts @@ -29,8 +29,8 @@ //// /** /*9*/ */ //// //// /** -//// /*10*/ -//// */ +//// /*10*/ +//// */ //// //// /** //// * /*11*/ diff --git a/tests/cases/fourslash/completionsJsdocTag.ts b/tests/cases/fourslash/completionsJsdocTag.ts index f4332afd11a2e..71a7a97bc6e61 100644 --- a/tests/cases/fourslash/completionsJsdocTag.ts +++ b/tests/cases/fourslash/completionsJsdocTag.ts @@ -5,109 +5,4 @@ //// * /**/ //// */ - -// 1x - jsdoc tags are listed when there is more than one whitespace after "*" -/////** -//// * /*10*/ -//// */ -//// -/////** -//// * /*11*/ -//// */ -//// - -// 2x - Also, if there are two or more blanks at the beginning of the line -/////** -//// /*20*/ -//// */ -//// -/////** -//// /*21*/ -//// */ -//// - -// 3x - jsdoc tag names will be listed -/////** @/*30*/ */ -//// -/////** @/*31*/ */ -//// -/////** -//// * @/*32*/ -//// */ -//// -/////** -//// * @/*33*/ -//// */ -//// -/////** -//// @/*34*/ -//// */ -//// -/////** -//// @/*35*/ -//// */ -//// -/////** -//// * @pa/*36*/ -//// */ -//// - -// 5x - jsdoc tag completions should not occur -/////** -//// */*50*/ -//// */ -//// -/////** -//// /*51*/ -//// */ -//// -/////** -/////*52*/ -//// */ -//// - verify.completions({ marker: "", includes: { name: "@property", text: "@property", kind: "keyword" } }); - - -// -// test for src/services/completions.ts#getCompletionData.insideComment.hasDocComment (#37546) -// -test.markerNames().forEach(marker => { - if (marker) { - let completionOpt: FourSlashInterface.CompletionsOptions; - const n = +marker; - switch (n) { - // jsdoc tags will be listed when there is more than one whitespace after "*" - case 10: case 11: - // Also, if there are two or more blanks at the beginning of the line - case 20: case 21: - completionOpt = { marker, includes: [ - "@abstract", "@access", - ]}; - break; - - // 3x - jsdoc tag names will be listed - case 30: case 31: case 32: case 33: case 34: case 35: case 36: - completionOpt = { - marker, - triggerCharacter: "@", - includes: ["package", "param"] - }; - break; - - // 5x - jsdoc tag completions should not occur - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // before the fix, jsdoc tags was listed but no longer appears - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case 50: case 51: case 52: - completionOpt = { marker, exact: [] }; - break; - - default: - break; - } - if (completionOpt) { - verify.completions(completionOpt); - } - } -});