Skip to content

Commit b5c6221

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR
1 parent 9bef19c commit b5c6221

File tree

2 files changed

+56
-43
lines changed

2 files changed

+56
-43
lines changed

src/services/completions.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ namespace ts.Completions {
1616
return undefined;
1717
}
1818

19-
const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isJsDocTagName, shouldAppendAtSignBeforeJsDocTagName } = completionData;
19+
const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, requestJsDocTagName, requestJsDocTag } = completionData;
2020

21-
if (isJsDocTagName) {
21+
if (requestJsDocTagName) {
2222
// If the current position is a jsDoc tag name, only tag names should be provided for completion
23-
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getAllJsDocCompletionEntries(shouldAppendAtSignBeforeJsDocTagName) };
23+
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getJSDocTagNameCompletions() };
24+
}
25+
26+
if (requestJsDocTag) {
27+
// If the current position is a jsDoc tag, only tags should be provided for completion
28+
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getJSDocTagCompletions() };
2429
}
2530

2631
const entries: CompletionEntry[] = [];
@@ -54,7 +59,7 @@ namespace ts.Completions {
5459
}
5560

5661
// Add keywords if this is not a member completion list
57-
if (!isMemberCompletion && !isJsDocTagName) {
62+
if (!isMemberCompletion && !(requestJsDocTag && requestJsDocTagName)) {
5863
addRange(entries, keywordCompletions);
5964
}
6065

@@ -814,13 +819,10 @@ namespace ts.Completions {
814819
function getCompletionData(typeChecker: TypeChecker, log: (message: string) => void, sourceFile: SourceFile, position: number) {
815820
const isJavaScriptFile = isSourceFileJavaScript(sourceFile);
816821

817-
let isJsDocTagName = false;
818-
// This is for the case when users request completion in JsDoc without "@"
819-
// i.e.
820-
// /**
821-
// * |completion here|
822-
// **/
823-
let shouldAppendAtSignBeforeJsDocTagName = false;
822+
// JsDoc tag-name is just the name of the JSDoc tagname (exclude "@")
823+
let requestJsDocTagName = false;
824+
// JsDoc tag includes both "@" and tag-name
825+
let requestJsDocTag = false;
824826

825827
let start = timestamp();
826828
const currentToken = getTokenAtPosition(sourceFile, position);
@@ -836,15 +838,27 @@ namespace ts.Completions {
836838
// The current position is next to the '@' sign, when no tag name being provided yet.
837839
// Provide a full list of tag names
838840
if (sourceFile.text.charCodeAt(position - 1) === CharacterCodes.at) {
839-
isJsDocTagName = true;
841+
requestJsDocTagName = true;
840842
}
841843
else {
844+
// When completion is requested without "@", we will have check to make sure that
845+
// there are no comments prefix the request position. We will only allow "*" and space.
846+
// e.g
847+
// /** |c| /*
848+
//
849+
// /**
850+
// |c|
851+
// */
852+
//
853+
// /**
854+
// * |c|
855+
// */
856+
//
857+
// /**
858+
// * |c|
859+
// */
842860
const lineStart = getLineStartPositionForPosition(position, sourceFile);
843-
shouldAppendAtSignBeforeJsDocTagName = sourceFile.text.substr(lineStart, position).indexOf("@") === -1;
844-
845-
if (shouldAppendAtSignBeforeJsDocTagName) {
846-
isJsDocTagName = true;
847-
}
861+
requestJsDocTag = !(sourceFile.text.substr(lineStart, position).match(/[^\*|\s|(/\*\*)]/));
848862
}
849863
}
850864

@@ -855,7 +869,7 @@ namespace ts.Completions {
855869
const tag = getJsDocTagAtPosition(sourceFile, position);
856870
if (tag) {
857871
if (tag.tagName.pos <= position && position <= tag.tagName.end) {
858-
isJsDocTagName = true;
872+
requestJsDocTagName = true;
859873
}
860874

861875
switch (tag.kind) {
@@ -870,8 +884,8 @@ namespace ts.Completions {
870884
}
871885
}
872886

873-
if (isJsDocTagName || shouldAppendAtSignBeforeJsDocTagName) {
874-
return { symbols: undefined, isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, location: undefined, isRightOfDot: false, isJsDocTagName, shouldAppendAtSignBeforeJsDocTagName };
887+
if (requestJsDocTagName || requestJsDocTag) {
888+
return { symbols: undefined, isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, location: undefined, isRightOfDot: false, requestJsDocTagName, requestJsDocTag };
875889
}
876890

877891
if (!insideJsDocTagExpression) {
@@ -999,7 +1013,7 @@ namespace ts.Completions {
9991013

10001014
log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
10011015

1002-
return { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot: (isRightOfDot || isRightOfOpenTag), isJsDocTagName, shouldAppendAtSignBeforeJsDocTagName };
1016+
return { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot: (isRightOfDot || isRightOfOpenTag), requestJsDocTagName, requestJsDocTag };
10031017

10041018
function getTypeScriptMemberSymbols(): void {
10051019
// Right of dot member completion list

src/services/jsDoc.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts.JsDoc {
4343
"version"
4444
];
4545
let jsDocTagNameCompletionEntries: CompletionEntry[];
46-
let jsDocTagNameWithAtSignCompletionEntries: CompletionEntry[];
46+
let jsDocTagCompletionEntries: CompletionEntry[];
4747

4848
export function getJsDocCommentsFromDeclarations(declarations: Declaration[]) {
4949
// Only collect doc comments from duplicate declarations once:
@@ -89,27 +89,26 @@ namespace ts.JsDoc {
8989
return undefined;
9090
}
9191

92-
export function getAllJsDocCompletionEntries(shouldAppendAtSign: boolean): CompletionEntry[] {
93-
if (!shouldAppendAtSign) {
94-
return jsDocTagNameCompletionEntries || (jsDocTagNameCompletionEntries = ts.map(jsDocTagNames, tagName => {
95-
return {
96-
name: tagName,
97-
kind: ScriptElementKind.keyword,
98-
kindModifiers: "",
99-
sortText: "0",
100-
};
101-
}));
102-
}
103-
else {
104-
return jsDocTagNameWithAtSignCompletionEntries || (jsDocTagNameWithAtSignCompletionEntries = ts.map(jsDocTagNames, tagName => {
105-
return {
106-
name: `@${tagName}`,
107-
kind: ScriptElementKind.keyword,
108-
kindModifiers: "",
109-
sortText: "0"
110-
}
111-
}));
112-
}
92+
export function getJSDocTagNameCompletions(): CompletionEntry[] {
93+
return jsDocTagNameCompletionEntries || (jsDocTagNameCompletionEntries = ts.map(jsDocTagNames, tagName => {
94+
return {
95+
name: tagName,
96+
kind: ScriptElementKind.keyword,
97+
kindModifiers: "",
98+
sortText: "0",
99+
};
100+
}));
101+
}
102+
103+
export function getJSDocTagCompletions(): CompletionEntry[] {
104+
return jsDocTagCompletionEntries || (jsDocTagCompletionEntries = ts.map(jsDocTagNames, tagName => {
105+
return {
106+
name: `@${tagName}`,
107+
kind: ScriptElementKind.keyword,
108+
kindModifiers: "",
109+
sortText: "0"
110+
}
111+
}));
113112
}
114113

115114
/**

0 commit comments

Comments
 (0)