mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
@@ -10,6 +10,7 @@ import { isTypeScriptDocument } from '../configuration/languageIds';
|
||||
import { API } from '../tsServer/api';
|
||||
import type * as Proto from '../tsServer/protocol/protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { readUnifiedConfig } from '../utils/configuration';
|
||||
import { Disposable } from '../utils/dispose';
|
||||
import { equals } from '../utils/objects';
|
||||
import { ResourceMap } from '../utils/resourceMap';
|
||||
@@ -206,7 +207,7 @@ export default class FileConfigurationManager extends Disposable {
|
||||
disableLineTextInReferences: true,
|
||||
interactiveInlayHints: true,
|
||||
includeCompletionsForModuleExports: config.get<boolean>('suggest.autoImports'),
|
||||
...getInlayHintsPreferences(config),
|
||||
...getInlayHintsPreferences(document, isTypeScriptDocument(document) ? 'typescript' : 'javascript'),
|
||||
...this.getOrganizeImportsPreferences(preferencesConfig),
|
||||
maximumHoverLength: this.getMaximumHoverLength(document),
|
||||
};
|
||||
@@ -274,31 +275,32 @@ function withDefaultAsUndefined<T, O extends T>(value: T, def: O): Exclude<T, O>
|
||||
return value === def ? undefined : value as Exclude<T, O>;
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
export const InlayHintSettingNames = Object.freeze({
|
||||
parameterNamesEnabled: 'inlayHints.parameterNames.enabled',
|
||||
parameterNamesSuppressWhenArgumentMatchesName: 'inlayHints.parameterNames.suppressWhenArgumentMatchesName',
|
||||
parameterTypesEnabled: 'inlayHints.parameterTypes.enabled',
|
||||
variableTypesEnabled: 'inlayHints.variableTypes.enabled',
|
||||
variableTypesSuppressWhenTypeMatchesName: 'inlayHints.variableTypes.suppressWhenTypeMatchesName',
|
||||
propertyDeclarationTypesEnabled: 'inlayHints.propertyDeclarationTypes.enabled',
|
||||
functionLikeReturnTypesEnabled: 'inlayHints.functionLikeReturnTypes.enabled',
|
||||
enumMemberValuesEnabled: 'inlayHints.enumMemberValues.enabled',
|
||||
});
|
||||
|
||||
export function getInlayHintsPreferences(config: vscode.WorkspaceConfiguration) {
|
||||
export function getInlayHintsPreferences(scope: vscode.ConfigurationScope, fallbackSection: string) {
|
||||
return {
|
||||
includeInlayParameterNameHints: getInlayParameterNameHintsPreference(config),
|
||||
includeInlayParameterNameHintsWhenArgumentMatchesName: !config.get<boolean>(InlayHintSettingNames.parameterNamesSuppressWhenArgumentMatchesName, true),
|
||||
includeInlayFunctionParameterTypeHints: config.get<boolean>(InlayHintSettingNames.parameterNamesEnabled, false),
|
||||
includeInlayVariableTypeHints: config.get<boolean>(InlayHintSettingNames.variableTypesEnabled, false),
|
||||
includeInlayVariableTypeHintsWhenTypeMatchesName: !config.get<boolean>(InlayHintSettingNames.variableTypesSuppressWhenTypeMatchesName, true),
|
||||
includeInlayPropertyDeclarationTypeHints: config.get<boolean>(InlayHintSettingNames.propertyDeclarationTypesEnabled, false),
|
||||
includeInlayFunctionLikeReturnTypeHints: config.get<boolean>(InlayHintSettingNames.functionLikeReturnTypesEnabled, false),
|
||||
includeInlayEnumMemberValueHints: config.get<boolean>(InlayHintSettingNames.enumMemberValuesEnabled, false),
|
||||
includeInlayParameterNameHints: getInlayParameterNameHintsPreference(scope, fallbackSection),
|
||||
includeInlayParameterNameHintsWhenArgumentMatchesName: !readUnifiedConfig<boolean>(InlayHintSettingNames.parameterNamesSuppressWhenArgumentMatchesName, true, { scope, fallbackSection }),
|
||||
includeInlayFunctionParameterTypeHints: readUnifiedConfig<boolean>(InlayHintSettingNames.parameterTypesEnabled, false, { scope, fallbackSection }),
|
||||
includeInlayVariableTypeHints: readUnifiedConfig<boolean>(InlayHintSettingNames.variableTypesEnabled, false, { scope, fallbackSection }),
|
||||
includeInlayVariableTypeHintsWhenTypeMatchesName: !readUnifiedConfig<boolean>(InlayHintSettingNames.variableTypesSuppressWhenTypeMatchesName, true, { scope, fallbackSection }),
|
||||
includeInlayPropertyDeclarationTypeHints: readUnifiedConfig<boolean>(InlayHintSettingNames.propertyDeclarationTypesEnabled, false, { scope, fallbackSection }),
|
||||
includeInlayFunctionLikeReturnTypeHints: readUnifiedConfig<boolean>(InlayHintSettingNames.functionLikeReturnTypesEnabled, false, { scope, fallbackSection }),
|
||||
includeInlayEnumMemberValueHints: readUnifiedConfig<boolean>(InlayHintSettingNames.enumMemberValuesEnabled, false, { scope, fallbackSection }),
|
||||
} as const;
|
||||
}
|
||||
|
||||
function getInlayParameterNameHintsPreference(config: vscode.WorkspaceConfiguration) {
|
||||
switch (config.get<string>('inlayHints.parameterNames.enabled')) {
|
||||
function getInlayParameterNameHintsPreference(scope: vscode.ConfigurationScope, fallbackSection: string) {
|
||||
switch (readUnifiedConfig<string>(InlayHintSettingNames.parameterNamesEnabled, 'none', { scope, fallbackSection })) {
|
||||
case 'none': return 'none';
|
||||
case 'literals': return 'literals';
|
||||
case 'all': return 'all';
|
||||
|
||||
@@ -11,20 +11,13 @@ import { API } from '../tsServer/api';
|
||||
import type * as Proto from '../tsServer/protocol/protocol';
|
||||
import { Location, Position } from '../typeConverters';
|
||||
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { unifiedConfigSection } from '../utils/configuration';
|
||||
import { Disposable } from '../utils/dispose';
|
||||
import FileConfigurationManager, { InlayHintSettingNames, getInlayHintsPreferences } from './fileConfigurationManager';
|
||||
import { conditionalRegistration, requireMinVersion, requireSomeCapability } from './util/dependentRegistration';
|
||||
|
||||
|
||||
const inlayHintSettingNames = Object.freeze([
|
||||
InlayHintSettingNames.parameterNamesSuppressWhenArgumentMatchesName,
|
||||
InlayHintSettingNames.parameterNamesEnabled,
|
||||
InlayHintSettingNames.variableTypesEnabled,
|
||||
InlayHintSettingNames.variableTypesSuppressWhenTypeMatchesName,
|
||||
InlayHintSettingNames.propertyDeclarationTypesEnabled,
|
||||
InlayHintSettingNames.functionLikeReturnTypesEnabled,
|
||||
InlayHintSettingNames.enumMemberValuesEnabled,
|
||||
]);
|
||||
const inlayHintSettingNames = Object.values(InlayHintSettingNames);
|
||||
|
||||
class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHintsProvider {
|
||||
|
||||
@@ -44,7 +37,10 @@ class TypeScriptInlayHintsProvider extends Disposable implements vscode.InlayHin
|
||||
super();
|
||||
|
||||
this._register(vscode.workspace.onDidChangeConfiguration(e => {
|
||||
if (inlayHintSettingNames.some(settingName => e.affectsConfiguration(language.id + '.' + settingName))) {
|
||||
if (inlayHintSettingNames.some(settingName =>
|
||||
e.affectsConfiguration(unifiedConfigSection + '.' + settingName) ||
|
||||
e.affectsConfiguration(language.id + '.' + settingName)
|
||||
)) {
|
||||
this._onDidChangeInlayHints.fire();
|
||||
}
|
||||
}));
|
||||
@@ -131,8 +127,7 @@ function fromProtocolInlayHintKind(kind: Proto.InlayHintKind): vscode.InlayHintK
|
||||
}
|
||||
|
||||
function areInlayHintsEnabledForFile(language: LanguageDescription, document: vscode.TextDocument) {
|
||||
const config = vscode.workspace.getConfiguration(language.id, document);
|
||||
const preferences = getInlayHintsPreferences(config);
|
||||
const preferences = getInlayHintsPreferences(document, language.id);
|
||||
|
||||
return preferences.includeInlayParameterNameHints === 'literals' ||
|
||||
preferences.includeInlayParameterNameHints === 'all' ||
|
||||
|
||||
Reference in New Issue
Block a user