diff --git a/src/services/services.ts b/src/services/services.ts index 4cb9e6b994b..954183907bf 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -132,7 +132,7 @@ namespace ts { let emptyArray: any[] = []; - const jsDocTagNames: string[] = [ + const jsDocTagNames = [ "augments", "author", "argument", @@ -2992,7 +2992,7 @@ namespace ts { let tagWithExpression = tag; if (tagWithExpression.typeExpression) { insideJsDocTagExpression = tagWithExpression.typeExpression.pos < position && position < tagWithExpression.typeExpression.end; - }; + } break; } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 67d82f5e425..9d8865be193 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -470,26 +470,27 @@ namespace ts { } /** - * Get the corresponding JSDocTag node if the position is in a jsDoc commet + * Get the corresponding JSDocTag node if the position is in a jsDoc comment */ export function getJsDocTagAtPosition(sourceFile: SourceFile, position: number): JSDocTag { let node = ts.getTokenAtPosition(sourceFile, position); - let jsDocComment: JSDocComment; - if (node.jsDocComment) { - jsDocComment = node.jsDocComment; - } - else { - while (node) { - if (node.kind === SyntaxKind.VariableStatement || - node.kind === SyntaxKind.FunctionDeclaration || - node.kind === SyntaxKind.Parameter) { - jsDocComment = node.jsDocComment; + if (isToken(node)) { + switch (node.kind) { + case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + // if the current token is var, let or const, skip the VariableDeclarationList + node = node.parent.parent; break; - } + default: + node = node.parent; + break; + } + if (!node.jsDocComment) { node = node.parent; } } - + let jsDocComment = node.jsDocComment; if (jsDocComment) { for (let tag of jsDocComment.tags) { if (tag.pos <= position && position <= tag.end) {