Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8800,6 +8800,7 @@ namespace ts {
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
readonly includeInlayFunctionParameterTypeHints?: boolean,
readonly includeInlayVariableTypeHints?: boolean;
readonly includeInlayVariableTypeHintsWhenTypeMatchesName?: boolean;
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
readonly includeInlayEnumMemberValueHints?: boolean;
Expand Down
9 changes: 5 additions & 4 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -3414,7 +3414,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"]`.
Expand Down Expand Up @@ -3464,6 +3464,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;
Expand Down
4 changes: 4 additions & 0 deletions src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,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;
Expand Down Expand Up @@ -9696,6 +9697,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;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4119,6 +4119,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;
Expand Down
1 change: 1 addition & 0 deletions tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/inlayHintsShouldWork67.ts
Original file line number Diff line number Diff line change
@@ -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
});