Compare commits
10 Commits
1.1.0
...
6999fc30e8
Author | SHA1 | Date | |
---|---|---|---|
6999fc30e8 | |||
7d0c1a0a3e | |||
6c78c9e430 | |||
8354ebb1ca | |||
d7aa9ac403 | |||
922407bdb6 | |||
4c51b72892 | |||
57d6be7019 | |||
d3a4b0d79f | |||
66c429dd54 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -23,6 +23,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
-->
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Improvement
|
||||
|
||||
- Adjust the project code directory structure. (项目代码目录结构调整)
|
||||
|
||||
### Changed
|
||||
|
||||
- Do not display the editor context menu `Variable Conversion` option when text is not selected. (当未选中文本时,不显示右键菜单 `变量转换` 选项)
|
||||
|
||||
## 1.1.0
|
||||
|
||||
### Added
|
||||
|
@@ -6,8 +6,9 @@
|
||||
A powerful variable naming conversion extension. Supports one-key conversion & cyclic conversion. You can use it through the editer menu, shortcut keys and bottom bar.
|
||||
|
||||
- ✅ 支持多选区 Support multi-selection
|
||||
- ✅ 支持多窗口 (不支持子窗口状态栏) Support subwindow (subwindow status bar are not supported)
|
||||
- ✅ 支持多窗口 Support subwindow
|
||||
- ✅ 支持撤回 & 重做 Support undo & redo (Ctrl + Z / Ctrl + Y)
|
||||
- ✅ 支持禁用部分目标转换格式 Supports disabling some target conversion formats
|
||||
|
||||
> 🔭 Tips for Chinese users: 如果您无法看到下文图片,请[点这里](https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension/blob/main/README.md)查看
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"displayName": "Variable Conversion",
|
||||
"description": "一个强大的变量名转换插件,支持右键菜单、快捷键、状态栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、中划线(连字符/脊柱式)、空格分隔、点分隔、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), space, dot, lower, upper case, and more.",
|
||||
// 版本号
|
||||
"version": "1.1.0",
|
||||
"version": "2.0.0",
|
||||
// logo
|
||||
"icon": "image/logo.png",
|
||||
"publisher": "coder-xiaomo",
|
||||
@@ -209,7 +209,9 @@
|
||||
// 编辑器右键菜单
|
||||
"editor/context": [
|
||||
{
|
||||
"when": "editorTextFocus",
|
||||
// "when": "editorTextFocus",
|
||||
// 2024.12.07 当未选中文字时,隐藏 [变量转换] 右键菜单
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"command": "variable-conversion.convertCase",
|
||||
// "group": "1_modification@9"
|
||||
"group": "navigation@9"
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"name": "variable-conversion",
|
||||
"displayName": "Variable Conversion",
|
||||
"description": "一个强大的变量名转换插件,支持右键菜单、快捷键、状态栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、中划线(连字符/脊柱式)、空格分隔、点分隔、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), space, dot, lower, upper case, and more.",
|
||||
"version": "1.1.0",
|
||||
"version": "2.0.0",
|
||||
"icon": "image/logo.png",
|
||||
"publisher": "coder-xiaomo",
|
||||
"engines": {
|
||||
@@ -143,7 +143,7 @@
|
||||
"menus": {
|
||||
"editor/context": [
|
||||
{
|
||||
"when": "editorTextFocus",
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"command": "variable-conversion.convertCase",
|
||||
"group": "navigation@9"
|
||||
},
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { EOL } from '../type-definition/EOLType';
|
||||
import { SupportCase } from '../type-definition/SupportCaseType';
|
||||
import { TransformTextResult } from '../type-definition/TransformTextResultType';
|
||||
import { transformMutliLineText, transformText } from './transform';
|
||||
import { EOL } from '../../types/EOLType';
|
||||
import { SupportCase } from './types/SupportCaseType';
|
||||
import { TransformTextResult } from '../../types/TransformTextResultType';
|
||||
import { transformMutliLineText, transformText } from '../../utils/transform';
|
||||
|
||||
/**
|
||||
* 统一文本转换函数
|
||||
@@ -9,6 +9,7 @@ import { transformMutliLineText, transformText } from './transform';
|
||||
* @param {SupportCase} targetCase 目标文本情况
|
||||
* @param {string} str 用户选择的文本 user selection
|
||||
* @param {EOL} eol 行结束符
|
||||
* @param {Array<TransformTextResult>?} cutText 行结束符
|
||||
* @returns 转换后的文本
|
||||
* @since 2024-04-04
|
||||
*/
|
@@ -1,9 +1,9 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from "../type-definition/EOLType";
|
||||
import { cyclicConvertCaseOrder } from "../type-definition/SupportCaseType";
|
||||
import { EOL } from "../../types/EOLType";
|
||||
import { cyclicConvertCaseOrder } from "./types/SupportCaseType";
|
||||
import { caseConversion } from "./conversion";
|
||||
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from './utils';
|
||||
import { getUserConfigurations } from './user-configuration';
|
||||
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils';
|
||||
import { getUserConfigurations } from '../../utils/user-configuration';
|
||||
|
||||
interface UserSelection {
|
||||
currentEol: EOL
|
||||
@@ -66,7 +66,7 @@ function lazyConvert() {
|
||||
}
|
||||
|
||||
// 获取用户配置
|
||||
const disableFormatList = getUserConfigurations('disableFormat');
|
||||
const disableFormatList = getUserConfigurations<Array<string>>('disableFormat') || [];
|
||||
|
||||
const textList = userSelection.currentSelectionsText;
|
||||
// vscode.window.showInformationMessage('lazyConvert' + textList.join('\n'));
|
@@ -4,10 +4,10 @@
|
||||
* Code:
|
||||
* - Add type definition in below `SupportCase` enum and following array
|
||||
* - Add `commands`, `menus`, `configuration` parts in [package.json] and [package-comment.jsonc]
|
||||
* - Add main conversion logic in [src/main-code/conversion.ts]
|
||||
* - Add main conversion logic in [src/core/variable-convert/conversion.ts]
|
||||
*
|
||||
* Test:
|
||||
* - Add test case type definition in [src/type-definition/TestCaseType.ts]
|
||||
* - Add test case type definition in [src/test/types/TestCaseType.ts]
|
||||
* - Add test case in [src/test/test-case.ts]
|
||||
* - Add test code in [src/test/extension.test.ts]
|
||||
*
|
@@ -1,13 +1,23 @@
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
/**
|
||||
* @file extension.ts
|
||||
* @description 该文件包含了 VS Code 插件的主要扩展逻辑,包括命令注册、菜单配置和编辑器事件监听等。
|
||||
* @author coder-xiaomo
|
||||
* @version 1.0.0
|
||||
* @license MIT
|
||||
*
|
||||
* 本文件是插件的核心文件,负责扩展命令的注册以及编辑器中各种事件的处理。通过监听编辑器的选择状态,
|
||||
* 动态更新命令行为。插件在启动时会初始化必要的命令,并根据编辑器状态决定是否启用相关功能。
|
||||
*
|
||||
* @see https://code.visualstudio.com/api
|
||||
*/
|
||||
import * as vscode from 'vscode';
|
||||
import handleEditorReplace from './extension-handler/editor-submenu-handler';
|
||||
import { handleQuickPick } from './extension-handler/quick-pick-handler';
|
||||
import { commands } from './type-definition/SupportCaseType';
|
||||
import { createStatusBarItem, updateStatusBarItemVisable } from './extension-handler/status-bar-handler';
|
||||
import * as CyclicConversion from './main-code/cyclic-conversion';
|
||||
import { EOL } from './type-definition/EOLType';
|
||||
import { getUserConfigurations } from './main-code/user-configuration';
|
||||
import handleEditorReplace from './handler/editor-submenu-handler';
|
||||
import { handleQuickPick } from './handler/quick-pick-handler';
|
||||
import { commands } from './core/variable-convert/types/SupportCaseType';
|
||||
import { createStatusBarItem, updateStatusBarItemVisable } from './handler/status-bar-handler';
|
||||
import * as CyclicConversion from './core/variable-convert/cyclic-conversion';
|
||||
import { EOL } from './types/EOLType';
|
||||
import { getUserConfigurations } from './utils/user-configuration';
|
||||
|
||||
// This method is called when your extension is activated
|
||||
// Your extension is activated the very first time the command is executed
|
||||
@@ -44,7 +54,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||
// 获取用户配置
|
||||
const disableFormatList = getUserConfigurations('disableFormat');
|
||||
const disableFormatList = getUserConfigurations<Array<string>>('disableFormat') || [];
|
||||
// 更新右键菜单每一项是否展示
|
||||
for (const { settingsKey } of commands) {
|
||||
vscode.commands.executeCommand('setContext', '_isHideSubMenuItem_' + settingsKey, disableFormatList.includes(settingsKey));
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from '../type-definition/EOLType';
|
||||
import { caseConversion } from '../main-code/conversion';
|
||||
import { SupportCase } from '../type-definition/SupportCaseType';
|
||||
import { isStringArrayEqual } from '../main-code/utils';
|
||||
import { EOL } from '../types/EOLType';
|
||||
import { caseConversion } from '../core/variable-convert/conversion';
|
||||
import { SupportCase } from '../core/variable-convert/types/SupportCaseType';
|
||||
import { isStringArrayEqual } from '../utils/utils';
|
||||
|
||||
/**
|
||||
* 编辑器右键菜单
|
@@ -1,12 +1,12 @@
|
||||
import * as vscode from 'vscode';
|
||||
import QuickPickItemEx from "../type-definition/QuickPickItemExType";
|
||||
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../type-definition/SupportCaseType';
|
||||
import { TransformTextResult } from '../type-definition/TransformTextResultType';
|
||||
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';
|
||||
import QuickPickItemEx from "./types/QuickPickItemExType";
|
||||
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../core/variable-convert/types/SupportCaseType';
|
||||
import { TransformTextResult } from '../types/TransformTextResultType';
|
||||
import { transformMutliSelectionText } from '../utils/transform';
|
||||
import { EOL } from '../types/EOLType';
|
||||
import { caseConversion } from '../core/variable-convert/conversion';
|
||||
import { isStringArrayEqual } from '../utils/utils';
|
||||
import { getUserConfigurations } from '../utils/user-configuration';
|
||||
|
||||
const QuickPickLabelMaxLength = 60;
|
||||
|
||||
@@ -98,7 +98,7 @@ export function handleQuickPick() {
|
||||
|
||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||
// 获取用户配置
|
||||
const disableFormatList = getUserConfigurations('disableFormat');
|
||||
const disableFormatList = getUserConfigurations<Array<string>>('disableFormat') || [];
|
||||
// 排除禁用的选项
|
||||
const enabledQuickPickSupportCases = [];
|
||||
for (const quickPick of quickPickSupportCases) {
|
@@ -1,14 +0,0 @@
|
||||
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
|
||||
};
|
@@ -3,12 +3,12 @@ import * as assert from 'assert';
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
import testGroups from './test-case';
|
||||
import { TestCase, TestCaseGroup } from '../type-definition/TestCaseType';
|
||||
import { transformMutliLineText, transformText } from '../main-code/transform';
|
||||
import { caseConversion } from '../main-code/conversion';
|
||||
import { SupportCase } from '../type-definition/SupportCaseType';
|
||||
import { TransformTextResult } from '../type-definition/TransformTextResultType';
|
||||
import { pathConvertTestGroups } from './test-case/path-convert-test-case';
|
||||
import { TestCase, TestCaseGroup } from './test-case/types/TestCaseType';
|
||||
import { transformMutliLineText, transformText } from '../utils/transform';
|
||||
import { caseConversion } from '../core/variable-convert/conversion';
|
||||
import { SupportCase } from '../core/variable-convert/types/SupportCaseType';
|
||||
import { TransformTextResult } from '../types/TransformTextResultType';
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
/*
|
||||
@@ -22,10 +22,15 @@ suite('Extension Test Suite', () => {
|
||||
});
|
||||
*/
|
||||
|
||||
suite('Extension Test: run test case', () => {
|
||||
/**
|
||||
* 变量转换 测试函数
|
||||
*
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
suite('Extension Test: run variable convert test case', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
const groups: Array<TestCaseGroup> = testGroups;
|
||||
const groups: Array<TestCaseGroup> = pathConvertTestGroups;
|
||||
for (const testGroup of groups) {
|
||||
const testTitle = testGroup.testTitle;
|
||||
const testCases: Array<TestCase> = testGroup.cases;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { TestCaseGroup } from "../type-definition/TestCaseType";
|
||||
import { TestCaseGroup } from "./types/TestCaseType";
|
||||
|
||||
const LF = '\n';
|
||||
const CRLF = '\r\n';
|
||||
|
||||
const testGroups: Array<TestCaseGroup> = [
|
||||
export const pathConvertTestGroups: Array<TestCaseGroup> = [
|
||||
{
|
||||
group: 'Input validation',
|
||||
testTitle: 'Input validation (输入有效性验证)',
|
||||
@@ -1095,5 +1095,3 @@ const testGroups: Array<TestCaseGroup> = [
|
||||
},
|
||||
// add more cases...
|
||||
];
|
||||
|
||||
export default testGroups;
|
@@ -1,4 +1,4 @@
|
||||
import { EOL } from "./EOLType";
|
||||
import { EOL } from "../../../types/EOLType";
|
||||
|
||||
export type TestCaseGroup = {
|
||||
group: string
|
@@ -1,4 +1,4 @@
|
||||
import { TransformTextResult } from "../type-definition/TransformTextResultType";
|
||||
import { TransformTextResult } from "../types/TransformTextResultType";
|
||||
|
||||
const logDebugInfo = false;
|
||||
|
20
src/utils/user-configuration.ts
Normal file
20
src/utils/user-configuration.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import vscode from 'vscode';
|
||||
|
||||
/**
|
||||
* 获取用户配置项
|
||||
*
|
||||
* @param configKey 配置项的键
|
||||
* @returns 配置项的值
|
||||
* @since 2024-07-29
|
||||
*/
|
||||
function getUserConfigurations<T>(configKey: string): T | undefined {
|
||||
const config = vscode.workspace.getConfiguration('variable-conversion');
|
||||
|
||||
const configValue = config.get<T>(configKey);
|
||||
// console.log('configValue:', configValue);
|
||||
return configValue;
|
||||
}
|
||||
|
||||
export {
|
||||
getUserConfigurations
|
||||
};
|
@@ -1,3 +1,11 @@
|
||||
/**
|
||||
* 比较两个字符串数组 `Array<string>` 是否相同
|
||||
*
|
||||
* @param array1 数组1
|
||||
* @param array2 数组2
|
||||
* @returns
|
||||
* @since 2024-04-09
|
||||
*/
|
||||
export function isStringArrayEqual(array1: string[], array2: string[]) {
|
||||
if (array1.length !== array2.length) {
|
||||
return false;
|
||||
@@ -12,6 +20,15 @@ export function isStringArrayEqual(array1: string[], array2: string[]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除二维字符串数组中的重复数组元素
|
||||
*
|
||||
* 例如,输入 [["a", "b"], ["a", "b"], ["c", "d"]],会返回 [[ "a", "b"], ["c", "d"]],去除了重复出现的 ["a", "b"]。
|
||||
*
|
||||
* @param stringArr 要进行去重操作的二维字符串数组,即数组中每个元素又是一个字符串数组,代表一组相关的字符串元素集合。
|
||||
* @returns 返回一个二维字符串数组,其中已经去除了原输入二维数组中重复的元素组合,基于JSON序列化后的字符串比较来判定重复与否。
|
||||
* @since 2024-04-09
|
||||
*/
|
||||
export function stringListArrayDuplicateRemoval(stringArr: Array<string[]>): Array<string[]> {
|
||||
const tempArr: Array<string> = [];
|
||||
const newArr: Array<string[]> = [];
|
Reference in New Issue
Block a user