获取 disableFormat 配置项改为获取 enabledFormats 配置项
This commit is contained in:
@@ -86,7 +86,7 @@ Or right-click on the selected text -> Convert string to...
|
|||||||
|
|
||||||
| 配置项 Configuration Key | 描述 Description | 配置示例 | 默认值 |
|
| 配置项 Configuration Key | 描述 Description | 配置示例 | 默认值 |
|
||||||
| ----------------------------------- | ------------------------------------------------------------ | ------------------------------ | ------ |
|
| ----------------------------------- | ------------------------------------------------------------ | ------------------------------ | ------ |
|
||||||
| `variable-conversion.disableFormat` | 定义哪些格式是禁用的<br />Define which formats are disabled. | `["lower_case", "upper_case"]` | `[]` |
|
| `variable-conversion.enabledFormats` | 配置启用的变量命名方式<br />Configuration of Enabled Variable Naming Conventions. | `{ "xxxCase.enabled": boolean, ... }` | 见配置项 |
|
||||||
|
|
||||||
## 支持的类型 Support Case
|
## 支持的类型 Support Case
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ function lazyConvert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户配置
|
// 获取用户配置
|
||||||
const disableFormatList = getUserConfigurations<Array<string>>('disableFormat') || [];
|
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
|
||||||
|
|
||||||
const textList = userSelection.currentSelectionsText;
|
const textList = userSelection.currentSelectionsText;
|
||||||
// vscode.window.showInformationMessage('lazyConvert' + textList.join('\n'));
|
// vscode.window.showInformationMessage('lazyConvert' + textList.join('\n'));
|
||||||
@@ -75,7 +75,7 @@ function lazyConvert() {
|
|||||||
for (const cyclicConvertCase of cyclicConvertCaseOrder) {
|
for (const cyclicConvertCase of cyclicConvertCaseOrder) {
|
||||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||||
// 跳过禁用的目标格式
|
// 跳过禁用的目标格式
|
||||||
if (disableFormatList.includes(cyclicConvertCase.settingsKey)) {
|
if (enabledFormats[cyclicConvertCase.settingsKey] === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -278,114 +278,142 @@ const keyword = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface Command {
|
||||||
|
command: string;
|
||||||
|
targetCase: SupportVariableCase;
|
||||||
|
settingsKey: string;
|
||||||
|
// variable-conversion.enabledFormats 中的配置项
|
||||||
|
enableSettingsKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接管的变量转换命令
|
* 接管的变量转换命令
|
||||||
*/
|
*/
|
||||||
export const commands: Array<{ command: string; targetCase: SupportVariableCase; settingsKey: string }> = [
|
export const commands: Array<Command> = [
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toCamelCase',
|
command: 'variable-conversion.toCamelCase',
|
||||||
targetCase: SupportVariableCase.CAMEL_CASE,
|
targetCase: SupportVariableCase.CAMEL_CASE,
|
||||||
settingsKey: 'camel_case'
|
settingsKey: 'camel_case',
|
||||||
|
enableSettingsKey: 'camelCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toPascalCase',
|
command: 'variable-conversion.toPascalCase',
|
||||||
targetCase: SupportVariableCase.PASCAL_CASE,
|
targetCase: SupportVariableCase.PASCAL_CASE,
|
||||||
settingsKey: 'pascal_case'
|
settingsKey: 'pascal_case',
|
||||||
|
enableSettingsKey: 'pascalCase.enabled',
|
||||||
},
|
},
|
||||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSnakeCase',
|
command: 'variable-conversion.toSnakeCase',
|
||||||
targetCase: SupportVariableCase.SNAKE_CASE,
|
targetCase: SupportVariableCase.SNAKE_CASE,
|
||||||
settingsKey: 'snake_case'
|
settingsKey: 'snake_case',
|
||||||
|
enableSettingsKey: 'snakeCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSnakeUpperCase',
|
command: 'variable-conversion.toSnakeUpperCase',
|
||||||
targetCase: SupportVariableCase.SNAKE_UPPER_CASE,
|
targetCase: SupportVariableCase.SNAKE_UPPER_CASE,
|
||||||
settingsKey: 'snake_upper_case'
|
settingsKey: 'snake_upper_case',
|
||||||
|
enableSettingsKey: 'snakeUpperCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSnakePascalCase',
|
command: 'variable-conversion.toSnakePascalCase',
|
||||||
targetCase: SupportVariableCase.SNAKE_PASCAL_CASE,
|
targetCase: SupportVariableCase.SNAKE_PASCAL_CASE,
|
||||||
settingsKey: 'snake_pascal_case'
|
settingsKey: 'snake_pascal_case',
|
||||||
|
enableSettingsKey: 'snakePascalCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSnakeCamelCase',
|
command: 'variable-conversion.toSnakeCamelCase',
|
||||||
targetCase: SupportVariableCase.SNAKE_CAMEL_CASE,
|
targetCase: SupportVariableCase.SNAKE_CAMEL_CASE,
|
||||||
settingsKey: 'snake_camel_case'
|
settingsKey: 'snake_camel_case',
|
||||||
|
enableSettingsKey: 'snakeCamelCase.enabled',
|
||||||
},
|
},
|
||||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toKebabCase',
|
command: 'variable-conversion.toKebabCase',
|
||||||
targetCase: SupportVariableCase.KEBAB_CASE,
|
targetCase: SupportVariableCase.KEBAB_CASE,
|
||||||
settingsKey: 'kebab_case'
|
settingsKey: 'kebab_case',
|
||||||
|
enableSettingsKey: 'kebabCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toKebabUpperCase',
|
command: 'variable-conversion.toKebabUpperCase',
|
||||||
targetCase: SupportVariableCase.KEBAB_UPPER_CASE,
|
targetCase: SupportVariableCase.KEBAB_UPPER_CASE,
|
||||||
settingsKey: 'kebab_upper_case'
|
settingsKey: 'kebab_upper_case',
|
||||||
|
enableSettingsKey: 'kebabUpperCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toKebabPascalCase',
|
command: 'variable-conversion.toKebabPascalCase',
|
||||||
targetCase: SupportVariableCase.KEBAB_PASCAL_CASE,
|
targetCase: SupportVariableCase.KEBAB_PASCAL_CASE,
|
||||||
settingsKey: 'kebab_pascal_case'
|
settingsKey: 'kebab_pascal_case',
|
||||||
|
enableSettingsKey: 'kebabPascalCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toKebabCamelCase',
|
command: 'variable-conversion.toKebabCamelCase',
|
||||||
targetCase: SupportVariableCase.KEBAB_CAMEL_CASE,
|
targetCase: SupportVariableCase.KEBAB_CAMEL_CASE,
|
||||||
settingsKey: 'kebab_camel_case'
|
settingsKey: 'kebab_camel_case',
|
||||||
|
enableSettingsKey: 'kebabCamelCase.enabled',
|
||||||
},
|
},
|
||||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSpaceCase',
|
command: 'variable-conversion.toSpaceCase',
|
||||||
targetCase: SupportVariableCase.SPACE_CASE,
|
targetCase: SupportVariableCase.SPACE_CASE,
|
||||||
settingsKey: 'space_case'
|
settingsKey: 'space_case',
|
||||||
|
enableSettingsKey: 'spaceCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSpaceUpperCase',
|
command: 'variable-conversion.toSpaceUpperCase',
|
||||||
targetCase: SupportVariableCase.SPACE_UPPER_CASE,
|
targetCase: SupportVariableCase.SPACE_UPPER_CASE,
|
||||||
settingsKey: 'space_upper_case'
|
settingsKey: 'space_upper_case',
|
||||||
|
enableSettingsKey: 'spaceUpperCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSpacePascalCase',
|
command: 'variable-conversion.toSpacePascalCase',
|
||||||
targetCase: SupportVariableCase.SPACE_PASCAL_CASE,
|
targetCase: SupportVariableCase.SPACE_PASCAL_CASE,
|
||||||
settingsKey: 'space_pascal_case'
|
settingsKey: 'space_pascal_case',
|
||||||
|
enableSettingsKey: 'spacePascalCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toSpaceCamelCase',
|
command: 'variable-conversion.toSpaceCamelCase',
|
||||||
targetCase: SupportVariableCase.SPACE_CAMEL_CASE,
|
targetCase: SupportVariableCase.SPACE_CAMEL_CASE,
|
||||||
settingsKey: 'space_camel_case'
|
settingsKey: 'space_camel_case',
|
||||||
|
enableSettingsKey: 'spaceCamelCase.enabled',
|
||||||
},
|
},
|
||||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toDotCase',
|
command: 'variable-conversion.toDotCase',
|
||||||
targetCase: SupportVariableCase.DOT_CASE,
|
targetCase: SupportVariableCase.DOT_CASE,
|
||||||
settingsKey: 'dot_case'
|
settingsKey: 'dot_case',
|
||||||
|
enableSettingsKey: 'dotCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toDotUpperCase',
|
command: 'variable-conversion.toDotUpperCase',
|
||||||
targetCase: SupportVariableCase.DOT_UPPER_CASE,
|
targetCase: SupportVariableCase.DOT_UPPER_CASE,
|
||||||
settingsKey: 'dot_upper_case'
|
settingsKey: 'dot_upper_case',
|
||||||
|
enableSettingsKey: 'dotUpperCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toDotPascalCase',
|
command: 'variable-conversion.toDotPascalCase',
|
||||||
targetCase: SupportVariableCase.DOT_PASCAL_CASE,
|
targetCase: SupportVariableCase.DOT_PASCAL_CASE,
|
||||||
settingsKey: 'dot_pascal_case'
|
settingsKey: 'dot_pascal_case',
|
||||||
|
enableSettingsKey: 'dotPascalCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toDotCamelCase',
|
command: 'variable-conversion.toDotCamelCase',
|
||||||
targetCase: SupportVariableCase.DOT_CAMEL_CASE,
|
targetCase: SupportVariableCase.DOT_CAMEL_CASE,
|
||||||
settingsKey: 'dot_camel_case'
|
settingsKey: 'dot_camel_case',
|
||||||
|
enableSettingsKey: 'dotCamelCase.enabled',
|
||||||
},
|
},
|
||||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toLowerCase',
|
command: 'variable-conversion.toLowerCase',
|
||||||
targetCase: SupportVariableCase.LOWER_CASE,
|
targetCase: SupportVariableCase.LOWER_CASE,
|
||||||
settingsKey: 'lower_case'
|
settingsKey: 'lower_case',
|
||||||
|
enableSettingsKey: 'lowerCase.enabled',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
command: 'variable-conversion.toUpperCase',
|
command: 'variable-conversion.toUpperCase',
|
||||||
targetCase: SupportVariableCase.UPPER_CASE,
|
targetCase: SupportVariableCase.UPPER_CASE,
|
||||||
settingsKey: 'upper_case'
|
settingsKey: 'upper_case',
|
||||||
|
enableSettingsKey: 'upperCase.enabled',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -64,12 +64,12 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||||
// 获取用户配置
|
// 获取用户配置
|
||||||
const disableFormatList = getUserConfigurations<Array<string>>('disableFormat') || [];
|
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
|
||||||
const disablePathFormatList = getUserConfigurations<Array<string>>('disablePathFormat') || [];
|
const disablePathFormatList = getUserConfigurations<Array<string>>('disablePathFormat') || [];
|
||||||
// 更新右键菜单每一项是否展示
|
// 更新右键菜单每一项是否展示
|
||||||
// 变量转换右键菜单visible 2024.07.29
|
// 变量转换右键菜单visible 2024.07.29
|
||||||
for (const { settingsKey } of variableCommands) {
|
for (const { settingsKey, enableSettingsKey } of variableCommands) {
|
||||||
vscode.commands.executeCommand('setContext', '_isHideSubMenuItem_' + settingsKey, disableFormatList.includes(settingsKey));
|
vscode.commands.executeCommand('setContext', '_isHideSubMenuItem_' + settingsKey, enabledFormats[enableSettingsKey] === false);
|
||||||
}
|
}
|
||||||
// 路径转换右键菜单visible 2024.12.14
|
// 路径转换右键菜单visible 2024.12.14
|
||||||
for (const { settingsKey } of pathCommands) {
|
for (const { settingsKey } of pathCommands) {
|
||||||
|
@@ -98,17 +98,17 @@ export function handleQuickPick() {
|
|||||||
|
|
||||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||||
// 获取用户配置
|
// 获取用户配置
|
||||||
const disableFormatList = getUserConfigurations<Array<string>>('disableFormat') || [];
|
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
|
||||||
// 排除禁用的选项
|
// 排除禁用的选项
|
||||||
const enabledQuickPickSupportCases = [];
|
const enabledQuickPickSupportCases = [];
|
||||||
for (const quickPick of quickPickSupportCases) {
|
for (const quickPick of quickPickSupportCases) {
|
||||||
if (disableFormatList.includes(quickPick.settingsKey)) {
|
if (enabledFormats[quickPick.settingsKey] === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
enabledQuickPickSupportCases.push(quickPick);
|
enabledQuickPickSupportCases.push(quickPick);
|
||||||
}
|
}
|
||||||
if (enabledQuickPickSupportCases.length === 0) {
|
if (enabledQuickPickSupportCases.length === 0) {
|
||||||
vscode.window.showInformationMessage('所有格式都已被配置为禁用,请修改配置 `variable-conversion.disableFormat` 后重试\nAll formats have been configured to disable. Modify the `variable-conversion.disableFormat` configuration and try again.');
|
vscode.window.showInformationMessage('所有格式都已被配置为禁用,请修改配置 `variable-conversion.enabledFormats` 后重试\nAll formats have been configured to disable. Modify the `variable-conversion.enabledFormats` configuration and try again.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user