getDocCommentTemplateAtPosition: Return result if in empty comment (#26026)

This commit is contained in:
Andy 2018-07-27 17:34:16 -07:00 committed by GitHub
parent 644ceab02f
commit 5e1872f0c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View file

@ -272,14 +272,16 @@ namespace ts.JsDoc {
*/
export function getDocCommentTemplateAtPosition(newLine: string, sourceFile: SourceFile, position: number): TextInsertion | undefined {
// Check if in a context where we don't want to perform any insertion
if (isInString(sourceFile, position) || isInComment(sourceFile, position) || hasDocComment(sourceFile, position)) {
const tokenAtPos = getTokenAtPosition(sourceFile, position);
const existingDocComment = findAncestor(tokenAtPos, isJSDoc);
if (existingDocComment && (existingDocComment.comment !== undefined || length(existingDocComment.tags))) {
// Non-empty comment already exists.
return undefined;
}
const tokenAtPos = getTokenAtPosition(sourceFile, position);
const tokenStart = tokenAtPos.getStart(sourceFile);
if (!tokenAtPos || tokenStart < position) {
// Don't provide a doc comment template based on a *previous* node. (But an existing empty jsdoc comment will likely start before `position`.)
if (!existingDocComment && tokenStart < position) {
return undefined;
}

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
/////** /**/ */
////function f(p) { return p; }
////
/////** Doc/*1*/ */
////function g(p) { return p; }
verify.docCommentTemplateAt("", /*newTextOffset*/ 8,
`/**
*
* @param p
*/`);
verify.noDocCommentTemplateAt("1");