getDocCommentTemplateAtPosition: Return result if in empty comment (#26026)
This commit is contained in:
parent
644ceab02f
commit
5e1872f0c0
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
Loading…
Reference in a new issue