mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(49426): Object method snippet completions incorrectly add this parameters (#49757)
* fix(49426): omit this parameter * add OmitThisParameter to TypeFormatFlags * change flag value
This commit is contained in:
@@ -5868,7 +5868,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
|
||||
const expandedParams = getExpandedParameters(signature, /*skipUnionExpanding*/ true)[0];
|
||||
// If the expanded parameter list had a variadic in a non-trailing position, don't expand it
|
||||
const parameters = (some(expandedParams, p => p !== expandedParams[expandedParams.length - 1] && !!(getCheckFlags(p) & CheckFlags.RestParameter)) ? signature.parameters : expandedParams).map(parameter => symbolToParameterDeclaration(parameter, context, kind === SyntaxKind.Constructor, options?.privateSymbolVisitor, options?.bundledImports));
|
||||
const thisParameter = tryGetThisParameterDeclaration(signature, context);
|
||||
const thisParameter = context.flags & NodeBuilderFlags.OmitThisParameter ? undefined : tryGetThisParameterDeclaration(signature, context);
|
||||
if (thisParameter) {
|
||||
parameters.unshift(thisParameter);
|
||||
}
|
||||
|
||||
@@ -4664,10 +4664,11 @@ namespace ts {
|
||||
UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases
|
||||
UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type
|
||||
NoTypeReduction = 1 << 29, // Don't call getReducedType
|
||||
OmitThisParameter = 1 << 25,
|
||||
|
||||
// Error handling
|
||||
AllowThisInObjectLiteral = 1 << 15,
|
||||
AllowQualifiedNameInPlaceOfIdentifier = 1 << 16,
|
||||
AllowQualifiedNameInPlaceOfIdentifier = 1 << 16,
|
||||
/** @deprecated AllowQualifedNameInPlaceOfIdentifier. Use AllowQualifiedNameInPlaceOfIdentifier instead. */
|
||||
AllowQualifedNameInPlaceOfIdentifier = AllowQualifiedNameInPlaceOfIdentifier,
|
||||
AllowAnonymousIdentifier = 1 << 17,
|
||||
@@ -4709,6 +4710,7 @@ namespace ts {
|
||||
UseAliasDefinedOutsideCurrentScope = 1 << 14, // For a `type T = ... ` defined in a different file, write `T` instead of its value, even though `T` can't be accessed in the current scope.
|
||||
UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type
|
||||
NoTypeReduction = 1 << 29, // Don't call getReducedType
|
||||
OmitThisParameter = 1 << 25,
|
||||
|
||||
// Error Handling
|
||||
AllowUniqueESSymbolType = 1 << 20, // This is bit 20 to align with the same bit in `NodeBuilderFlags`
|
||||
@@ -4728,7 +4730,7 @@ namespace ts {
|
||||
NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | UseStructuralFallback | WriteTypeArgumentsOfSignature |
|
||||
UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral |
|
||||
UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias |
|
||||
UseSingleQuotesForStringLiteralType | NoTypeReduction,
|
||||
UseSingleQuotesForStringLiteralType | NoTypeReduction | OmitThisParameter
|
||||
}
|
||||
|
||||
export const enum SymbolFormatFlags {
|
||||
|
||||
@@ -1126,7 +1126,7 @@ namespace ts.Completions {
|
||||
const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName;
|
||||
const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
|
||||
const quotePreference = getQuotePreference(sourceFile, preferences);
|
||||
const builderFlags = quotePreference === QuotePreference.Single ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : undefined;
|
||||
const builderFlags = NodeBuilderFlags.OmitThisParameter | (quotePreference === QuotePreference.Single ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : NodeBuilderFlags.None);
|
||||
|
||||
switch (declaration.kind) {
|
||||
case SyntaxKind.PropertySignature:
|
||||
|
||||
+3
-1
@@ -2420,6 +2420,7 @@ declare namespace ts {
|
||||
UseAliasDefinedOutsideCurrentScope = 16384,
|
||||
UseSingleQuotesForStringLiteralType = 268435456,
|
||||
NoTypeReduction = 536870912,
|
||||
OmitThisParameter = 33554432,
|
||||
AllowThisInObjectLiteral = 32768,
|
||||
AllowQualifiedNameInPlaceOfIdentifier = 65536,
|
||||
/** @deprecated AllowQualifedNameInPlaceOfIdentifier. Use AllowQualifiedNameInPlaceOfIdentifier instead. */
|
||||
@@ -2450,6 +2451,7 @@ declare namespace ts {
|
||||
UseAliasDefinedOutsideCurrentScope = 16384,
|
||||
UseSingleQuotesForStringLiteralType = 268435456,
|
||||
NoTypeReduction = 536870912,
|
||||
OmitThisParameter = 33554432,
|
||||
AllowUniqueESSymbolType = 1048576,
|
||||
AddUndefined = 131072,
|
||||
WriteArrowStyleSignature = 262144,
|
||||
@@ -2458,7 +2460,7 @@ declare namespace ts {
|
||||
InFirstTypeArgument = 4194304,
|
||||
InTypeAlias = 8388608,
|
||||
/** @deprecated */ WriteOwnNameForAnyLike = 0,
|
||||
NodeBuilderFlagsMask = 814775659
|
||||
NodeBuilderFlagsMask = 848330091
|
||||
}
|
||||
export enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
|
||||
+3
-1
@@ -2420,6 +2420,7 @@ declare namespace ts {
|
||||
UseAliasDefinedOutsideCurrentScope = 16384,
|
||||
UseSingleQuotesForStringLiteralType = 268435456,
|
||||
NoTypeReduction = 536870912,
|
||||
OmitThisParameter = 33554432,
|
||||
AllowThisInObjectLiteral = 32768,
|
||||
AllowQualifiedNameInPlaceOfIdentifier = 65536,
|
||||
/** @deprecated AllowQualifedNameInPlaceOfIdentifier. Use AllowQualifiedNameInPlaceOfIdentifier instead. */
|
||||
@@ -2450,6 +2451,7 @@ declare namespace ts {
|
||||
UseAliasDefinedOutsideCurrentScope = 16384,
|
||||
UseSingleQuotesForStringLiteralType = 268435456,
|
||||
NoTypeReduction = 536870912,
|
||||
OmitThisParameter = 33554432,
|
||||
AllowUniqueESSymbolType = 1048576,
|
||||
AddUndefined = 131072,
|
||||
WriteArrowStyleSignature = 262144,
|
||||
@@ -2458,7 +2460,7 @@ declare namespace ts {
|
||||
InFirstTypeArgument = 4194304,
|
||||
InTypeAlias = 8388608,
|
||||
/** @deprecated */ WriteOwnNameForAnyLike = 0,
|
||||
NodeBuilderFlagsMask = 814775659
|
||||
NodeBuilderFlagsMask = 848330091
|
||||
}
|
||||
export enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @newline: LF
|
||||
// @Filename: a.ts
|
||||
////interface IFoo {
|
||||
//// bar(this: IFoo): void;
|
||||
////}
|
||||
////const obj: IFoo = {
|
||||
//// /*1*/
|
||||
////}
|
||||
|
||||
verify.completions({
|
||||
marker: "1",
|
||||
preferences: {
|
||||
includeCompletionsWithInsertText: true,
|
||||
includeCompletionsWithSnippetText: true,
|
||||
includeCompletionsWithObjectLiteralMethodSnippets: true,
|
||||
useLabelDetailsInCompletionEntries: true,
|
||||
},
|
||||
includes: [
|
||||
{
|
||||
name: "bar",
|
||||
sortText: completion.SortText.ObjectLiteralProperty(completion.SortText.LocationPriority, "bar"),
|
||||
insertText: undefined,
|
||||
},
|
||||
{
|
||||
name: "bar",
|
||||
sortText: completion.SortText.SortBelow(
|
||||
completion.SortText.ObjectLiteralProperty(completion.SortText.LocationPriority, "bar")),
|
||||
source: completion.CompletionSource.ObjectLiteralMethodSnippet,
|
||||
isSnippet: true,
|
||||
insertText: "bar() {\n $0\n},",
|
||||
labelDetails: {
|
||||
detail: "()",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user