From ae4b29c559280e1447eb07928f637652eb7c13cb Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 6 Aug 2020 09:11:46 -0700 Subject: [PATCH] Skip triple-slash references --- src/compiler/parser.ts | 18 ++++++++++++++---- .../fourslash/signatureHelpTripleSlashJSDoc.ts | 7 ++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a4e19f3674e..dc4c0a58170 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7215,6 +7215,7 @@ namespace ts { } function parseJSDocCommentWorker(startOrRanges: number | CommentRange[] = 0, length: number | undefined): JSDoc | undefined { + // TODO: Probably should save a boolean isTripleSlash at the beginning and make all the nested functions change their behaviour. const content = sourceText; // TODO: Why alias this? const comments: string[] = []; let tags: JSDocTag[]; @@ -7223,16 +7224,25 @@ namespace ts { if (Array.isArray(startOrRanges)) { if (!startOrRanges.length) return undefined; const ranges = startOrRanges; - for (const comment of ranges) { - const { pos: start, end } = comment; + let currentTag: JSDocTag | undefined; // TODO: Probably can use tags + for (const { pos: start, end } of ranges) { + if (isRecognizedTripleSlashComment(content, start, end)) continue; const length = end - start; scanner.scanRange(start + 3, length - 3, () => { while (nextTokenJSDoc() !== SyntaxKind.EndOfFileToken) { if (token() === SyntaxKind.AtToken) { - addTag(parseTag(0)); + addTag(currentTag); + currentTag = parseTag(0); } else { - comments.push(scanner.getTokenText()); + if (currentTag) { + // this doesn't update currentTag.end, which will cause problems later + // I think that parseXTag will have to return unfinished tags or something. + (currentTag as any).comment = (currentTag.comment || "") + scanner.getTokenText() + } + else { + comments.push(scanner.getTokenText()); + } } } }); diff --git a/tests/cases/fourslash/signatureHelpTripleSlashJSDoc.ts b/tests/cases/fourslash/signatureHelpTripleSlashJSDoc.ts index 7dc096d4782..23feb8652dc 100644 --- a/tests/cases/fourslash/signatureHelpTripleSlashJSDoc.ts +++ b/tests/cases/fourslash/signatureHelpTripleSlashJSDoc.ts @@ -9,9 +9,10 @@ //// /// multiline comment //// /// //// /// @return {number} -//// function add1(n) { +//// function add1(/*2*/n) { //// return n + 1 //// } -//// add1/*1*/ +//// add1/*1*/(12) -verify.quickInfoAt('1', 'function add1(n: number): number', ' Adds one') +verify.quickInfoAt('1', 'function add1(n: number): number', ' Adds one ') +verify.quickInfoAt('2', '(parameter) n: number', '- this is a long, multiline comment ')