mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
fix(47562): Add option to suppress type hint if variable name matches type name (#48529)
* fix(47562): Add option to suppress type hint if variable name matches type * Remove the unnecessary debug code * Re-run gulp runtests * Use equateStringsCaseInsensitive to compare strings
This commit is contained in:
parent
b57d6e1df4
commit
1fb2b2d70f
@ -8813,6 +8813,7 @@ namespace ts {
|
||||
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
|
||||
readonly includeInlayFunctionParameterTypeHints?: boolean,
|
||||
readonly includeInlayVariableTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
|
||||
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
|
||||
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
|
||||
readonly includeInlayEnumMemberValueHints?: boolean;
|
||||
|
||||
@ -728,7 +728,7 @@ namespace ts.server.protocol {
|
||||
}
|
||||
|
||||
// All we need is the `success` and `message` fields of Response.
|
||||
export interface ApplyCodeActionCommandResponse extends Response {}
|
||||
export interface ApplyCodeActionCommandResponse extends Response { }
|
||||
|
||||
export interface FileRangeRequestArgs extends FileRequestArgs {
|
||||
/**
|
||||
@ -1067,7 +1067,7 @@ namespace ts.server.protocol {
|
||||
readonly arguments: JsxClosingTagRequestArgs;
|
||||
}
|
||||
|
||||
export interface JsxClosingTagRequestArgs extends FileLocationRequestArgs {}
|
||||
export interface JsxClosingTagRequestArgs extends FileLocationRequestArgs { }
|
||||
|
||||
export interface JsxClosingTagResponse extends Response {
|
||||
readonly body: TextInsertion;
|
||||
@ -2390,7 +2390,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* Human-readable description of the `source` from the CompletionEntry.
|
||||
*/
|
||||
sourceDisplay?: SymbolDisplayPart[];
|
||||
sourceDisplay?: SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
/** @deprecated Prefer CompletionInfoResponse, which supports several top-level fields in addition to the array of entries. */
|
||||
@ -3415,7 +3415,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* Allows completions to be formatted with snippet text, indicated by `CompletionItem["isSnippet"]`.
|
||||
*/
|
||||
readonly includeCompletionsWithSnippetText?: boolean;
|
||||
readonly includeCompletionsWithSnippetText?: boolean;
|
||||
/**
|
||||
* If enabled, the completion list will include completions with invalid identifier names.
|
||||
* For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`.
|
||||
@ -3465,6 +3465,7 @@ namespace ts.server.protocol {
|
||||
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
|
||||
readonly includeInlayFunctionParameterTypeHints?: boolean,
|
||||
readonly includeInlayVariableTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
|
||||
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
|
||||
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
|
||||
readonly includeInlayEnumMemberValueHints?: boolean;
|
||||
|
||||
@ -137,6 +137,10 @@ namespace ts.InlayHints {
|
||||
|
||||
const typeDisplayString = printTypeInSingleLine(declarationType);
|
||||
if (typeDisplayString) {
|
||||
const isVariableNameMatchesType = preferences.includeInlayVariableTypeHintsWhenTypeMatchesName === false && equateStringsCaseInsensitive(decl.name.getText(), typeDisplayString);
|
||||
if (isVariableNameMatchesType) {
|
||||
return;
|
||||
}
|
||||
addTypeHints(typeDisplayString, decl.name.end);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4120,6 +4120,7 @@ declare namespace ts {
|
||||
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
|
||||
readonly includeInlayFunctionParameterTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
|
||||
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
|
||||
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
|
||||
readonly includeInlayEnumMemberValueHints?: boolean;
|
||||
@ -9711,6 +9712,7 @@ declare namespace ts.server.protocol {
|
||||
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
|
||||
readonly includeInlayFunctionParameterTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
|
||||
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
|
||||
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
|
||||
readonly includeInlayEnumMemberValueHints?: boolean;
|
||||
|
||||
@ -4120,6 +4120,7 @@ declare namespace ts {
|
||||
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
|
||||
readonly includeInlayFunctionParameterTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
|
||||
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
|
||||
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
|
||||
readonly includeInlayEnumMemberValueHints?: boolean;
|
||||
|
||||
@ -666,6 +666,7 @@ declare namespace FourSlashInterface {
|
||||
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
|
||||
readonly includeInlayFunctionParameterTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHints?: boolean;
|
||||
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
|
||||
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
|
||||
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
|
||||
readonly includeInlayEnumMemberValueHints?: boolean;
|
||||
|
||||
24
tests/cases/fourslash/inlayHintsShouldWork67.ts
Normal file
24
tests/cases/fourslash/inlayHintsShouldWork67.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// type Client = {};
|
||||
//// function getClient(): Client { return {}; };
|
||||
//// const client/**/ = getClient();
|
||||
|
||||
const markers = test.markers();
|
||||
|
||||
verify.getInlayHints([
|
||||
{
|
||||
text: ': Client',
|
||||
position: markers[0].position,
|
||||
kind: ts.InlayHintKind.Type,
|
||||
whitespaceBefore: true
|
||||
}
|
||||
], undefined, {
|
||||
includeInlayVariableTypeHints: true,
|
||||
includeInlayVariableTypeHintsWhenTypeMatchesName: true
|
||||
});
|
||||
|
||||
verify.getInlayHints([], undefined, {
|
||||
includeInlayVariableTypeHints: true,
|
||||
includeInlayVariableTypeHintsWhenTypeMatchesName: false
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user