From 00303d53fe865aaed3c50f234842d187a13060fc Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Wed, 25 Oct 2023 11:51:46 -0700 Subject: [PATCH] test cases --- src/services/completions.ts | 2 +- ...mpletionsDotComputedPropertyEnum3.baseline | 303 ++++++++++++++++++ .../completionsDotComputedPropertyEnum3.ts | 66 ++++ 3 files changed, 370 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/completionsDotComputedPropertyEnum3.baseline create mode 100644 tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 38b5ec95729..9351b1f4342 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3769,7 +3769,7 @@ function getCompletionData( function createComputedPropertyAccess(nameSymbol: Symbol, leftMostNameSymbol: Symbol, computedPropertyNameExpression: Expression) { let node: Node | undefined; if (!isTransientSymbol(nameSymbol)) { - node = typeChecker.symbolToEntityName(nameSymbol, /*meaning*/ undefined!, contextToken, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope); + node = typeChecker.symbolToNode(nameSymbol, /*meaning*/ undefined!, contextToken, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope); } else { // Object literals assigned as const diff --git a/tests/baselines/reference/completionsDotComputedPropertyEnum3.baseline b/tests/baselines/reference/completionsDotComputedPropertyEnum3.baseline new file mode 100644 index 00000000000..53d50406509 --- /dev/null +++ b/tests/baselines/reference/completionsDotComputedPropertyEnum3.baseline @@ -0,0 +1,303 @@ +=== /tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts === +// /** +// * Mimicking rxjs to avoid dependency import +// */ +// +// type Observable = { +// subscribe(): Observable +// }; +// +// enum CPEvents { +// CLICK = "click", +// EMSG = "emsg", +// } +// +// // Payloads have been replaced for the repro-case, but they do not matter right now. +// interface CPMappedEvents { +// [CPEvents.EMSG]: unknown; +// } +// +// type CPUnmappedEvents = { +// [K in Exclude]: Event; +// }; +// +// export type CPEventsMap = CPMappedEvents & CPUnmappedEvents; +// +// export type CPObservableEvents = { +// [K in keyof CPEventsMap]: Observable; +// }; +// +// declare const eventObservables: CPObservableEvents; +// eventObservables.; +// ^ +// | ---------------------------------------------------------------------- +// | (property) click: Observable +// | (enum member) CPEvents.EMSG = "emsg" +// | ---------------------------------------------------------------------- +// eventObservables['']; +// +// | ---------------------------------------------------------------------- +// | (property) click: Observable +// | (property) [CPEvents.EMSG]: Observable +// | ---------------------------------------------------------------------- + +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts", + "position": 616, + "name": "a" + }, + "item": { + "flags": 0, + "isGlobalCompletion": false, + "isMemberCompletion": true, + "isNewIdentifierLocation": false, + "entries": [ + { + "name": "click", + "kind": "property", + "kindModifiers": "", + "sortText": "11", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "click", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Observable", + "kind": "aliasName" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "Event", + "kind": "text" + }, + { + "text": ">", + "kind": "punctuation" + } + ], + "documentation": [] + }, + { + "name": "CPEvents.EMSG", + "kind": "enum member", + "kindModifiers": "", + "sortText": "11", + "insertText": "[CPEvents.EMSG]", + "replacementSpan": { + "start": 615, + "length": 1 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "enum member", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "CPEvents", + "kind": "enumName" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "EMSG", + "kind": "enumMemberName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"emsg\"", + "kind": "stringLiteral" + } + ], + "documentation": [] + } + ] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts", + "position": 636, + "name": "b" + }, + "item": { + "isGlobalCompletion": false, + "isMemberCompletion": true, + "isNewIdentifierLocation": false, + "optionalReplacementSpan": { + "start": 636, + "length": 0 + }, + "entries": [ + { + "name": "click", + "kind": "property", + "kindModifiers": "", + "sortText": "11", + "replacementSpan": { + "start": 636, + "length": 0 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "click", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Observable", + "kind": "aliasName" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "Event", + "kind": "text" + }, + { + "text": ">", + "kind": "punctuation" + } + ], + "documentation": [] + }, + { + "name": "emsg", + "kind": "property", + "kindModifiers": "", + "sortText": "11", + "replacementSpan": { + "start": 636, + "length": 0 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "[CPEvents.EMSG]", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Observable", + "kind": "aliasName" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "unknown", + "kind": "keyword" + }, + { + "text": ">", + "kind": "punctuation" + } + ], + "documentation": [] + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts b/tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts new file mode 100644 index 00000000000..e65bdc26703 --- /dev/null +++ b/tests/cases/fourslash/completionsDotComputedPropertyEnum3.ts @@ -0,0 +1,66 @@ +/// + +// Make sure completion shows fully qualified names for enum members +// and literals for mapped proeprties keyed with string literals + +/////** +//// * Mimicking rxjs to avoid dependency import +//// */ +//// +////type Observable = { +//// subscribe(): Observable +////}; +//// +////enum CPEvents { +//// CLICK = "click", +//// EMSG = "emsg", +////} +//// +////// Payloads have been replaced for the repro-case, but they do not matter right now. +////interface CPMappedEvents { +//// [CPEvents.EMSG]: unknown; +////} +//// +////type CPUnmappedEvents = { +//// [K in Exclude]: Event; +////}; +//// +////export type CPEventsMap = CPMappedEvents & CPUnmappedEvents; +//// +////export type CPObservableEvents = { +//// [K in keyof CPEventsMap]: Observable; +////}; +//// +////declare const eventObservables: CPObservableEvents; +////eventObservables./*a*/; +////eventObservables['/*b*/']; + +verify.completions({ + marker: "a", + unsorted: [ + { name: "click" }, + { name: "CPEvents.EMSG", insertText: "[CPEvents.EMSG]" }, + ], + preferences: { includeCompletionsWithInsertText: true } +}); + +verify.completions({ + marker: "a", + unsorted: [ + { name: "click" }, + { name: "emsg" }, + ], + preferences: { includeCompletionsWithInsertText: false } +}); + +verify.completions({ + marker: "b", + unsorted: [ + { name: "click" }, + { name: "emsg" }, + ] +}); + +verify.baselineCompletions({ + includeCompletionsWithInsertText: true, +}); \ No newline at end of file