Skip to content

Commit

Permalink
Change to a version with minimal modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffy-g committed May 11, 2020
1 parent fe460f0 commit 3f1bb2d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 135 deletions.
54 changes: 26 additions & 28 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/cases/fourslash/completionInJsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
//// /** /*9*/ */
////
//// /**
//// /*10*/
//// */
//// /*10*/
//// */
////
//// /**
//// * /*11*/
Expand Down
105 changes: 0 additions & 105 deletions tests/cases/fourslash/completionsJsdocTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});

0 comments on commit 3f1bb2d

Please sign in to comment.