1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

Merge branch 'feature-format-order'

This commit is contained in:
2025-12-05 15:01:21 +08:00
13 changed files with 401 additions and 16 deletions

View File

@@ -11,7 +11,8 @@
// Code Spell Checker 插件 // Code Spell Checker 插件
"cSpell.words": [ "cSpell.words": [
"coder-xiaomo",
"Gitee", "Gitee",
"coder-xiaomo" "unconfigured"
], ],
} }

View File

@@ -25,6 +25,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
--> -->
## 2.2.0
### Added
- Add new configuration `variable-conversion.formatOrder` to customize the display order of variable naming conventions. (新增 `variable-conversion.formatOrder` 配置项,用于自定义变量命名方式的显示顺序)
- Add new command `variable-conversion.showConvertCaseDetailDialog` to display current format configuration. (新增 `variable-conversion.showConvertCaseDetailDialog` 命令,用于显示当前配置的格式信息)
- Add clickable link for the configuration description. (在配置项描述中添加了点击跳转超链接)
- Add shortcut key `Ctrl + Alt + \` to trigger format order info display dialog. (新增快捷键 `Ctrl + Alt + \` 用于触发显示格式顺序弹窗)
- Support displaying duplicate and invalid items in format information dialog. (支持在信息弹窗中显示配置的重复项和无效项)
- Add buttons in format information dialog for quick navigation to corresponding settings. (在格式弹窗中添加按钮,支持快捷跳转至设置页对应配置项)
### Improved
- Improve cyclic conversion to follow user-configured formatOrder. (改进了循环转换功能使其遵循用户配置的formatOrder顺序)
## 2.1.0 ## 2.1.0
### Changed ### Changed

View File

@@ -7,6 +7,12 @@ A powerful variable and path conversion extension. Supports one-key conversion &
> **【近期更新】** > **【近期更新】**
> >
> **v2.2.0 (2025-12-05)**
>
> - 支持配置目标转换格式顺序
> - 支持展示当前配置的格式顺序信息弹窗,可显示配置重复项和无效项
> - 支持从弹窗中点击按钮快捷跳转至设置页对应配置项
>
> **v2.1.0 (2025-07-14)** > **v2.1.0 (2025-07-14)**
> >
> - 支持仅开启部分目标转换格式 (优化 VSCode 配置项) > - 支持仅开启部分目标转换格式 (优化 VSCode 配置项)
@@ -82,6 +88,7 @@ Or right-click on the selected text -> Convert string to...
| 变量转换 快速选择 Variable Conversion QuickPick | Shift + Alt + T | | 变量转换 快速选择 Variable Conversion QuickPick | Shift + Alt + T |
| 变量循环转换→上一个 Variable Cyclic Conversion → Previous one | Ctrl + Alt + [ | | 变量循环转换→上一个 Variable Cyclic Conversion → Previous one | Ctrl + Alt + [ |
| 变量循环转换→下一个 Variable Cyclic Conversion → Next one | Ctrl + Alt + ] | | 变量循环转换→下一个 Variable Cyclic Conversion → Next one | Ctrl + Alt + ] |
| 显示格式顺序信息弹窗 Show Format Order Info Dialog | Ctrl + Alt + \` |
| 路径转换 快速选择 Path Conversion QuickPick | Shift + Alt + / | | 路径转换 快速选择 Path Conversion QuickPick | Shift + Alt + / |
| 路径循环转换→上一个 Path Cyclic conversion → Previous one | Ctrl + Alt + / | | 路径循环转换→上一个 Path Cyclic conversion → Previous one | Ctrl + Alt + / |
| 路径循环转换→下一个 Path Cyclic conversion → Next one | Ctrl + Shift + Alt + / | | 路径循环转换→下一个 Path Cyclic conversion → Next one | Ctrl + Shift + Alt + / |
@@ -90,10 +97,42 @@ Or right-click on the selected text -> Convert string to...
## 配置项 Configurations ## 配置项 Configurations
| 配置项 Configuration Key | 描述 Description | 配置示例 | 默认值 | | 配置项 Configuration Key | 描述 Description | 配置示例 | 默认值 |
| --------------------------------------- | ------------------------------------------------------------ | ------------------------------------- | -------- | | --------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------- | -------- |
| `variable-conversion.enabledFormats` | 配置启用的变量命名方式<br />Configuration of Enabled Variable Naming Conventions. | `{ "xxxCase.enabled": boolean, ... }` | 见配置项 | | `variable-conversion.enabledFormats` | 配置启用的变量命名方式<br />Configuration of Enabled Variable Naming Conventions. | `{ "xxxCase.enabled": boolean, ... }` | 见配置项 |
| `variable-conversion.disablePathFormat` | 定义哪些路径风格是禁用的<br />Define which path formats are disabled. | `["windows_style", "unix_style"]` | 见配置项 | | `variable-conversion.formatOrder` | 配置变量命名方式的显示顺序<br />Configure the display order of variable naming conventions. | `[ "camel_case", "pascal_case", "snake_case" ]` | 见配置项 |
| `variable-conversion.disablePathFormat` | 定义哪些路径风格是禁用的<br />Define which path formats are disabled. | `["windows_style", "unix_style"]` | 见配置项 |
配置项如下:
<!--
GitHub 上这种表格高亮行会有问题(表头不会高亮)
| ![Enabled Formats](image/settings-enable-formats.png) | ![Format Order](image/settings-format-order.png) |
| :----------------------------------------------------------: | :----------------------------------------------: |
| **Enabled Formats 配置** | **Format Order 配置** |
| ![Disable Path Format](image/settings-disable-path-format.png) | |
| **Disable Path Format 配置** | |
-->
<table>
<tr>
<td align="center"><strong>Enabled Formats 配置</strong></td>
<td align="center"><strong>Format Order 配置</strong></td>
</tr>
<tr>
<td align="center"><img src="image/settings-enable-formats.png" alt="Enabled Formats"></td>
<td align="center"><img src="image/settings-format-order.png" alt="Format Order"></td>
</tr>
<tr>
<td align="center"><strong>Disable Path Format 配置</strong></td>
<td align="center"></td>
</tr>
<tr>
<td align="center"><img src="image/settings-disable-path-format.png" alt="Disable Path Format"></td>
<td align="center"></td>
</tr>
</table>
## 支持的类型 Support Case ## 支持的类型 Support Case

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@@ -64,6 +64,11 @@
}, },
"when": "editorTextFocus" "when": "editorTextFocus"
}, },
// 展示当前配置的转换格式顺序对话框
{
"command": "variable-conversion.showConvertCaseDetailDialog",
"key": "ctrl+alt+\\"
},
// ↓ 路径转换快捷键 // ↓ 路径转换快捷键
{ {
"command": "variable-conversion.convertPath", "command": "variable-conversion.convertPath",
@@ -547,7 +552,7 @@
"variable-conversion.enabledFormats": { "variable-conversion.enabledFormats": {
"type": "object", "type": "object",
"description": "Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.", "description": "Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.",
"markdownDescription": "配置启用的变量命名方式\n\nConfiguration of Enabled Variable Naming Conventions.\n\n&nbsp;\n\n🌰 e.g. *Mike like eat ice-cream*\n\n对于这个句子不同命名方式如以下示例\n\nFor this sentence, different naming conventions are as follows:\n\n[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)", "markdownDescription": "配置启用的变量命名方式\n\nConfiguration of Enabled Variable Naming Conventions.\n\n[配置转换顺序](command:workbench.action.openSettings?%5B%22variable-conversion.formatOrder%22%5D)&nbsp;&nbsp;&nbsp;&nbsp;[查看当前配置(对话框)](command:variable-conversion.showConvertCaseDetailDialog)&nbsp;&nbsp;&nbsp;&nbsp;[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)\n\n&nbsp;\n\n🌰 e.g. *Mike like eat ice-cream*\n\n对于这个句子不同命名方式示例如下\n\nFor this sentence, different naming conventions are as follows:",
"scope": "window", "scope": "window",
"properties": { "properties": {
"lowerCase.enabled": { "lowerCase.enabled": {
@@ -684,7 +689,59 @@
"dotCamelCase.enabled": false "dotCamelCase.enabled": false
} }
}, },
// "variable-conversion.formatOrder": {}, "variable-conversion.formatOrder": {
"type": "array",
"markdownDescription": "配置变量命名方式的显示顺序\n\nConfigure the display order of variable naming conventions.\n\n如果某个格式在 enabledFormats 中被禁用,则即使在 formatOrder 中配置也不会显示。\n\nIf a format is disabled in enabledFormats, it will not be displayed even if configured in formatOrder.\n\n如您通过 [settings.json](command:workbench.action.openSettingsJson) 进行配置,请确保该配置中的格式名称与 enabledFormats 中的保持一致。\n\nWhen configuring via [settings.json](command:workbench.action.openSettingsJson), please ensure that the format names in this configuration match those in enabledFormats.\n\n🌰 e.g. `[\"camel_case\", \"snake_case\", \"pascal_case\"]`\n\n[配置启用的变量命名方式](command:workbench.action.openSettings?%5B%22variable-conversion.enabledFormats%22%5D)&nbsp;&nbsp;&nbsp;&nbsp;[查看当前配置(对话框)](command:variable-conversion.showConvertCaseDetailDialog)&nbsp;&nbsp;&nbsp;&nbsp;[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)",
"scope": "window",
"items": {
"type": "string",
"enum": [
"camel_case",
"pascal_case",
"snake_case",
"snake_camel_case",
"snake_pascal_case",
"snake_upper_case",
"kebab_case",
"kebab_camel_case",
"kebab_pascal_case",
"kebab_upper_case",
"space_case",
"space_camel_case",
"space_pascal_case",
"space_upper_case",
"dot_case",
"dot_camel_case",
"dot_pascal_case",
"dot_upper_case",
"lower_case",
"upper_case"
],
"enumDescriptions": [
"驼峰命名 (camel_case)",
"大驼峰命名 (pascal_case)",
"下划线命名 (snake_case)",
"下划线驼峰命名 (snake_camel_case)",
"下划线大驼峰命名 (snake_pascal_case)",
"下划线大写命名 (snake_upper_case)",
"连字符命名 (kebab_case)",
"连字符驼峰命名 (kebab_camel_case)",
"连字符大驼峰命名 (kebab_pascal_case)",
"连字符大写命名 (kebab_upper_case)",
"空格命名 (space_case)",
"空格驼峰命名 (space_camel_case)",
"空格大驼峰命名 (space_pascal_case)",
"空格大写命名 (space_upper_case)",
"点命名 (dot_case)",
"点驼峰命名 (dot_camel_case)",
"点大驼峰命名 (dot_pascal_case)",
"点大写命名 (dot_upper_case)",
"全小写命名 (lower_case)",
"全大写命名 (upper_case)"
]
},
"default": []
},
"variable-conversion.disableFormat": { "variable-conversion.disableFormat": {
"order": 1, "order": 1,
// markdownDescription 最多配置 11 行 // markdownDescription 最多配置 11 行

View File

@@ -53,6 +53,10 @@
}, },
"when": "editorTextFocus" "when": "editorTextFocus"
}, },
{
"command": "variable-conversion.showConvertCaseDetailDialog",
"key": "ctrl+alt+\\"
},
{ {
"command": "variable-conversion.convertPath", "command": "variable-conversion.convertPath",
"key": "shift+alt+/", "key": "shift+alt+/",
@@ -327,7 +331,7 @@
"variable-conversion.enabledFormats": { "variable-conversion.enabledFormats": {
"type": "object", "type": "object",
"description": "Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.", "description": "Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.",
"markdownDescription": "配置启用的变量命名方式\n\nConfiguration of Enabled Variable Naming Conventions.\n\n&nbsp;\n\n🌰 e.g. *Mike like eat ice-cream*\n\n对于这个句子不同命名方式如以下示例\n\nFor this sentence, different naming conventions are as follows:\n\n[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)", "markdownDescription": "配置启用的变量命名方式\n\nConfiguration of Enabled Variable Naming Conventions.\n\n[配置转换顺序](command:workbench.action.openSettings?%5B%22variable-conversion.formatOrder%22%5D)&nbsp;&nbsp;&nbsp;&nbsp;[查看当前配置(对话框)](command:variable-conversion.showConvertCaseDetailDialog)&nbsp;&nbsp;&nbsp;&nbsp;[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)\n\n&nbsp;\n\n🌰 e.g. *Mike like eat ice-cream*\n\n对于这个句子不同命名方式示例如下\n\nFor this sentence, different naming conventions are as follows:",
"scope": "window", "scope": "window",
"properties": { "properties": {
"lowerCase.enabled": { "lowerCase.enabled": {
@@ -455,6 +459,59 @@
"dotCamelCase.enabled": false "dotCamelCase.enabled": false
} }
}, },
"variable-conversion.formatOrder": {
"type": "array",
"markdownDescription": "配置变量命名方式的显示顺序\n\nConfigure the display order of variable naming conventions.\n\n如果某个格式在 enabledFormats 中被禁用,则即使在 formatOrder 中配置也不会显示。\n\nIf a format is disabled in enabledFormats, it will not be displayed even if configured in formatOrder.\n\n如您通过 [settings.json](command:workbench.action.openSettingsJson) 进行配置,请确保该配置中的格式名称与 enabledFormats 中的保持一致。\n\nWhen configuring via [settings.json](command:workbench.action.openSettingsJson), please ensure that the format names in this configuration match those in enabledFormats.\n\n🌰 e.g. `[\"camel_case\", \"snake_case\", \"pascal_case\"]`\n\n[配置启用的变量命名方式](command:workbench.action.openSettings?%5B%22variable-conversion.enabledFormats%22%5D)&nbsp;&nbsp;&nbsp;&nbsp;[查看当前配置(对话框)](command:variable-conversion.showConvertCaseDetailDialog)&nbsp;&nbsp;&nbsp;&nbsp;[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)",
"scope": "window",
"items": {
"type": "string",
"enum": [
"camel_case",
"pascal_case",
"snake_case",
"snake_camel_case",
"snake_pascal_case",
"snake_upper_case",
"kebab_case",
"kebab_camel_case",
"kebab_pascal_case",
"kebab_upper_case",
"space_case",
"space_camel_case",
"space_pascal_case",
"space_upper_case",
"dot_case",
"dot_camel_case",
"dot_pascal_case",
"dot_upper_case",
"lower_case",
"upper_case"
],
"enumDescriptions": [
"驼峰命名 (camel_case)",
"大驼峰命名 (pascal_case)",
"下划线命名 (snake_case)",
"下划线驼峰命名 (snake_camel_case)",
"下划线大驼峰命名 (snake_pascal_case)",
"下划线大写命名 (snake_upper_case)",
"连字符命名 (kebab_case)",
"连字符驼峰命名 (kebab_camel_case)",
"连字符大驼峰命名 (kebab_pascal_case)",
"连字符大写命名 (kebab_upper_case)",
"空格命名 (space_case)",
"空格驼峰命名 (space_camel_case)",
"空格大驼峰命名 (space_pascal_case)",
"空格大写命名 (space_upper_case)",
"点命名 (dot_case)",
"点驼峰命名 (dot_camel_case)",
"点大驼峰命名 (dot_pascal_case)",
"点大写命名 (dot_upper_case)",
"全小写命名 (lower_case)",
"全大写命名 (upper_case)"
]
},
"default": []
},
"variable-conversion.disableFormat": { "variable-conversion.disableFormat": {
"order": 1, "order": 1,
"markdownDescription": "定义哪些变量命名方式是禁用的\n\nDefine which variable formats are disabled.\n\n若您感觉以下配置比较麻烦也可以选择在 `settings.json` 中编辑:\n\nIf you find the following configuration troublesome, you can also edit this configuration item in `settings.json`:\n\n`\"variable-conversion.disableFormat\": [ ... ],`\n\n[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)\n\n配置后您可能需要*重启扩展宿主*,或*重启当前窗口*才可使该配置完全生效(二选一即可):\n\nYou may need to *restart extension host* or *reload window* after configuration to take full effect (either):\n\n[重启扩展宿主 (Restart Extension Host)](command:workbench.action.restartExtensionHost), [重启当前窗口 (Reload Window)](command:workbench.action.reloadWindow)", "markdownDescription": "定义哪些变量命名方式是禁用的\n\nDefine which variable formats are disabled.\n\n若您感觉以下配置比较麻烦也可以选择在 `settings.json` 中编辑:\n\nIf you find the following configuration troublesome, you can also edit this configuration item in `settings.json`:\n\n`\"variable-conversion.disableFormat\": [ ... ],`\n\n[在 settings.json 中编辑 (Edit in settings.json)](command:workbench.action.openSettingsJson)\n\n配置后您可能需要*重启扩展宿主*,或*重启当前窗口*才可使该配置完全生效(二选一即可):\n\nYou may need to *restart extension host* or *reload window* after configuration to take full effect (either):\n\n[重启扩展宿主 (Restart Extension Host)](command:workbench.action.restartExtensionHost), [重启当前窗口 (Reload Window)](command:workbench.action.reloadWindow)",

View File

@@ -1,6 +1,6 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { EOL } from "../../types/EOLType"; import { EOL } from "../../types/EOLType";
import { cyclicConvertCaseOrder } from "./types/SupportVariableCaseType"; import { cyclicConvertCaseOrder, settingsKeyToEnableSettingsKey } from "./types/SupportVariableCaseType";
import { caseConversion } from "./conversion"; import { caseConversion } from "./conversion";
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils'; import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils';
import { getUserConfigurations } from '../../utils/user-configuration'; import { getUserConfigurations } from '../../utils/user-configuration';
@@ -75,15 +75,24 @@ function lazyConvert() {
// 获取用户配置 // 获取用户配置
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {}; const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
const formatOrder = getUserConfigurations<string[]>('formatOrder') || [];
const textList = userSelection.currentSelectionsText; const textList = userSelection.currentSelectionsText;
// vscode.window.showInformationMessage('lazyConvert' + textList.join('\n')); // vscode.window.showInformationMessage('lazyConvert' + textList.join('\n'));
const eol = userSelection.currentEol; const eol = userSelection.currentEol;
const conversionsTarget: Array<string[]> = [textList];
// 先收集所有启用的格式及其转换结果
// const conversionsTarget: Array<string[]> = [textList];
const formatMap = new Map<string, string[]>();
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 (enabledFormats[cyclicConvertCase.settingsKey] === false) { const enableSettingsKey = settingsKeyToEnableSettingsKey.get(cyclicConvertCase.settingsKey);
if (!enableSettingsKey) {
console.warn('Cannot find enableSettingsKey for settingsKey:', cyclicConvertCase.settingsKey);
continue;
}
if (enabledFormats[enableSettingsKey] !== true) {
continue; continue;
} }
@@ -94,11 +103,34 @@ function lazyConvert() {
const conversionResult: string = caseConversion(cyclicConvertCase.type, line, eol); const conversionResult: string = caseConversion(cyclicConvertCase.type, line, eol);
conversionsTargetItem.push(conversionResult); conversionsTargetItem.push(conversionResult);
} }
conversionsTarget.push(conversionsTargetItem); // conversionsTarget.push(conversionsTargetItem);
formatMap.set(cyclicConvertCase.settingsKey, conversionsTargetItem);
}
// 根据formatOrder对格式进行排序
const orderedConversions: Array<string[]> = [textList];
const processedSettingsKeys = new Set<string>();
// 先添加在formatOrder中配置的格式
for (const formatName of formatOrder) {
const conversions = formatMap.get(formatName);
if (conversions && !processedSettingsKeys.has(formatName)) {
orderedConversions.push(conversions);
processedSettingsKeys.add(formatName);
}
}
// 再添加未在formatOrder中配置但启用的格式保持原有顺序
for (const cyclicConvertCase of cyclicConvertCaseOrder) {
const settingsKey = cyclicConvertCase.settingsKey;
const conversions = formatMap.get(settingsKey);
if (conversions && !processedSettingsKeys.has(settingsKey)) {
orderedConversions.push(conversions);
processedSettingsKeys.add(settingsKey);
}
} }
// 按数组去重 // 按数组去重
const noDuplicate = stringListArrayDuplicateRemoval(conversionsTarget); // const noDuplicate = stringListArrayDuplicateRemoval(conversionsTarget);
const noDuplicate = stringListArrayDuplicateRemoval(orderedConversions);
// console.log('noDuplicate', noDuplicate); // console.log('noDuplicate', noDuplicate);
userSelection.conversionsTarget = noDuplicate; userSelection.conversionsTarget = noDuplicate;

View File

@@ -0,0 +1,141 @@
import * as vscode from 'vscode';
import { cyclicConvertCaseOrder, quickPickSupportCases, commands } from './types/SupportVariableCaseType';
import { getUserConfigurations } from '../../utils/user-configuration';
/**
* 显示当前配置的格式顺序信息
*/
export function showConvertCaseDetailDialog() {
// 获取用户配置的格式顺序
const formatOrder = getUserConfigurations<string[]>('formatOrder') || [];
// 获取启用的格式
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
// 创建格式名称映射
const formatNameMap: Record<string, string> = {};
quickPickSupportCases.forEach(item => {
formatNameMap[item.settingsKey] = item.name;
});
// 获取所有有效的settingsKey
const validSettingsKeys = new Set(quickPickSupportCases.map(item => item.settingsKey));
// 检测重复项和无效项
const seenSettingsKeys = new Set<string>();
const duplicateSettingsKeys = new Set<string>();
const invalidSettingsKeys = new Set<string>();
formatOrder.forEach(format => {
if (!validSettingsKeys.has(format)) {
invalidSettingsKeys.add(format);
} else if (seenSettingsKeys.has(format)) {
duplicateSettingsKeys.add(format);
} else {
seenSettingsKeys.add(format);
}
});
// 创建settingsKey到enableSettingsKey的映射
const settingsKeyToEnableKeyMap: Record<string, string> = {};
commands.forEach(item => {
settingsKeyToEnableKeyMap[item.settingsKey] = item.enableSettingsKey;
});
// 构建显示内容
const message = [
'当前配置的变量命名格式顺序:\n\n',
];
// 先显示用户配置的顺序
if (formatOrder.length > 0) {
message.push('用户自定义顺序:\n');
formatOrder.forEach((format, index) => {
const enableKey = settingsKeyToEnableKeyMap[format];
const isEnabled = enableKey ? enabledFormats[enableKey] !== false : true;
const status = isEnabled ? '✔️' : '❌'; // ✅✔️☑️
// 添加重复和无效标记
let marker = '';
if (!validSettingsKeys.has(format)) {
marker = ' ❌ (无效格式)';
} else if (duplicateSettingsKeys.has(format)) {
marker = ' ⚠️ (重复配置)';
}
message.push(`${index + 1}. ${formatNameMap[format] || format} (${format}) ${marker || status}\n`);
});
} else {
message.push('未设置自定义顺序,使用默认顺序\n\n');
}
// 显示未配置但已启用的格式
const unconfiguredEnabledFormats = cyclicConvertCaseOrder
.filter(item => {
const enableKey = settingsKeyToEnableKeyMap[item.settingsKey];
const isEnabled = enableKey ? enabledFormats[enableKey] !== false : true;
return isEnabled && !formatOrder.includes(item.settingsKey);
})
.map(item => item.settingsKey);
if (unconfiguredEnabledFormats.length > 0) {
message.push('\n未配置但已启用的格式默认顺序\n');
unconfiguredEnabledFormats.forEach((format, index) => {
message.push(`${formatOrder.length + index + 1}. ${formatNameMap[format] || format} (${format}) ✔️\n`);
});
}
// 显示未启用的格式
const disabledFormats = cyclicConvertCaseOrder
.filter(item => {
const enableKey = settingsKeyToEnableKeyMap[item.settingsKey];
return enableKey ? enabledFormats[enableKey] === false : false;
})
.map(item => item.settingsKey);
if (disabledFormats.length > 0) {
message.push('\n未启用的格式\n');
disabledFormats.forEach(format => {
message.push(`- ${formatNameMap[format] || format} (${format}) ❌\n`);
});
}
// 警告信息
if (duplicateSettingsKeys.size > 0 || invalidSettingsKeys.size > 0) {
message.push('\n');
if (duplicateSettingsKeys.size > 0) {
message.push(`⚠️ 警告:发现重复配置的格式:${Array.from(duplicateSettingsKeys).join(', ')}\n`);
}
if (invalidSettingsKeys.size > 0) {
message.push(`❌ 错误:发现无效格式:${Array.from(invalidSettingsKeys).join(', ')}\n`);
}
}
message.push(
'\n',
'提示:\n',
'- 未启用的格式即使在顺序中配置也不会显示在转换选项中\n',
'- 重复和无效的格式配置可能会导致显示异常\n',
);
// 显示信息弹窗
vscode.window.showInformationMessage<vscode.MessageItem>(
'变量转换功能配置信息',
{ modal: true, detail: message.join('') },
// 弹窗按钮
{ title: '插件全部配置' },
{ title: '配置启用的命名方式' },
{ title: '配置转换顺序' },
).then(selection => {
if (selection) {
// 跳转到设置项
if (selection.title === '插件全部配置') {
vscode.commands.executeCommand('workbench.action.openSettings', 'variable-conversion');
} else if (selection.title === '配置启用的命名方式') {
vscode.commands.executeCommand('workbench.action.openSettings', 'variable-conversion.enabledFormats');
} else if (selection.title === '配置转换顺序') {
vscode.commands.executeCommand('workbench.action.openSettings', 'variable-conversion.formatOrder');
}
}
});
}

View File

@@ -417,6 +417,12 @@ export const commands: Array<Command> = [
}, },
]; ];
// settingsKey 到 enableSettingsKey 的映射
export const settingsKeyToEnableSettingsKey = new Map<string, string>();
commands.forEach(command => {
settingsKeyToEnableSettingsKey.set(command.settingsKey, command.enableSettingsKey);
});
export interface QuickPickSupportCaseItem { export interface QuickPickSupportCaseItem {
type: SupportVariableCase, type: SupportVariableCase,
name: string, name: string,

View File

@@ -17,6 +17,7 @@ import handleEditorReplaceVariable from './handler/variable-convert/editor-subme
import { handleQuickPick as handleQuickPickVariable } from './handler/variable-convert/quick-pick-handler'; import { handleQuickPick as handleQuickPickVariable } from './handler/variable-convert/quick-pick-handler';
import { commands as variableCommands } from './core/variable-convert/types/SupportVariableCaseType'; import { commands as variableCommands } from './core/variable-convert/types/SupportVariableCaseType';
import * as CyclicConversionVariable from './core/variable-convert/cyclic-conversion'; import * as CyclicConversionVariable from './core/variable-convert/cyclic-conversion';
import { showConvertCaseDetailDialog } from './core/variable-convert/show-convert-case-order-dialog';
// Path Convert // Path Convert
import handleEditorReplacePath from './handler/path-convert/editor-submenu-handler'; import handleEditorReplacePath from './handler/path-convert/editor-submenu-handler';
@@ -156,6 +157,10 @@ export function activate(context: vscode.ExtensionContext) {
}); });
context.subscriptions.push(loopConvertCaseNextDisposable); context.subscriptions.push(loopConvertCaseNextDisposable);
// 注册显示格式顺序信息的命令
let showConvertCaseDetailDialogDisposable = vscode.commands.registerCommand('variable-conversion.showConvertCaseDetailDialog', showConvertCaseDetailDialog);
context.subscriptions.push(showConvertCaseDetailDialogDisposable);
/** /**
* 路径转换 * 路径转换

View File

@@ -1,6 +1,6 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import QuickPickItemEx from "../types/QuickPickItemExType"; import QuickPickItemEx from "../types/QuickPickItemExType";
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../../core/variable-convert/types/SupportVariableCaseType'; import { QuickPickSupportCaseItem, quickPickSupportCases, settingsKeyToEnableSettingsKey } from '../../core/variable-convert/types/SupportVariableCaseType';
import { TransformTextResult } from '../../types/TransformTextResultType'; import { TransformTextResult } from '../../types/TransformTextResultType';
import { transformMultiSelectionText } from '../../utils/transform'; import { transformMultiSelectionText } from '../../utils/transform';
import { EOL } from '../../types/EOLType'; import { EOL } from '../../types/EOLType';
@@ -101,22 +101,54 @@ export function handleQuickPick() {
return; return;
} }
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
// 获取用户配置 // 获取用户配置
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {}; const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
const formatOrder = getUserConfigurations<string[]>('formatOrder') || [];
// 排除禁用的选项 // 排除禁用的选项
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
const enabledQuickPickSupportCases = []; const enabledQuickPickSupportCases = [];
for (const quickPick of quickPickSupportCases) { for (const quickPick of quickPickSupportCases) {
if (enabledFormats[quickPick.settingsKey] === false) { const enableSettingsKey = settingsKeyToEnableSettingsKey.get(quickPick.settingsKey);
if (!enableSettingsKey) {
console.warn('Cannot find enableSettingsKey for settingsKey:', quickPick.settingsKey);
continue;
}
if (enabledFormats[enableSettingsKey] !== true) {
continue; continue;
} }
enabledQuickPickSupportCases.push(quickPick); enabledQuickPickSupportCases.push(quickPick);
} }
if (enabledQuickPickSupportCases.length === 0) { if (enabledQuickPickSupportCases.length === 0) {
vscode.window.showInformationMessage('所有格式都已被配置为禁用,请修改配置 `variable-conversion.enabledFormats` 后重试\nAll formats have been configured to disable. Modify the `variable-conversion.enabledFormats` 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;
} }
// 按用户配置的顺序排序
// issue: #5 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/5
// issue: #6 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/6
if (formatOrder.length > 0) {
enabledQuickPickSupportCases.sort((a, b) => {
const indexA = formatOrder.indexOf(a.settingsKey);
const indexB = formatOrder.indexOf(b.settingsKey);
// 如果两个都在配置中,按配置顺序
if (indexA !== -1 && indexB !== -1) {
return indexA - indexB;
}
// 如果只有一个在配置中,在配置中的排在前面
if (indexA !== -1) {
return -1;
}
if (indexB !== -1) {
return 1;
}
// 如果都不在配置中,保持原有顺序
return 0;
});
}
// 基于选中的文本生成选项 // 基于选中的文本生成选项
const options = generateOptionsBasedOnText(textList, eol, enabledQuickPickSupportCases); const options = generateOptionsBasedOnText(textList, eol, enabledQuickPickSupportCases);
if (options.length === 0) { if (options.length === 0) {