From 1b282cda1de630186e9ad4aa20f30dfd66bb9c9b Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 27 Jan 2016 14:07:32 -0800 Subject: [PATCH 1/2] Parse JSDoc comments for ES6 class constructors and methods Fixes #6646 --- src/compiler/parser.ts | 4 ++-- .../fourslash/getJavaScriptCompletions16.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptCompletions16.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 57bd9860d12..1ee74603825 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4778,7 +4778,7 @@ namespace ts { parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, Diagnostics.or_expected); - return finishNode(node); + return addJSDocComment(finishNode(node)); } function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, asteriskToken: Node, name: PropertyName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { @@ -4792,7 +4792,7 @@ namespace ts { const isAsync = !!(method.flags & NodeFlags.Async); fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); - return finishNode(method); + return addJSDocComment(finishNode(method)); } function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, name: PropertyName, questionToken: Node): ClassElement { diff --git a/tests/cases/fourslash/getJavaScriptCompletions16.ts b/tests/cases/fourslash/getJavaScriptCompletions16.ts new file mode 100644 index 00000000000..07c50d3f892 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions16.ts @@ -0,0 +1,18 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// "use strict"; +//// +//// class Something { +//// +//// /** +//// * @param {number} a +//// */ +//// constructor(a, b) { +//// a./**/ +//// } +//// } + +goTo.marker(); +verify.completionListContains('toFixed', undefined, undefined, 'method'); From 3dfd378b7e0cf6fb685c63410439fdd12a672fb9 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 1 Feb 2016 21:20:37 -0800 Subject: [PATCH 2/2] Add some tests --- .../fourslash/getJavaScriptCompletions16.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/getJavaScriptCompletions16.ts b/tests/cases/fourslash/getJavaScriptCompletions16.ts index 07c50d3f892..4d4b76d98d6 100644 --- a/tests/cases/fourslash/getJavaScriptCompletions16.ts +++ b/tests/cases/fourslash/getJavaScriptCompletions16.ts @@ -10,9 +10,26 @@ //// * @param {number} a //// */ //// constructor(a, b) { -//// a./**/ +//// a/*body*/ +//// } +//// +//// /** +//// * @param {number} a +//// */ +//// method(a) { +//// a/*method*/ //// } //// } +//// let x = new Something(/*sig*/); -goTo.marker(); +goTo.marker('body'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); +edit.backspace(); + +goTo.marker('sig'); +verify.currentSignatureHelpIs('Something(a: number, b: any): Something'); + +goTo.marker('method'); +edit.insert('.'); verify.completionListContains('toFixed', undefined, undefined, 'method');