Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5239,7 +5239,7 @@ function getCompletionData(
* @returns Symbols to be suggested in an class element depending on existing memebers and symbol flags
*/
function filterClassMembersList(baseSymbols: readonly Symbol[], existingMembers: readonly ClassElement[], currentClassElementModifierFlags: ModifierFlags): Symbol[] {
const existingMemberNames = new Set<__String>();
const existingMemberNames = new Set(["prototype" as __String]); // always exclude 'prototype' from completions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, this only has to be excluded when the completion request is for a static member... but I feel this is enough and it's not worth adding an extra parameter to filterClassMembersList to cover for this distinction here

for (const m of existingMembers) {
// Ignore omitted expressions for missing members
if (
Expand Down Expand Up @@ -5274,7 +5274,6 @@ function getCompletionData(

return baseSymbols.filter(propertySymbol =>
!existingMemberNames.has(propertySymbol.escapedName) &&
!!propertySymbol.declarations &&
!(getDeclarationModifierFlagsFromSymbol(propertySymbol) & ModifierFlags.Private) &&
!(propertySymbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(propertySymbol.valueDeclaration))
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />

//// type Base = {
//// [K in "foo" | "bar"]: K;
//// };
////
//// class Cls implements Base { /*1*/ }

verify.completions({
marker: "1",
includes: ["foo", "bar"],
isNewIdentifierLocation: true,
});

verify.completions({
marker: "1",
includes: [
{
name: "foo",
insertText: `foo: "foo";`,
filterText: "foo",
},
{
name: "bar",
insertText: `bar: "bar";`,
filterText: "bar",
},
],
isNewIdentifierLocation: true,
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/// <reference path="fourslash.ts" />

// https://github.com/microsoft/TypeScript/issues/62689

//// type EventType = "start" | "foo" | "bar" | "fooBar" | "end";
////
//// type EventDataType<T extends EventType> = T extends "fooBar"
//// ? { foo: string; bar: number }
//// : T extends "foo"
//// ? { foo: string }
//// : T extends "bar"
//// ? { bar: number }
//// : T extends EventType
//// ? Record<string, any>
//// : never;
////
//// type ListenerFunction<T extends EventType> = (
//// context: any,
//// data: EventDataType<T>,
//// ) => void | Promise<void>;
////
//// type EvtListenerMethods = {
//// [K in EventType as `on${Capitalize<K>}`]?: ListenerFunction<K>;
//// };
////
//// class A implements EvtListenerMethods {
//// onFoo(context: any, data: EventDataType<"foo">) {}
//// onBar(context: any, data: { abcd: any }) {}
//// /*1*/
//// }
////
//// interface EvtListener extends EvtListenerMethods {}
////
//// class B implements EvtListener {
//// onFoo(context: any, data: EventDataType<"foo">) {}
//// onBar(context: any, data: { abcd: any }) {}
//// /*2*/
//// }
////
//// interface EvtListenerHardcoded {
//// onStart?: ListenerFunction<"start">;
//// onFooBar?: ListenerFunction<"fooBar">;
//// onFoo?: ListenerFunction<"foo">;
//// onBar?: ListenerFunction<"bar">;
//// onEnd?: ListenerFunction<"end">;
//// }
////
//// class C implements EvtListenerHardcoded {
//// onFoo(context: any, data: EventDataType<"foo">) {}
//// onBar(context: any, data: { abcd: any }) {}
//// /*3*/
//// }

verify.completions({
marker: ["1", "2", "3"],
includes: ["onStart", "onEnd", "onFooBar"],
excludes: ["onFoo", "onBar"],
isNewIdentifierLocation: true,
});

verify.completions({
marker: ["1", "2", "3"],
includes: [
{
name: "onStart",
insertText: `onStart?: ListenerFunction<"start">;`,
filterText: "onStart",
},
{
name: "onEnd",
insertText: `onEnd?: ListenerFunction<"end">;`,
filterText: "onEnd",
},
{
name: "onFooBar",
insertText: `onFooBar?: ListenerFunction<"fooBar">;`,
filterText: "onFooBar",
},
],
excludes: ["onFoo", "onBar"],
isNewIdentifierLocation: true,
preferences: {
includeCompletionsWithClassMemberSnippets: true,
includeCompletionsWithInsertText: true,
},
});