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

QuickPick 菜单支持过滤用户配置的禁用格式 (disableFormat)

This commit is contained in:
2024-07-29 22:32:06 +08:00
parent f8fe40c374
commit 68ffcc49f7
5 changed files with 200 additions and 18 deletions

View File

@@ -1,11 +1,12 @@
import * as vscode from 'vscode';
import QuickPickItemEx from "../type-definition/QuickPickItemExType";
import { quickPickSupportCases } from '../type-definition/SupportCaseType';
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../type-definition/SupportCaseType';
import { TransformTextResult } from '../type-definition/TransformTextResultType';
import { transformMutliLineText, transformMutliSelectionText } from '../main-code/transform';
import { transformMutliSelectionText } from '../main-code/transform';
import { EOL } from '../type-definition/EOLType';
import { caseConversion } from '../main-code/conversion';
import { isStringArrayEqual } from '../main-code/utils';
import { getUserConfigurations } from '../main-code/user-configuration';
const QuickPickLabelMaxLength = 60;
@@ -18,12 +19,12 @@ interface RecommendItem {
/**
* 弹出的提示
*/
function generateOptionsBasedOnText(textList: string[], eol: EOL): Array<QuickPickItemEx> {
function generateOptionsBasedOnText(textList: string[], eol: EOL, enabledQuickPickSupportCases: Array<QuickPickSupportCaseItem>): Array<QuickPickItemEx> {
// Cut text 切割文本
const resultsList: Array<TransformTextResult[]> = transformMutliSelectionText(textList);
const mergeResultList: Array<RecommendItem> = [];
for (const quickPick of quickPickSupportCases) {
for (const quickPick of enabledQuickPickSupportCases) {
const conversionResults: Array<string> = [];
for (let i = 0; i < textList.length; i++) {
const text = textList[i];
@@ -95,8 +96,24 @@ export function handleQuickPick() {
return;
}
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
// 获取用户配置
const disableFormatList = getUserConfigurations('disableFormat');
// 排除禁用的选项
const enabledQuickPickSupportCases = [];
for (const quickPick of quickPickSupportCases) {
if (disableFormatList.includes(quickPick.settingsKey)) {
continue;
}
enabledQuickPickSupportCases.push(quickPick);
}
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.');
return;
}
// 基于选中的文本生成选项
const options = generateOptionsBasedOnText(textList, eol);
const options = generateOptionsBasedOnText(textList, eol, enabledQuickPickSupportCases);
if (options.length === 0) {
vscode.window.showInformationMessage('所选内容暂无可选转换,请尝试重新选择\nNo conversion candidates are available for the selected content, please try to select another text.');
return;

View File

@@ -0,0 +1,14 @@
const vscode = require('vscode');
function getUserConfigurations(configKey: string) {
const config = vscode.workspace.getConfiguration('variable-conversion');
// 获取 disableFormat 配置项
const configValue = config.get(configKey);
console.log('configValue:', configValue);
return configValue;
}
export {
getUserConfigurations
};

View File

@@ -309,130 +309,158 @@ export const commands: Array<{ command: string; targetCase: SupportCase }> = [
{ command: 'variable-conversion.toUpperCase', targetCase: SupportCase.UPPER_CASE },
];
export interface QuickPickSupportCaseItem {
type: SupportCase,
name: string,
shortName: string,
keyword: string[],
settingsKey: string,
}
/**
* 所有支持的命名方式
* @since 2024-04-06
*/
export const quickPickSupportCases = [
export const quickPickSupportCases: Array<QuickPickSupportCaseItem> = [
{
type: SupportCase.CAMEL_CASE,
name: '小驼峰(驼峰)命名',
shortName: '小驼峰',
keyword: keyword.camel,
settingsKey: 'camel_case',
},
{
type: SupportCase.PASCAL_CASE,
name: '大驼峰(帕斯卡)命名',
shortName: '帕斯卡',
keyword: keyword.pascal,
settingsKey: 'pascal_case',
},
{
type: SupportCase.SNAKE_CASE,
name: '下划线(蛇形)命名',
shortName: '蛇形',
keyword: [...keyword.snake, ...keyword.lower],
settingsKey: 'snake_case',
},
{
type: SupportCase.SNAKE_CAMEL_CASE,
name: '下划线(蛇形) + 小驼峰(驼峰)命名',
shortName: '蛇形驼峰',
keyword: [...keyword.snake, ...keyword.camel],
settingsKey: 'snake_camel_case',
},
{
type: SupportCase.SNAKE_PASCAL_CASE,
name: '下划线(蛇形) + 大驼峰(帕斯卡)命名',
shortName: '蛇形帕斯卡',
keyword: [...keyword.snake, ...keyword.pascal],
settingsKey: 'snake_pascal_case',
},
{
type: SupportCase.SNAKE_UPPER_CASE,
name: '下划线(蛇形) + 全大写命名',
shortName: '蛇形大写',
keyword: [...keyword.snake, ...keyword.upper],
settingsKey: 'snake_upper_case',
},
{
type: SupportCase.KEBAB_CASE,
name: '中划线(连字符/脊柱式)命名',
shortName: '脊柱',
keyword: [...keyword.kebab, ...keyword.lower],
settingsKey: 'kebab_case',
},
{
type: SupportCase.KEBAB_CAMEL_CASE,
name: '中划线(连字符/脊柱式) + 小驼峰(驼峰)命名',
shortName: '脊柱驼峰',
keyword: [...keyword.kebab, ...keyword.camel],
settingsKey: 'kebab_camel_case',
},
{
type: SupportCase.KEBAB_PASCAL_CASE,
name: '中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名',
shortName: '脊柱帕斯卡',
keyword: [...keyword.kebab, ...keyword.pascal],
settingsKey: 'kebab_pascal_case',
},
{
type: SupportCase.KEBAB_UPPER_CASE,
name: '中划线(连字符/脊柱式) + 全大写命名',
shortName: '脊柱大写',
keyword: [...keyword.kebab, ...keyword.upper],
settingsKey: 'kebab_upper_case',
},
{
type: SupportCase.SPACE_CASE,
name: '空格分隔命名',
shortName: '脊柱',
keyword: [...keyword.space, ...keyword.lower],
settingsKey: 'space_case',
},
{
type: SupportCase.SPACE_CAMEL_CASE,
name: '空格分隔 + 小驼峰(驼峰)命名',
shortName: '脊柱驼峰',
keyword: [...keyword.space, ...keyword.camel],
settingsKey: 'space_camel_case',
},
{
type: SupportCase.SPACE_PASCAL_CASE,
name: '空格分隔 + 大驼峰(帕斯卡)命名',
shortName: '脊柱帕斯卡',
keyword: [...keyword.space, ...keyword.pascal],
settingsKey: 'space_pascal_case',
},
{
type: SupportCase.SPACE_UPPER_CASE,
name: '空格分隔 + 全大写命名',
shortName: '脊柱大写',
keyword: [...keyword.space, ...keyword.upper],
settingsKey: 'space_upper_case',
},
{
type: SupportCase.DOT_CASE,
name: '点分隔命名',
shortName: '脊柱',
keyword: [...keyword.dot, ...keyword.lower],
settingsKey: 'dot_case',
},
{
type: SupportCase.DOT_CAMEL_CASE,
name: '点分隔 + 小驼峰(驼峰)命名',
shortName: '脊柱驼峰',
keyword: [...keyword.dot, ...keyword.camel],
settingsKey: 'dot_camel_case',
},
{
type: SupportCase.DOT_PASCAL_CASE,
name: '点分隔 + 大驼峰(帕斯卡)命名',
shortName: '脊柱帕斯卡',
keyword: [...keyword.dot, ...keyword.pascal],
settingsKey: 'dot_pascal_case',
},
{
type: SupportCase.DOT_UPPER_CASE,
name: '点分隔 + 全大写命名',
shortName: '脊柱大写',
keyword: [...keyword.dot, ...keyword.upper],
settingsKey: 'dot_upper_case',
},
{
type: SupportCase.LOWER_CASE,
name: '全小写',
shortName: '小写',
keyword: keyword.lower,
settingsKey: 'lower_case',
},
{
type: SupportCase.UPPER_CASE,
name: '全大写',
shortName: '大写',
keyword: keyword.upper,
settingsKey: 'upper_case',
},
];