@@ -16,11 +16,16 @@ namespace ts.Completions {
16
16
return undefined ;
17
17
}
18
18
19
- const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isJsDocTagName , shouldAppendAtSignBeforeJsDocTagName } = completionData ;
19
+ const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, requestJsDocTagName , requestJsDocTag } = completionData ;
20
20
21
- if ( isJsDocTagName ) {
21
+ if ( requestJsDocTagName ) {
22
22
// 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 ( ) } ;
24
29
}
25
30
26
31
const entries : CompletionEntry [ ] = [ ] ;
@@ -54,7 +59,7 @@ namespace ts.Completions {
54
59
}
55
60
56
61
// Add keywords if this is not a member completion list
57
- if ( ! isMemberCompletion && ! isJsDocTagName ) {
62
+ if ( ! isMemberCompletion && ! ( requestJsDocTag && requestJsDocTagName ) ) {
58
63
addRange ( entries , keywordCompletions ) ;
59
64
}
60
65
@@ -814,13 +819,10 @@ namespace ts.Completions {
814
819
function getCompletionData ( typeChecker : TypeChecker , log : ( message : string ) => void , sourceFile : SourceFile , position : number ) {
815
820
const isJavaScriptFile = isSourceFileJavaScript ( sourceFile ) ;
816
821
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 ;
824
826
825
827
let start = timestamp ( ) ;
826
828
const currentToken = getTokenAtPosition ( sourceFile , position ) ;
@@ -836,15 +838,27 @@ namespace ts.Completions {
836
838
// The current position is next to the '@' sign, when no tag name being provided yet.
837
839
// Provide a full list of tag names
838
840
if ( sourceFile . text . charCodeAt ( position - 1 ) === CharacterCodes . at ) {
839
- isJsDocTagName = true ;
841
+ requestJsDocTagName = true ;
840
842
}
841
843
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
+ // */
842
860
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 | ( / \* \* ) ] / ) ) ;
848
862
}
849
863
}
850
864
@@ -855,7 +869,7 @@ namespace ts.Completions {
855
869
const tag = getJsDocTagAtPosition ( sourceFile , position ) ;
856
870
if ( tag ) {
857
871
if ( tag . tagName . pos <= position && position <= tag . tagName . end ) {
858
- isJsDocTagName = true ;
872
+ requestJsDocTagName = true ;
859
873
}
860
874
861
875
switch ( tag . kind ) {
@@ -870,8 +884,8 @@ namespace ts.Completions {
870
884
}
871
885
}
872
886
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 } ;
875
889
}
876
890
877
891
if ( ! insideJsDocTagExpression ) {
@@ -999,7 +1013,7 @@ namespace ts.Completions {
999
1013
1000
1014
log ( "getCompletionData: Semantic work: " + ( timestamp ( ) - semanticStart ) ) ;
1001
1015
1002
- return { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot : ( isRightOfDot || isRightOfOpenTag ) , isJsDocTagName , shouldAppendAtSignBeforeJsDocTagName } ;
1016
+ return { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot : ( isRightOfDot || isRightOfOpenTag ) , requestJsDocTagName , requestJsDocTag } ;
1003
1017
1004
1018
function getTypeScriptMemberSymbols ( ) : void {
1005
1019
// Right of dot member completion list
0 commit comments