From 733d7aed975fab908b63d980f0426d53004828c3 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 16 Feb 2023 00:33:39 +0200 Subject: [PATCH] fix(52749): Assertion failure in derived class completion (#52787) --- src/services/codefixes/helpers.ts | 2 +- .../completionsClassMembers4.baseline | 319 ++++++++++++++++++ .../fourslash/completionsClassMembers4.ts | 25 ++ 3 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/completionsClassMembers4.baseline create mode 100644 tests/cases/fourslash/completionsClassMembers4.ts diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 2a30b8d289a..154f1ad1b57 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -751,7 +751,7 @@ function createMethodImplementingSignatures( function getReturnTypeFromSignatures(signatures: readonly Signature[], checker: TypeChecker, context: TypeConstructionContext, enclosingDeclaration: ClassLikeDeclaration): TypeNode | undefined { if (length(signatures)) { const type = checker.getUnionType(map(signatures, checker.getReturnTypeOfSignature)); - return checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context)); + return checker.typeToTypeNode(type, enclosingDeclaration, NodeBuilderFlags.NoTruncation, getNoopSymbolTrackerWithResolver(context)); } } diff --git a/tests/baselines/reference/completionsClassMembers4.baseline b/tests/baselines/reference/completionsClassMembers4.baseline new file mode 100644 index 00000000000..ecbe05f1c20 --- /dev/null +++ b/tests/baselines/reference/completionsClassMembers4.baseline @@ -0,0 +1,319 @@ +=== /foo.ts === +// export class Observable { +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// pipe(): Observable; +// } +// export class Foo extends Observable { +// +// ^ +// | ---------------------------------------------------------------------- +// | abstract +// | accessor +// | async +// | constructor +// | declare +// | get +// | override +// | private +// | protected +// | public +// | readonly +// | set +// | static +// | (method) Observable.pipe(): Observable (+10 overloads) +// | ---------------------------------------------------------------------- +// } + +[ + { + "marker": { + "fileName": "/foo.ts", + "position": 543, + "name": "" + }, + "item": { + "flags": 0, + "isGlobalCompletion": false, + "isMemberCompletion": true, + "isNewIdentifierLocation": true, + "entries": [ + { + "name": "abstract", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "abstract", + "kind": "keyword" + } + ] + }, + { + "name": "accessor", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "accessor", + "kind": "keyword" + } + ] + }, + { + "name": "async", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "async", + "kind": "keyword" + } + ] + }, + { + "name": "constructor", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "constructor", + "kind": "keyword" + } + ] + }, + { + "name": "declare", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "declare", + "kind": "keyword" + } + ] + }, + { + "name": "get", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "get", + "kind": "keyword" + } + ] + }, + { + "name": "override", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "override", + "kind": "keyword" + } + ] + }, + { + "name": "private", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "private", + "kind": "keyword" + } + ] + }, + { + "name": "protected", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "protected", + "kind": "keyword" + } + ] + }, + { + "name": "public", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "public", + "kind": "keyword" + } + ] + }, + { + "name": "readonly", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "readonly", + "kind": "keyword" + } + ] + }, + { + "name": "set", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "set", + "kind": "keyword" + } + ] + }, + { + "name": "static", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "static", + "kind": "keyword" + } + ] + }, + { + "name": "pipe", + "kind": "method", + "kindModifiers": "", + "sortText": "17", + "insertText": "pipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable;\npipe(): Observable | Observable | Observable | Observable | Observable | Observable | Observable | Observable | Observable | Observable | Observable {\n $0\n}", + "isSnippet": true, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "method", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Observable", + "kind": "className" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "any", + "kind": "keyword" + }, + { + "text": ">", + "kind": "punctuation" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "pipe", + "kind": "methodName" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Observable", + "kind": "className" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "any", + "kind": "keyword" + }, + { + "text": ">", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "+", + "kind": "operator" + }, + { + "text": "10", + "kind": "numericLiteral" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "overloads", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + } + ], + "documentation": [] + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/completionsClassMembers4.ts b/tests/cases/fourslash/completionsClassMembers4.ts new file mode 100644 index 00000000000..fcefc946445 --- /dev/null +++ b/tests/cases/fourslash/completionsClassMembers4.ts @@ -0,0 +1,25 @@ +/// + +// @filename: /foo.ts +////export class Observable { +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +//// pipe(): Observable; +////} +////export class Foo extends Observable { +//// /**/ +////} + +verify.baselineCompletions({ + includeCompletionsWithInsertText: true, + includeCompletionsWithSnippetText: true, + includeCompletionsWithClassMemberSnippets: true, +});