From 6428d0fc7dae5801cdaf2d160ac39a3dfc8f0c06 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 26 May 2022 16:00:04 -0700 Subject: Support TS's includeInlayVariableTypeHintsWhenTypeMatchesName setting (#150489) From https://github.com/microsoft/TypeScript/pull/48529 Let users control is variable type inlay hints are suppresed if the variable name matches the type name, such as: ```ts const range = new Range(); ``` --- extensions/typescript-language-features/package.json | 12 ++++++++++++ extensions/typescript-language-features/package.nls.json | 6 ++---- .../src/languageFeatures/fileConfigurationManager.ts | 2 ++ .../src/languageFeatures/inlayHints.ts | 5 +++-- 4 files changed, 19 insertions(+), 6 deletions(-) (limited to 'extensions') diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index 14618b75330..1c3fccddc99 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -301,6 +301,12 @@ "markdownDescription": "%configuration.inlayHints.variableTypes.enabled%", "scope": "resource" }, + "typescript.inlayHints.variableTypes.suppressWhenTypeMatchesName": { + "type": "boolean", + "default": true, + "markdownDescription": "%configuration.inlayHints.variableTypes.suppressWhenTypeMatchesName%", + "scope": "resource" + }, "typescript.inlayHints.propertyDeclarationTypes.enabled": { "type": "boolean", "default": false, @@ -353,6 +359,12 @@ "markdownDescription": "%configuration.inlayHints.variableTypes.enabled%", "scope": "resource" }, + "javascript.inlayHints.variableTypes.suppressWhenTypeMatchesName": { + "type": "boolean", + "default": true, + "markdownDescription": "%configuration.inlayHints.variableTypes.suppressWhenTypeMatchesName%", + "scope": "resource" + }, "javascript.inlayHints.propertyDeclarationTypes.enabled": { "type": "boolean", "default": false, diff --git a/extensions/typescript-language-features/package.nls.json b/extensions/typescript-language-features/package.nls.json index 5a91821e729..513bcfbaaa1 100644 --- a/extensions/typescript-language-features/package.nls.json +++ b/extensions/typescript-language-features/package.nls.json @@ -88,10 +88,7 @@ "message": "Enable/disable inlay hints for parameter names:\n```typescript\n\nparseInt(/* str: */ '123', /* radix: */ 8)\n \n```\nRequires using TypeScript 4.4+ in the workspace.", "comment": "The text inside the ``` block is code and should not be localized." }, - "configuration.inlayHints.parameterNames.suppressWhenArgumentMatchesName": { - "message": "Suppress parameter name hints on arguments whose text is identical to the parameter name.", - "comment": "The text inside the ``` block is code and should not be localized." - }, + "configuration.inlayHints.parameterNames.suppressWhenArgumentMatchesName": "Suppress parameter name hints on arguments whose text is identical to the parameter name.", "configuration.inlayHints.parameterTypes.enabled": { "message": "Enable/disable inlay hints for implicit parameter types:\n```typescript\n\nel.addEventListener('click', e /* :MouseEvent */ => ...)\n \n```\nRequires using TypeScript 4.4+ in the workspace.", "comment": "The text inside the ``` block is code and should not be localized." @@ -100,6 +97,7 @@ "message": "Enable/disable inlay hints for implicit variable types:\n```typescript\n\nconst foo /* :number */ = Date.now();\n \n```\nRequires using TypeScript 4.4+ in the workspace.", "comment": "The text inside the ``` block is code and should not be localized." }, + "configuration.inlayHints.variableTypes.suppressWhenTypeMatchesName": "Suppress type hints on variables whose name is identical to the type name. Requires using TypeScript 4.8+ in the workspace.", "configuration.inlayHints.propertyDeclarationTypes.enabled": { "message": "Enable/disable inlay hints for implicit types on property declarations:\n```typescript\n\nclass Foo {\n\tprop /* :number */ = Date.now();\n}\n \n```\nRequires using TypeScript 4.4+ in the workspace.", "comment": "The text inside the ``` block is code and should not be localized." diff --git a/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts b/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts index be91f9db4c5..c35aa35aee0 100644 --- a/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts +++ b/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts @@ -210,6 +210,7 @@ export class InlayHintSettingNames { static readonly parameterNamesSuppressWhenArgumentMatchesName = 'inlayHints.parameterNames.suppressWhenArgumentMatchesName'; static readonly parameterNamesEnabled = 'inlayHints.parameterTypes.enabled'; static readonly variableTypesEnabled = 'inlayHints.variableTypes.enabled'; + static readonly variableTypesSuppressWhenTypeMatchesName = 'inlayHints.variableTypes.suppressWhenTypeMatchesName'; static readonly propertyDeclarationTypesEnabled = 'inlayHints.propertyDeclarationTypes.enabled'; static readonly functionLikeReturnTypesEnabled = 'inlayHints.functionLikeReturnTypes.enabled'; static readonly enumMemberValuesEnabled = 'inlayHints.enumMemberValues.enabled'; @@ -221,6 +222,7 @@ export function getInlayHintsPreferences(config: vscode.WorkspaceConfiguration) includeInlayParameterNameHintsWhenArgumentMatchesName: !config.get(InlayHintSettingNames.parameterNamesSuppressWhenArgumentMatchesName, true), includeInlayFunctionParameterTypeHints: config.get(InlayHintSettingNames.parameterNamesEnabled, false), includeInlayVariableTypeHints: config.get(InlayHintSettingNames.variableTypesEnabled, false), + includeInlayVariableTypeHintsWhenTypeMatchesName: !config.get(InlayHintSettingNames.variableTypesSuppressWhenTypeMatchesName, true), includeInlayPropertyDeclarationTypeHints: config.get(InlayHintSettingNames.propertyDeclarationTypesEnabled, false), includeInlayFunctionLikeReturnTypeHints: config.get(InlayHintSettingNames.functionLikeReturnTypesEnabled, false), includeInlayEnumMemberValueHints: config.get(InlayHintSettingNames.enumMemberValuesEnabled, false), diff --git a/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts b/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts index b3a90b993b0..b0f6d257200 100644 --- a/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts +++ b/extensions/typescript-language-features/src/languageFeatures/inlayHints.ts @@ -15,14 +15,15 @@ import { Position } from '../utils/typeConverters'; import FileConfigurationManager, { getInlayHintsPreferences, InlayHintSettingNames } from './fileConfigurationManager'; -const inlayHintSettingNames = [ +const inlayHintSettingNames = Object.freeze([ InlayHintSettingNames.parameterNamesSuppressWhenArgumentMatchesName, InlayHintSettingNames.parameterNamesEnabled, InlayHintSettingNames.variableTypesEnabled, + InlayHintSettingNames.variableTypesSuppressWhenTypeMatchesName, InlayHintSettingNames.propertyDeclarationTypesEnabled, InlayHintSettingNames.functionLikeReturnTypesEnabled, InlayHintSettingNames.enumMemberValuesEnabled, -]; +]); class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHintsProvider { -- cgit v1.2.3