Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0d92fbe4ec | |||
![]() |
50354d52b8 |
@@ -1,26 +0,0 @@
|
||||
# EditorConfig is awesome: https://editorconfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
insert_final_newline = true
|
||||
|
||||
# Set default charset
|
||||
charset = utf-8
|
||||
|
||||
[*.{js,ts}]
|
||||
# 4 space indentation
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[.vscode/**.json]
|
||||
indent_style = tab
|
||||
|
||||
# 历史原因需要保留 tab 缩进的代码文件
|
||||
[src/{test/extension.test.ts,extension.ts}]
|
||||
indent_style = tab
|
30
.eslintrc.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": [
|
||||
"warn",
|
||||
{
|
||||
"selector": "import",
|
||||
"format": [ "camelCase", "PascalCase" ]
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"out",
|
||||
"dist",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
}
|
2
.vscode/extensions.json
vendored
@@ -3,6 +3,6 @@
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"ms-vscode.extension-test-runner"
|
||||
"ms-vscode.extension-test-runner"
|
||||
]
|
||||
}
|
||||
|
3
.vscode/launch.json
vendored
@@ -10,8 +10,7 @@
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--disable-extensions", // 调试时禁用其他扩展
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
|
24
.vscode/settings.json
vendored
@@ -1,17 +1,11 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off",
|
||||
|
||||
// Code Spell Checker 插件
|
||||
"cSpell.words": [
|
||||
"Gitee",
|
||||
"coder-xiaomo"
|
||||
],
|
||||
}
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
@@ -5,7 +5,7 @@ src/**
|
||||
.yarnrc
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/eslint.config.mjs
|
||||
**/.eslintrc.json
|
||||
**/*.map
|
||||
**/*.ts
|
||||
**/.vscode-test.*
|
||||
|
55
CHANGELOG.md
@@ -21,64 +21,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Removed
|
||||
|
||||
### Internal
|
||||
|
||||
-->
|
||||
|
||||
## 2.1.0
|
||||
|
||||
### Changed
|
||||
|
||||
- **[BREAKING!!!]** Deprecate `variable-conversion.disableFormat`, please use `variable-conversion.enabledFormats` instead. (移除 `variable-conversion.disableFormat` 配置项,请使用 `variable-conversion.enabledFormats`)
|
||||
- Support enabling only partial target conversion formats. (支持仅开启部分目标转换格式)
|
||||
|
||||
## 2.0.1
|
||||
|
||||
### Internal
|
||||
|
||||
- Add `.editorconfig` file. (添加 `.editorconfig` 文件)
|
||||
- Upgrade plugin dependency versions. (升级插件依赖版本)
|
||||
- Modify eslint configuration. (调整 eslint 配置)
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- New: Support path conversions via shortcut keys `Ctrl + Alt + /` and `Ctrl + Shift + Alt + /` (also supports multi-selection conversion). (支持通过 `Ctrl + Alt + /`, `Ctrl + Shift + Alt + /` 快捷键进行路径转换 (同时支持多选区转换))
|
||||
- New: Support following path conversion type: QuickPick menu conversion, context menu conversion, status bar button conversion, shortcut key conversion. (支持以下路径转换方式:QuickPick 菜单转换、右键菜单转换、状态栏按钮转换、快捷键转换)
|
||||
|
||||
### Changed
|
||||
|
||||
- Do not display the editor context menu `Variable Conversion` option when text is not selected. (当未选中文本时,不显示右键菜单 `变量转换` 选项)
|
||||
|
||||
### Improvement
|
||||
|
||||
- Adjust the project code directory structure. (项目代码目录结构调整)
|
||||
|
||||
## 1.1.0
|
||||
|
||||
### Added
|
||||
|
||||
- Support configuring which formats are disabled through the VSCode settings page. It will apply to QuickPick menu conversions, context menu conversions, and shortcut key cyclic conversions. (支持通过 VSCode 设置页配置哪些格式是禁用的。配置后将同时对 QuickPick 菜单转换、右键菜单转换、快捷键循环转换生效)
|
||||
|
||||
## 1.0.11
|
||||
|
||||
### Improvement
|
||||
|
||||
- Imperfect support: When a sub window is activated, clicking on the status bar of the main window can correctly bring up the QuickPick menu. (不完美支持:当子窗口激活时,点击主窗口状态栏能够正确弹出快速拾取菜单)
|
||||
|
||||
## 1.0.10
|
||||
|
||||
### Added
|
||||
|
||||
- Add 4 new conversion types: Dot Case, Dot Camel Case, Dot Pascal Case, Dot Upper Case (新增 4 种转换类型: 点分隔 + 全小写/小驼峰/大驼峰/全大写)
|
||||
|
||||
## 1.0.8
|
||||
|
||||
### Added
|
||||
|
||||
- New: Supports multi-selection conversion (支持多选区转换)
|
||||
- New: Supports scrolling variable conversion via shortcut keys `Ctrl + Alt + [` and `Ctrl + Alt + ]` (also supports multi-selection conversion). (支持通过 `Ctrl + Alt + [`, `Ctrl + Alt + ]` 快捷键进行变量循环转换 (同时支持多选区转换))
|
||||
- New: Supports scrolling conversion via shortcut keys `Ctrl + Alt + [` and `Ctrl + Alt + ]` (also supports multi-selection conversion) 支持通过快捷键循环转换 (同时支持多选区转换)
|
||||
|
||||
## 1.0.7
|
||||
|
||||
@@ -103,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
- Fix bug: The infobox showed `editor is undefined` when the current active TAB was not an editor
|
||||
|
||||
|
||||
## 1.0.4
|
||||
|
||||
### Added
|
||||
@@ -127,4 +78,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Adds an editor context menu with submenu
|
||||
- Implement conversion to Camel Case, Pascal Case, Snake Case(Snake Camel, Snake Pascal, Snake Upper), Kebab Case(Kebab Camel, Kebab Pascal, Kebab Upper), Lower Case, Upper Case
|
||||
- Add test cases
|
||||
- Initial release
|
||||
- Initial release
|
71
Publish.md
@@ -1,71 +0,0 @@
|
||||
# 如何发行你的插件
|
||||
|
||||
vsce login coder-xiaomo
|
||||
|
||||
重要!删除 out 目录,并切到 release 分支再进行打包,避免打入其他无用文件
|
||||
|
||||
vsce publish
|
||||
|
||||
INFO Publishing 'coder-xiaomo.variable-conversion v0.0.1'...
|
||||
INFO Extension URL (might take a few minutes): https://marketplace.visualstudio.com/items?itemName=coder-xiaomo.variable-conversion
|
||||
INFO Hub URL: https://marketplace.visualstudio.com/manage/publishers/coder-xiaomo/extensions/variable-conversion/hub
|
||||
DONE Published coder-xiaomo.variable-conversion v0.0.1.
|
||||
|
||||
具体步骤参考:
|
||||
https://zhuanlan.zhihu.com/p/339695661
|
||||
|
||||
## 安装官方打包工具
|
||||
|
||||
首先我们要安装上这个官方的插件发行工具,可以把我们的插件工程打包成.vsix文件,也可以直接发布到插件市场当中
|
||||
npm i vsce -g
|
||||
|
||||
后面使用命令发行插件时,如果你没有设置package.json里的repository会收到提示。但不是非要填(插件可以不开源),选N即可。
|
||||
|
||||
## 打包成 .vsix 文件
|
||||
|
||||
vsce package
|
||||
|
||||
打包完成后,会在工程目录生成.vsix文件,这个文件的安装只能通过插件搜索右上方的菜单来进行
|
||||
|
||||
|
||||
## 把插件发行到插件市场
|
||||
|
||||
### 注册Azure开发者账号
|
||||
|
||||
先得有一个 微软通行证 https://login.live.com/ ,然后打开 azure开发者中心 https://aka.ms/SignupAzureDevOps ,新建一个 azure开发组织。
|
||||
|
||||
#### 新建个人令牌
|
||||
|
||||
注意选择 Full access 和 过期时间,如果令牌过期,需要回到这个页面再新建令牌。
|
||||
|
||||
|
||||
这步之后,一定要复制并保存好你的令牌字符串哦。之后只能新建,是找不到的。
|
||||
|
||||
### 注册插件市场发行账户
|
||||
|
||||
接着我们 注册插件市场发行账号,也在这可以管理所有市场中自己发布的插件。
|
||||
|
||||
|
||||
当然我们也可以使用vsce命令来创建发行账户
|
||||
|
||||
vsce create-publisher 发行账户名称
|
||||
|
||||
## 发行
|
||||
|
||||
vsce publish
|
||||
|
||||
这个过程里还会检查一些package.json的必填项,一切无误的话,就会看到下面这个图
|
||||
|
||||
|
||||
发行成功啦!
|
||||
|
||||
但此时我们的插件在市场中还搜不到,等个5-10分钟一般就有了。
|
||||
|
||||
|
||||
## 注意事项
|
||||
README.md是插件主页的详情介绍;
|
||||
记得更新package.json里的版本号;
|
||||
如果package.json中填写了repository字段,在发布时会要求你先提交仓库;
|
||||
README.md中的图片资源必须全部是HTTPS的;
|
||||
CHANGELOG.md是插件主页的变更选项卡;
|
||||
一但用户安装了你的插件,只要不卸载,插件有新版时后会自动更新的。
|
136
README.md
@@ -1,42 +1,37 @@
|
||||
# 变量命名转换助手 — Variable Conversion (VSCode 扩展)
|
||||
# 命名方式转换插件 Variable Conversion
|
||||
|
||||
[Marketplace](https://marketplace.visualstudio.com/items?itemName=coder-xiaomo.variable-conversion) [GitHub](https://github.com/coder-xiaomo/variable-conversion-vscode-extension.git) [Gitee](https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension.git)
|
||||
一个强大的变量名转换插件,支持一键转换、循环转换,支持右键菜单、快捷键、状态栏等多种方式使用。<br>
|
||||
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.
|
||||
|
||||
一个强大的变量命名及路径风格转换插件,支持一键转换、循环转换,支持右键菜单、快捷键、状态栏等多种方式使用。<br>
|
||||
A powerful variable and path conversion extension. Supports one-key conversion & cyclic conversion. You can use it through the editer menu, shortcut keys and status bar.
|
||||
|
||||
> **【近期更新】**
|
||||
>
|
||||
> **v2.1.0 (2025-07-14)**
|
||||
>
|
||||
> - 支持仅开启部分目标转换格式 (优化 VSCode 配置项)
|
||||
>
|
||||
> **v2.0.0 (2024-12-15)**
|
||||
>
|
||||
> - 支持 Windows / Unix 路径风格转换(可选中文本中的路径,然后使用 `Ctrl + Alt + /` 快捷键,或点击右键菜单、底部状态栏路径转换按钮轻松实现转换)
|
||||
|
||||
- ✅ 支持多选区 Support multi-selection
|
||||
- ✅ 支持多窗口 Support subwindow
|
||||
- ✅ 支持撤回 & 重做 Support undo & redo (Ctrl + Z / Ctrl + Y)
|
||||
- ✅ 支持仅开启部分目标转换格式 Support enabling only partial target conversion formats
|
||||
|
||||
> 🔭 Tips for Chinese users: 如果您无法看到下文图片,请[点这里](https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension/blob/main/README.md)查看
|
||||
- [x] 支持多选区 Support multi-selection
|
||||
- [x] 支持多窗口 (不支持子窗口状态栏) Support subwindow (subwindow status bar are not supported)
|
||||
- [x] 支持撤回 & 重做 Support undo & redo (Ctrl + Z / Ctrl + Y)
|
||||
|
||||
## 如何使用? How to Use?
|
||||
|
||||
### 循环转换 Cyclic conversion
|
||||
> 🔭 Tips for Chinese users: 如果您无法看到下文图片,请[点击这里查看](https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension/blob/main/README.md)
|
||||
|
||||
选中需要转换的内容,然后按下 `Ctrl + Alt + [` 或 `Ctrl + Alt + ]` 即可前后灵活切换变量命名方式。 <br>
|
||||
Select what you want to convert in the editor, and then press `Ctrl + Alt + [` or `Ctrl + Alt + ]` to flexibly convert variable name flexibly.
|
||||
### 循环转换(Beta) Cyclic conversion(Beta)
|
||||
|
||||
选中代码中需要转换的内容,然后按下 `Ctrl + Alt + [` and `Ctrl + Alt + ]` 即可前后灵活切换变量命名方式。
|
||||
|
||||

|
||||
|
||||
### 基础转换 Basic conversion
|
||||
### 基础转换
|
||||
|
||||
**1. 选中代码中需要转换的内容** **Select The Text To Convert**
|
||||
|
||||

|
||||
|
||||
> 小提示: <br>
|
||||
> 1. 可以先按住 `Alt` 键不放,再鼠标先后选中多个选区 <br>
|
||||
> 2. 可以先按住 `Shift + Alt` 键不放,再按下鼠标左键,使用鼠标滑过需要选中的区块 <br>
|
||||
> 3. 可以通过 `Ctrl + D` 快捷键选中光标所在的单词 <br>
|
||||
> Tips: <br>
|
||||
> 1. You can first hold down `Alt`, and then use the mouse to select multiple selection <br>
|
||||
> 2. You can first hold down `Shift + Alt`, then press the left mouse button, and use the mouse to slide over the block that needs to be selected <br>
|
||||
> 3. You can press `Ctrl + D` to select the word near the cursor <br>
|
||||
|
||||
**2. 按 `Shift + Alt + T`** **Press `Shift + Alt + T`**
|
||||
|
||||

|
||||
@@ -58,47 +53,18 @@ Or right-click on the selected text -> Convert string to...
|
||||
|
||||
**3. 选择转换目标,转换完成** **Select the conversion target and complete**
|
||||
|
||||
### 路径转换 Path Conversion (Beta)
|
||||
## 快捷键
|
||||
|
||||
> 该功能仍在 Beta 测试阶段,如您在使用过程中遇到问题,欢迎通过文末联系方式进行反馈。
|
||||
>
|
||||
> This feature is still in Beta testing stage, if you encounter any problems during use, please give feedback via the contact information at the end of the article.
|
||||
| 功能 Feature | 快捷键 shortcut key |
|
||||
| ------------------------------------------------ | ------------------- |
|
||||
| 变量转换 快速选择 QuickPick | Shift + Alt + T |
|
||||
| 循环转换→上一个 Cyclic conversion → Previous one | Ctrl + Alt + [ |
|
||||
| 循环转换→下一个 Cyclic conversion → Next one | Ctrl + Alt + ] |
|
||||
|
||||
路径转换与变量转换操作逻辑基本相同,都可以通过 *右键菜单*、*底部状态栏*、*快捷键* 等方式使用,唯一区别是快捷键的不同。
|
||||
|
||||
路径转换快捷键为:
|
||||
|
||||
- 切换下一个路径风格:`Ctrl + Alt + /`
|
||||
- 切换上一个路径风格:`Ctrl + Alt + Shift + /`
|
||||
|
||||

|
||||
|
||||
**注:** 目前 `v2.0.0` 版本暂仅支持 `Windows 风格路径` 与 `Unix 风格路径` 互转,所以这两个快捷键目前效果相同。**后续会陆续增加其他更多路径风格**(例如 `Windows Git Bash` 风格,浏览器 `file://` 协议风格等),敬请期待。
|
||||
|
||||
## 快捷键 Shortcut key
|
||||
|
||||
| 功能 Feature | 快捷键 shortcut key |
|
||||
| ------------------------------------------------------------ | ---------------------- |
|
||||
| 变量转换 快速选择 Variable Conversion QuickPick | Shift + Alt + T |
|
||||
| 变量循环转换→上一个 Variable Cyclic Conversion → Previous one | Ctrl + Alt + [ |
|
||||
| 变量循环转换→下一个 Variable Cyclic Conversion → Next one | Ctrl + Alt + ] |
|
||||
| 路径转换 快速选择 Path Conversion QuickPick | Shift + Alt + / |
|
||||
| 路径循环转换→上一个 Path Cyclic conversion → Previous one | Ctrl + Alt + / |
|
||||
| 路径循环转换→下一个 Path Cyclic conversion → Next one | Ctrl + Shift + Alt + / |
|
||||
|
||||
> 若您觉得快捷键使用不顺手,您可在 VSCode 左下角齿轮图标⚙ → 键盘快捷方式中自定义修改快捷键。
|
||||
|
||||
## 配置项 Configurations
|
||||
|
||||
| 配置项 Configuration Key | 描述 Description | 配置示例 | 默认值 |
|
||||
| --------------------------------------- | ------------------------------------------------------------ | ------------------------------------- | -------- |
|
||||
| `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"]` | 见配置项 |
|
||||
|
||||
## 支持的类型 Support Case
|
||||
|
||||
### 变量转换
|
||||
|
||||
| 类型 | Case | 举例 e.g. |
|
||||
| ------------------------------------------ | ------------------------ | ---------------- |
|
||||
| 小驼峰(驼峰)命名 | Camel Case | fooBar |
|
||||
@@ -115,44 +81,9 @@ Or right-click on the selected text -> Convert string to...
|
||||
| 空格分隔 + 小驼峰(驼峰)命名 | Space Camel Case | foo Bar |
|
||||
| 空格分隔 + 大驼峰(帕斯卡)命名 | Space Pascal Case | Foo Bar |
|
||||
| 空格分隔 + 全大写命名 | Space Upper Case | FOO BAR |
|
||||
| 点分隔命名 | Dot Case | foo.bar |
|
||||
| 点分隔 + 小驼峰(驼峰)命名 | Dot Camel Case | foo.Bar |
|
||||
| 点分隔 + 大驼峰(帕斯卡)命名 | Dot Pascal Case | Foo.Bar |
|
||||
| 点分隔 + 全大写命名 | Dot Upper Case | FOO.BAR |
|
||||
| 全小写 | Lower Case | foo_bar / foobar |
|
||||
| 全大写 | Upper Case | FOO_BAR / FOOBAR |
|
||||
|
||||
### 路径转换
|
||||
|
||||
现已支持的路径风格:
|
||||
|
||||
| 路径风格 | Sttyle | 举例 e.g. |
|
||||
| ------------ | ------------- | ---------------------------------------------- |
|
||||
| Windows 风格 | Windows Style | `C:\Windows\System32` <br />`.\public\assets\` |
|
||||
| Unix 风格 | Unix Style | `/usr/bin`<br />`./public/assets/` |
|
||||
|
||||
尚未支持的路径风格:
|
||||
|
||||
| 路径风格 | Case | 举例 e.g. |
|
||||
| -------------------------- | --------------------------------- | ------------------------------------- |
|
||||
| 👇未来计划支持 | | |
|
||||
| Windows 风格(反斜杠转义) | Windows Style (Backslash Escaped) | `C:\\Windows\\System32` |
|
||||
| Unix 风格(反斜杠转义) | Unix Style (Backslash Escaped) | `\/usr\/bin` |
|
||||
| Windows Git Bash 风格 | Windows Git Bash Style | `/c/Windows/System32` |
|
||||
| 👇未来可能支持 | | |
|
||||
| 浏览器 `file://` 协议风格 | | `file:///C:/Program%20Files%20(x86)/` |
|
||||
|
||||
## 小提示 Tips
|
||||
|
||||
#### 关于文本选区... About text selections...
|
||||
|
||||
- 可以先按住 `Alt` 键不放,再鼠标先后选中多个选区
|
||||
You can first hold down `Alt`, and then use the mouse to select multiple selection
|
||||
- 可以先按住 `Shift + Alt` 键不放,再按下鼠标左键,使用鼠标滑过需要选中的区块
|
||||
You can first hold down `Shift + Alt`, then press the left mouse button, and use the mouse to slide over the block that needs to be selected
|
||||
- 可以通过 `Ctrl + D` 快捷键选中光标所在的单词
|
||||
You can press `Ctrl + D` to select the word near the cursor
|
||||
|
||||
## 反馈 Feedback
|
||||
|
||||
如果您觉得本插件还不够好用,有更好的使用建议;或者发现了 BUG,欢迎[前往 GitHub 仓库提 issue](https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues). 使用简体中文、繁體中文或 English 均可,不建议使用翻译软件翻译,否则可能会让文字描述变得抽象难懂。<br>
|
||||
@@ -167,8 +98,19 @@ GitHub Repo (开源地址): https://github.com/coder-xiaomo/variable-conversion-
|
||||
|
||||
Gitee Mirror (码云镜像): https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension.git
|
||||
|
||||
-----
|
||||
<!--
|
||||
|
||||
**玩得开心!**
|
||||
## Extension Settings
|
||||
|
||||
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
|
||||
|
||||
For example:
|
||||
|
||||
This extension contributes the following settings:
|
||||
|
||||
* `myExtension.enable`: Enable/disable this extension.
|
||||
* `myExtension.thing`: Set to `blah` to do something.
|
||||
|
||||
-->
|
||||
|
||||
**Enjoy!**
|
||||
|
@@ -1,28 +0,0 @@
|
||||
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
|
||||
export default [{
|
||||
files: ["**/*.ts"],
|
||||
}, {
|
||||
plugins: {
|
||||
"@typescript-eslint": typescriptEslint,
|
||||
},
|
||||
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: 2022,
|
||||
sourceType: "module",
|
||||
},
|
||||
|
||||
rules: {
|
||||
"@typescript-eslint/naming-convention": ["warn", {
|
||||
selector: "import",
|
||||
format: ["camelCase", "PascalCase"],
|
||||
}],
|
||||
|
||||
curly: "warn",
|
||||
eqeqeq: "warn",
|
||||
"no-throw-literal": "warn",
|
||||
semi: "warn",
|
||||
},
|
||||
}];
|
Before Width: | Height: | Size: 241 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 20 KiB |
@@ -1,866 +0,0 @@
|
||||
{
|
||||
// 插件 id 及名称
|
||||
"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": "2.1.0",
|
||||
// logo
|
||||
"icon": "image/logo.png",
|
||||
"publisher": "coder-xiaomo",
|
||||
"engines": {
|
||||
"vscode": "^1.102.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
// 仓库地址
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/coder-xiaomo/variable-conversion-vscode-extension.git"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://git.only4.work/coder-xiaomo/variable-conversion-vscode-extension.git"
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension.git"
|
||||
}
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"activationEvents": [
|
||||
// 当编辑器完成启动时激活
|
||||
"onStartupFinished",
|
||||
// 当用户选中文本时激活
|
||||
"onTextSelected"
|
||||
],
|
||||
"contributes": {
|
||||
// docs: https://code.visualstudio.com/docs/getstarted/keybindings#_accepted-keys
|
||||
"keybindings": [
|
||||
// 绑定快捷键
|
||||
// ↓ 变量转换快捷键
|
||||
{
|
||||
"command": "variable-conversion.convertCase",
|
||||
"key": "shift+alt+t",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
// 循环转换 上一个
|
||||
{
|
||||
"command": "variable-conversion.cyclicConvertCase.previous",
|
||||
"key": "ctrl+alt+[",
|
||||
"args": {
|
||||
"arrowKey": "["
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
// 循环转换 下一个
|
||||
{
|
||||
"command": "variable-conversion.cyclicConvertCase.next",
|
||||
"key": "ctrl+alt+]",
|
||||
"args": {
|
||||
"arrowKey": "]"
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
// ↓ 路径转换快捷键
|
||||
{
|
||||
"command": "variable-conversion.convertPath",
|
||||
"key": "shift+alt+/",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
// 循环转换 上一个
|
||||
{
|
||||
"command": "variable-conversion.cyclicConvertPath.previous",
|
||||
"key": "ctrl+alt+shift+/",
|
||||
"args": {
|
||||
"direction": "<-"
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
// 循环转换 下一个
|
||||
{
|
||||
"command": "variable-conversion.cyclicConvertPath.next",
|
||||
"key": "ctrl+alt+/",
|
||||
"args": {
|
||||
"direction": "->"
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
}
|
||||
],
|
||||
"commands": [
|
||||
/**
|
||||
* 循环转换 可以不添加
|
||||
*/
|
||||
// {
|
||||
// "command": "variable-conversion.cyclicConvertCase.previous",
|
||||
// "title": "变量转换(上一个)"
|
||||
// },
|
||||
// {
|
||||
// "command": "variable-conversion.cyclicConvertCase.next",
|
||||
// "title": "变量转换(下一个)"
|
||||
// },
|
||||
/**
|
||||
* 右键菜单
|
||||
*/
|
||||
{
|
||||
"command": "variable-conversion.convertCase",
|
||||
"title": "变量转换"
|
||||
},
|
||||
/**
|
||||
* 右键菜单 - 子菜单
|
||||
*/
|
||||
// group-1-camel
|
||||
{
|
||||
"command": "variable-conversion.toCamelCase",
|
||||
"title": "小驼峰(驼峰)命名 (Camel Case) [ fooBar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toPascalCase",
|
||||
"title": "大驼峰(帕斯卡)命名 (Pascal Case) [ FooBar ]"
|
||||
},
|
||||
// group-2-snake
|
||||
{
|
||||
"command": "variable-conversion.toSnakeCase",
|
||||
"title": "下划线(蛇形)命名 (Snake Case) [ foo_bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toSnakeUpperCase",
|
||||
"title": "下划线(蛇形) + 全大写命名 (Snake Upper Case) [ FOO_BAR ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toSnakePascalCase",
|
||||
"title": "下划线(蛇形) + 大驼峰(帕斯卡)命名 (Snake Pascal Case) [ Foo_Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toSnakeCamelCase",
|
||||
"title": "下划线(蛇形) + 小驼峰(驼峰)命名 (Snake Camel Case) [ foo_Bar ]"
|
||||
},
|
||||
// group-3-kebab
|
||||
{
|
||||
"command": "variable-conversion.toKebabCase",
|
||||
"title": "中划线(连字符/脊柱式)命名 (Kebab/Spinal Case) [ foo-bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toKebabUpperCase",
|
||||
"title": "中划线(连字符/脊柱式) + 全大写命名 (Kebab Upper Case) [ FOO-BAR ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toKebabPascalCase",
|
||||
"title": "中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名 (Kebab Pascal Case) [ Foo-Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toKebabCamelCase",
|
||||
"title": "中划线(连字符/脊柱式) + 小驼峰(驼峰)命名 (Kebab Camel Case) [ foo-Bar ]"
|
||||
},
|
||||
// group-4-space
|
||||
{
|
||||
"command": "variable-conversion.toSpaceCase",
|
||||
"title": "空格分隔命名 (Space Case) [ foo bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toSpaceUpperCase",
|
||||
"title": "空格分隔 + 全大写命名 (Space Upper Case) [ FOO BAR ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toSpacePascalCase",
|
||||
"title": "空格分隔 + 大驼峰(帕斯卡)命名 (Space Pascal Case) [ Foo Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toSpaceCamelCase",
|
||||
"title": "空格分隔 + 小驼峰(驼峰)命名 (Space Camel Case) [ foo Bar ]"
|
||||
},
|
||||
// group-5-dot
|
||||
{
|
||||
"command": "variable-conversion.toDotCase",
|
||||
"title": "点分隔命名 (Dot Case) [ foo bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotUpperCase",
|
||||
"title": "点分隔 + 全大写命名 (Dot Upper Case) [ FOO BAR ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotPascalCase",
|
||||
"title": "点分隔 + 大驼峰(帕斯卡)命名 (Dot Pascal Case) [ Foo Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotCamelCase",
|
||||
"title": "点分隔 + 小驼峰(驼峰)命名 (Dot Camel Case) [ foo Bar ]"
|
||||
},
|
||||
// group-6-upper-lower
|
||||
{
|
||||
"command": "variable-conversion.toLowerCase",
|
||||
"title": "全小写 (Lower Case) [ foobar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toUpperCase",
|
||||
"title": "全大写 (Upper Case) [ FOOBAR ]"
|
||||
},
|
||||
// 隐藏命令
|
||||
// {
|
||||
// "command": "editor.action.transformToCamelcase",
|
||||
// "title": "[VSCode 自带] 驼峰式大小写 (Camel Case) [ fooBar ]",
|
||||
// "enablement": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToKebabcase",
|
||||
// "title": "[VSCode 自带] Kebab 命名 (Kebab Case) [ foo-bar ]",
|
||||
// "enablement": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToTitlecase",
|
||||
// "title": "[VSCode 自带] 词首字母大写 (Title Case) [ Foo Bar ]",
|
||||
// "enablement": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToLowercase",
|
||||
// "title": "[VSCode 自带] 转换为小写 (Lower Case) [ foo bar ]",
|
||||
// "enablement": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToUppercase",
|
||||
// "title": "[VSCode 自带] 转换为大写 (Upper Case) [ FOO BAR ]",
|
||||
// "enablement": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToSnakecase",
|
||||
// "title": "[VSCode 自带] 转换为蛇形命名法 (Snake Case) [ foo_bar ]",
|
||||
// "enablement": "false"
|
||||
// },
|
||||
/**
|
||||
* 右键菜单
|
||||
*/
|
||||
{
|
||||
"command": "variable-conversion.convertPath",
|
||||
"title": "路径转换"
|
||||
},
|
||||
/**
|
||||
* 右键菜单 - 子菜单
|
||||
*/
|
||||
// group-1-common-style
|
||||
{
|
||||
"command": "variable-conversion.pathFormat.toWindowsStyle",
|
||||
"title": "Windows 风格 [ C:\\Windows\\System32 ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.pathFormat.toUnixStyle",
|
||||
"title": "Unix 风格 [ /usr/bin ]"
|
||||
}
|
||||
],
|
||||
// docs: https://code.visualstudio.com/api/references/contribution-points#contributes.menus
|
||||
"menus": {
|
||||
// 编辑器右键菜单
|
||||
"editor/context": [
|
||||
// 变量转换
|
||||
{
|
||||
// "when": "editorTextFocus",
|
||||
// 2024.12.07 当未选中文字时,隐藏 [变量转换] 右键菜单
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"command": "variable-conversion.convertCase",
|
||||
// "group": "1_modification@9"
|
||||
"group": "navigation@10"
|
||||
},
|
||||
// 将变量转换为...
|
||||
{
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"submenu": "variable-conversion.stringConversionMenu",
|
||||
// docs: https://code.visualstudio.com/api/references/contribution-points#Sorting-of-groups
|
||||
// "group": "1_modification@9"
|
||||
"group": "navigation@11"
|
||||
},
|
||||
// 路径转换
|
||||
{
|
||||
// "when": "editorTextFocus",
|
||||
// 2024.12.07 当未选中文字时,隐藏 [变量转换] 右键菜单
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"command": "variable-conversion.convertPath",
|
||||
"group": "navigation@12"
|
||||
},
|
||||
// 将路径转换为...
|
||||
{
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"submenu": "variable-conversion.pathConversionMenu",
|
||||
"group": "navigation@13"
|
||||
}
|
||||
],
|
||||
"variable-conversion.stringConversionMenu": [
|
||||
// group-1-camel
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_camel_case",
|
||||
"command": "variable-conversion.toCamelCase",
|
||||
"group": "group-1-camel@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_pascal_case",
|
||||
"command": "variable-conversion.toPascalCase",
|
||||
"group": "group-1-camel@2"
|
||||
},
|
||||
// group-2-snake
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_case",
|
||||
"command": "variable-conversion.toSnakeCase",
|
||||
"group": "group-2-snake@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_upper_case",
|
||||
"command": "variable-conversion.toSnakeUpperCase",
|
||||
"group": "group-2-snake@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_pascal_case",
|
||||
"command": "variable-conversion.toSnakePascalCase",
|
||||
"group": "group-2-snake@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_camel_case",
|
||||
"command": "variable-conversion.toSnakeCamelCase",
|
||||
"group": "group-2-snake@4"
|
||||
},
|
||||
// group-3-kebab
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_case",
|
||||
"command": "variable-conversion.toKebabCase",
|
||||
"group": "group-3-kebab@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_upper_case",
|
||||
"command": "variable-conversion.toKebabUpperCase",
|
||||
"group": "group-3-kebab@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_pascal_case",
|
||||
"command": "variable-conversion.toKebabPascalCase",
|
||||
"group": "group-3-kebab@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_camel_case",
|
||||
"command": "variable-conversion.toKebabCamelCase",
|
||||
"group": "group-3-kebab@4"
|
||||
},
|
||||
// group-4-space
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_case",
|
||||
"command": "variable-conversion.toSpaceCase",
|
||||
"group": "group-4-space@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_upper_case",
|
||||
"command": "variable-conversion.toSpaceUpperCase",
|
||||
"group": "group-4-space@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_pascal_case",
|
||||
"command": "variable-conversion.toSpacePascalCase",
|
||||
"group": "group-4-space@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_camel_case",
|
||||
"command": "variable-conversion.toSpaceCamelCase",
|
||||
"group": "group-4-space@4"
|
||||
},
|
||||
// group-5-dot
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_case",
|
||||
"command": "variable-conversion.toDotCase",
|
||||
"group": "group-5-dot@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_upper_case",
|
||||
"command": "variable-conversion.toDotUpperCase",
|
||||
"group": "group-5-dot@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_pascal_case",
|
||||
"command": "variable-conversion.toDotPascalCase",
|
||||
"group": "group-5-dot@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_camel_case",
|
||||
"command": "variable-conversion.toDotCamelCase",
|
||||
"group": "group-5-dot@4"
|
||||
},
|
||||
// group-6-upper-lower
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_lower_case",
|
||||
"command": "variable-conversion.toLowerCase",
|
||||
"group": "group-6-upper-lower@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_upper_case",
|
||||
"command": "variable-conversion.toUpperCase",
|
||||
"group": "group-6-upper-lower@2"
|
||||
}
|
||||
// 隐藏菜单项
|
||||
// {
|
||||
// "command": "editor.action.transformToCamelcase",
|
||||
// "group": "group-vscode",
|
||||
// "when": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToKebabcase",
|
||||
// "group": "group-vscode",
|
||||
// "when": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToTitlecase",
|
||||
// "group": "group-vscode",
|
||||
// "when": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToLowercase",
|
||||
// "group": "group-vscode",
|
||||
// "when": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToUppercase",
|
||||
// "group": "group-vscode",
|
||||
// "when": "false"
|
||||
// },
|
||||
// {
|
||||
// "command": "editor.action.transformToSnakecase",
|
||||
// "group": "group-vscode",
|
||||
// "when": "false"
|
||||
// }
|
||||
],
|
||||
"variable-conversion.pathConversionMenu": [
|
||||
// group-1-common-style
|
||||
{
|
||||
// Windows 风格
|
||||
"when": "!_isHideSubMenuItem_windows_style",
|
||||
"command": "variable-conversion.pathFormat.toWindowsStyle",
|
||||
"group": "group-1-common-style@1"
|
||||
},
|
||||
{
|
||||
// Unix 风格
|
||||
"when": "!_isHideSubMenuItem_unix_style",
|
||||
"command": "variable-conversion.pathFormat.toUnixStyle",
|
||||
"group": "group-1-common-style@2"
|
||||
}
|
||||
]
|
||||
},
|
||||
// docs: https://code.visualstudio.com/api/references/contribution-points#contributes.submenus
|
||||
"submenus": [
|
||||
{
|
||||
"id": "variable-conversion.stringConversionMenu",
|
||||
"label": "将变量转换为..."
|
||||
},
|
||||
{
|
||||
"id": "variable-conversion.pathConversionMenu",
|
||||
"label": "将路径转换为..."
|
||||
}
|
||||
],
|
||||
// intro: https://code.visualstudio.com/api/ux-guidelines/settings
|
||||
// docs: https://code.visualstudio.com/api/references/contribution-points#contributes.configuration
|
||||
"configuration": {
|
||||
"title": "Variable Conversion 变量转换",
|
||||
"properties": {
|
||||
// 仅测试用
|
||||
// "variable-conversion.test1": {
|
||||
// "title": "定义转换格式的排序",
|
||||
// "description": "Defines the ordering of the conversion format.\n定义转换格式的排序",
|
||||
// "type": "array",
|
||||
// "default": [
|
||||
// "camelCase",
|
||||
// "snake_case",
|
||||
// "PascalCase"
|
||||
// ]
|
||||
// },
|
||||
// "variable-conversion.enableFormat": {
|
||||
// "type": "object",
|
||||
// "default": {
|
||||
// "camelCase": true,
|
||||
// "snake_case": true,
|
||||
// "PascalCase": true
|
||||
// },
|
||||
// "description": "Define which formats are enabled.\n定义哪些格式是开启的"
|
||||
// },
|
||||
// "variable-conversion.disableFormat2": {
|
||||
// "type": "object",
|
||||
// "default": {
|
||||
// "camelCase": true,
|
||||
// "snake_case": true,
|
||||
// "PascalCase": true
|
||||
// },
|
||||
// "description": "Define which formats are enabled.\n定义哪些格式是开启的"
|
||||
// },
|
||||
//
|
||||
// 配置项灵感来自: go.addTags 配置项
|
||||
// link: https://github.com/golang/vscode-go/blob/8dccbfd59467c7ef09cb9e34309dd466018c5e98/extension/package.json#L1588-L1634
|
||||
// "go.addTags": {
|
||||
// "type": "object",
|
||||
// "properties": {
|
||||
// "promptForTags": {
|
||||
// "type": "boolean",
|
||||
// "default": false,
|
||||
// "description": "If true, Go: Add Tags command will prompt the user to provide tags, options, transform values instead of using the configured values"
|
||||
// },
|
||||
// "tags": {
|
||||
// "type": "string",
|
||||
// "default": "json",
|
||||
// "description": "Comma separated tags to be used by Go: Add Tags command"
|
||||
// },
|
||||
// "options": {
|
||||
// "type": "string",
|
||||
// "default": "json=omitempty",
|
||||
// "description": "Comma separated tag=options pairs to be used by Go: Add Tags command"
|
||||
// },
|
||||
// "transform": {
|
||||
// "type": "string",
|
||||
// "enum": [
|
||||
// "snakecase",
|
||||
// "camelcase",
|
||||
// "lispcase",
|
||||
// "pascalcase",
|
||||
// "keep"
|
||||
// ],
|
||||
// "default": "snakecase",
|
||||
// "description": "Transformation rule used by Go: Add Tags command to add tags"
|
||||
// },
|
||||
// "template": {
|
||||
// "type": "string",
|
||||
// "default": "",
|
||||
// "description": "Custom format used by Go: Add Tags command for the tag value to be applied"
|
||||
// }
|
||||
// },
|
||||
// "additionalProperties": false,
|
||||
// "default": {
|
||||
// "tags": "json",
|
||||
// "options": "json=omitempty",
|
||||
// "promptForTags": false,
|
||||
// "transform": "snakecase",
|
||||
// "template": ""
|
||||
// },
|
||||
// "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.",
|
||||
// "scope": "resource"
|
||||
// },
|
||||
//
|
||||
// 全小写命名
|
||||
// lower_case(全小写), snake_case(下划线), kebab_case(连字符), space_case(空格), dot_case(点)
|
||||
// 全大写命名
|
||||
// upper_case(全大写), snake_upper_case(下划线), kebab_upper_case(连字符), space_upper_case(空格), dot_upper_case(点)
|
||||
// 大驼峰命名
|
||||
// pascal_case(大驼峰), snake_pascal_case(下划线), kebab_pascal_case(连字符), space_pascal_case(空格), dot_pascal_case(点)
|
||||
// 小驼峰命名
|
||||
// camel_case(小驼峰), snake_camel_case(下划线), kebab_camel_case(连字符), space_camel_case(空格), dot_camel_case(点)
|
||||
//
|
||||
"variable-conversion.enabledFormats": {
|
||||
"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.",
|
||||
"markdownDescription": "配置启用的变量命名方式\n\nConfiguration of Enabled Variable Naming Conventions.\n\n \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)",
|
||||
"scope": "window",
|
||||
"properties": {
|
||||
"lowerCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] lower case (全小写)\n 🌰e.g. mike like eat ice-cream"
|
||||
// "markdownDescription": "是否启用 [全小写] 目标转换格式\n\nEnable [lowercase] target conversion format\n\n\n\ne.g. Mike like eat ice-cream."
|
||||
},
|
||||
"snakeCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] snake case (下划线)\n 🌰e.g. mike_like_eat_ice_cream"
|
||||
},
|
||||
"kebabCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] kebab case (连字符)\n 🌰e.g. mike-like-eat-ice-cream"
|
||||
},
|
||||
"spaceCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] space case (空格)\n 🌰e.g. mike like eat ice cream"
|
||||
},
|
||||
"dotCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] dot case (点)\n 🌰e.g. mike.like.eat.ice.cream"
|
||||
},
|
||||
"upperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] upper case (全大写)\n 🌰e.g. MIKE LIKE EAT ICE-CREAM"
|
||||
},
|
||||
"snakeUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] snake upper case (下划线)\n 🌰e.g. MIKE_LIKE_EAT_ICE_CREAM"
|
||||
},
|
||||
"kebabUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] kebab upper case (连字符)\n 🌰e.g. MIKE-LIKE-EAT-ICE-CREAM"
|
||||
},
|
||||
"spaceUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] space upper case (空格)\n 🌰e.g. MIKE LIKE EAT ICE CREAM"
|
||||
},
|
||||
"dotUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] dot upper case (点)\n 🌰e.g. MIKE.LIKE.EAT.ICE.CREAM"
|
||||
},
|
||||
"pascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] pascal case (大驼峰)\n 🌰e.g. MikeLikeEatIceCream"
|
||||
},
|
||||
"snakePascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] snake pascal case (下划线)\n 🌰e.g. Mike_Like_Eat_Ice_Cream"
|
||||
},
|
||||
"kebabPascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] kebab pascal case (连字符)\n 🌰e.g. Mike-Like-Eat-Ice-Cream"
|
||||
},
|
||||
"spacePascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] space pascal case (空格)\n 🌰e.g. Mike Like Eat Ice Cream"
|
||||
},
|
||||
"dotPascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] dot pascal case (点)\n 🌰e.g. Mike.Like.Eat.Ice.Cream"
|
||||
},
|
||||
"camelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] camel case (小驼峰)\n 🌰e.g. mikeLikeEatIceCream"
|
||||
},
|
||||
"snakeCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] snake camel case (下划线)\n 🌰e.g. mike_Like_Eat_Ice_Cream"
|
||||
},
|
||||
"kebabCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] kebab camel case (连字符)\n 🌰e.g. mike-Like-Eat-Ice-Cream"
|
||||
},
|
||||
"spaceCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] space camel case (空格)\n 🌰e.g. mike Like Eat Ice Cream"
|
||||
},
|
||||
"dotCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] dot camel case (点)\n 🌰e.g. mike.Like.Eat.Ice.Cream"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"default": {
|
||||
// 全小写命名
|
||||
// lower_case(全小写), snake_case(下划线), kebab_case(连字符), space_case(空格), dot_case(点)
|
||||
"lowerCase.enabled": true,
|
||||
"snakeCase.enabled": true,
|
||||
"kebabCase.enabled": true,
|
||||
"spaceCase.enabled": true,
|
||||
"dotCase.enabled": false,
|
||||
// 全大写命名
|
||||
// upper_case(全大写), snake_upper_case(下划线), kebab_upper_case(连字符), space_upper_case(空格), dot_upper_case(点)
|
||||
"upperCase.enabled": true,
|
||||
"snakeUpperCase.enabled": true,
|
||||
"kebabUpperCase.enabled": false,
|
||||
"spaceUpperCase.enabled": true,
|
||||
"dotUpperCase.enabled": false,
|
||||
// 大驼峰命名
|
||||
// pascal_case(大驼峰), snake_pascal_case(下划线), kebab_pascal_case(连字符), space_pascal_case(空格), dot_pascal_case(点)
|
||||
"pascalCase.enabled": true,
|
||||
"snakePascalCase.enabled": false,
|
||||
"kebabPascalCase.enabled": false,
|
||||
"spacePascalCase.enabled": false,
|
||||
"dotPascalCase.enabled": false,
|
||||
// 小驼峰命名
|
||||
// camel_case(小驼峰), snake_camel_case(下划线), kebab_camel_case(连字符), space_camel_case(空格), dot_camel_case(点)
|
||||
"camelCase.enabled": true,
|
||||
"snakeCamelCase.enabled": false,
|
||||
"kebabCamelCase.enabled": false,
|
||||
"spaceCamelCase.enabled": false,
|
||||
"dotCamelCase.enabled": false
|
||||
}
|
||||
},
|
||||
// "variable-conversion.formatOrder": {},
|
||||
"variable-conversion.disableFormat": {
|
||||
"order": 1,
|
||||
// markdownDescription 最多配置 11 行
|
||||
"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)",
|
||||
"markdownDeprecationMessage": "**Deprecated**: Please use `#variable-conversion.enabledFormats#` instead.\n\n**已弃用**,请使用 `#variable-conversion.enabledFormats#`。",
|
||||
"type": "array",
|
||||
"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": [
|
||||
"小驼峰(驼峰)命名",
|
||||
"大驼峰(帕斯卡)命名",
|
||||
"下划线(蛇形)命名",
|
||||
"下划线(蛇形) + 小驼峰(驼峰)命名",
|
||||
"下划线(蛇形) + 大驼峰(帕斯卡)命名",
|
||||
"下划线(蛇形) + 全大写命名",
|
||||
"中划线(连字符/脊柱式)命名",
|
||||
"中划线(连字符/脊柱式) + 小驼峰(驼峰)命名",
|
||||
"中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名",
|
||||
"中划线(连字符/脊柱式) + 全大写命名",
|
||||
"空格分隔命名",
|
||||
"空格分隔 + 小驼峰(驼峰)命名",
|
||||
"空格分隔 + 大驼峰(帕斯卡)命名",
|
||||
"空格分隔 + 全大写命名",
|
||||
"点分隔命名",
|
||||
"点分隔 + 小驼峰(驼峰)命名",
|
||||
"点分隔 + 大驼峰(帕斯卡)命名",
|
||||
"点分隔 + 全大写命名",
|
||||
"全小写",
|
||||
"全大写"
|
||||
]
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"variable-conversion.circularConversionFormatOrder": {
|
||||
"order": 2,
|
||||
"title": "定义循环转换快捷键的目标格式排序",
|
||||
// "description": "Defines the destination format ordering of the circular conversion shortcut.\n定义循环转换快捷键的目标格式排序",
|
||||
// markdownDescription 最多配置 11 行
|
||||
// "markdownDescription": "Defines the destination format ordering of the circular conversion shortcut, separated by commas.\n\n 定义循环转换快捷键的目标格式排序,以英文逗号分隔\n\n Target formats that are not in the following configuration list will appear last in the following custom order in the default order.\n\n不在以下配置列表中的目标格式,将按照默认顺序排在以下自定义顺序最后\n\n 🌟Lower Case 全小写命名: `lower_case`(全小写), `snake_case`(下划线), `kebab_case`(连字符), `space_case`(空格), `dot_case`(点)\n\n 🌟Upper Case 全大写命名: `upper_case`(全大写), `snake_upper_case`(下划线), `kebab_upper_case`(连字符), `space_upper_case`(空格), `dot_upper_case`(点)\n\n 🌟Pascal Case 大驼峰命名: `pascal_case`(大驼峰), `snake_pascal_case`(下划线), `kebab_pascal_case`(连字符), `space_pascal_case`(空格), `dot_pascal_case`(点)\n\n 🌟Camel Case 小驼峰命名: `camel_case`(小驼峰), `snake_camel_case`(下划线), `kebab_camel_case`(连字符), `space_camel_case`(空格), `dot_camel_case`(点)\n\n🐳Default value 默认值: `camel_case, snake_case, pascal_case, kebab_case, space_case, dot_case, snake_upper_case, kebab_upper_case, space_upper_case, dot_upper_case, snake_pascal_case, kebab_pascal_case, space_pascal_case, dot_pascal_case, snake_camel_case, kebab_camel_case, space_camel_case, dot_camel_case, lower_case, upper_case`\n\n If you find the following configuration troublesome, you can also edit this configuration item in `settings.json`. 若您感觉以下配置比较麻烦,也可以选择在 `settings.json` 中编辑: `\"variable-conversion.circularConversionFormatOrder\": \"...\",` [Edit in settings.json (在 settings.json 中编辑)](command:workbench.action.openSettingsJson)",
|
||||
"markdownDescription": "定义循环转换快捷键的目标格式排序,以英文逗号分隔。不在以下配置列表中的目标格式,将按照默认顺序排在以下自定义顺序最后\n\n Defines the destination format ordering of the circular conversion shortcut, separated by commas. (Target formats that are not in the following configuration list will appear last in the following custom order in the default order.)\n\n 📌请[在 `settings.json` 中编辑该配置](command:workbench.action.openSettingsJson),**不要使用**设置页面的下拉框进行配置: `\"variable-conversion.circularConversionFormatOrder\": [ ... ],`\n\n 📌Please [edit this configuration in `settings.json`](command:workbench.action.openSettingsJson), **instead of** using the drop-down box on the settings page.\n\n 🐳默认值 Default value: `\"variable-conversion.circularConversionFormatOrder\": [ \"camel_case\", \"snake_case\", \"pascal_case\", \"kebab_case\", \"space_case\", \"dot_case\", \"snake_upper_case\", \"kebab_upper_case\", \"space_upper_case\", \"dot_upper_case\", \"snake_pascal_case\", \"kebab_pascal_case\", \"space_pascal_case\", \"dot_pascal_case\", \"snake_camel_case\", \"kebab_camel_case\", \"space_camel_case\", \"dot_camel_case\", \"lower_case\", \"upper_case\" ],`\n\n 👉Configuration item meaning 配置项说明\n\n 🌟Lower Case 全小写命名: `lower_case`(全小写), `snake_case`(下划线), `kebab_case`(连字符), `space_case`(空格), `dot_case`(点)\n\n 🌟Upper Case 全大写命名: `upper_case`(全大写), `snake_upper_case`(下划线), `kebab_upper_case`(连字符), `space_upper_case`(空格), `dot_upper_case`(点)\n\n 🌟Pascal Case 大驼峰命名: `pascal_case`(大驼峰), `snake_pascal_case`(下划线), `kebab_pascal_case`(连字符), `space_pascal_case`(空格), `dot_pascal_case`(点)\n\n 🌟Camel Case 小驼峰命名: `camel_case`(小驼峰), `snake_camel_case`(下划线), `kebab_camel_case`(连字符), `space_camel_case`(空格), `dot_camel_case`(点)",
|
||||
// "type": "string",
|
||||
// "default": "camel_case, snake_case, pascal_case, kebab_case, space_case, dot_case, snake_upper_case, kebab_upper_case, space_upper_case, dot_upper_case, snake_pascal_case, kebab_pascal_case, space_pascal_case, dot_pascal_case, snake_camel_case, kebab_camel_case, space_camel_case, dot_camel_case, lower_case, upper_case"
|
||||
"type": "array",
|
||||
"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": [
|
||||
"小驼峰(驼峰)命名",
|
||||
"大驼峰(帕斯卡)命名",
|
||||
"下划线(蛇形)命名",
|
||||
"下划线(蛇形) + 小驼峰(驼峰)命名",
|
||||
"下划线(蛇形) + 大驼峰(帕斯卡)命名",
|
||||
"下划线(蛇形) + 全大写命名",
|
||||
"中划线(连字符/脊柱式)命名",
|
||||
"中划线(连字符/脊柱式) + 小驼峰(驼峰)命名",
|
||||
"中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名",
|
||||
"中划线(连字符/脊柱式) + 全大写命名",
|
||||
"空格分隔命名",
|
||||
"空格分隔 + 小驼峰(驼峰)命名",
|
||||
"空格分隔 + 大驼峰(帕斯卡)命名",
|
||||
"空格分隔 + 全大写命名",
|
||||
"点分隔命名",
|
||||
"点分隔 + 小驼峰(驼峰)命名",
|
||||
"点分隔 + 大驼峰(帕斯卡)命名",
|
||||
"点分隔 + 全大写命名",
|
||||
"全小写",
|
||||
"全大写"
|
||||
]
|
||||
},
|
||||
"default": [
|
||||
"camel_case",
|
||||
"snake_case",
|
||||
"pascal_case",
|
||||
"kebab_case",
|
||||
"space_case",
|
||||
"dot_case",
|
||||
"snake_upper_case",
|
||||
"kebab_upper_case",
|
||||
"space_upper_case",
|
||||
"dot_upper_case",
|
||||
"snake_pascal_case",
|
||||
"kebab_pascal_case",
|
||||
"space_pascal_case",
|
||||
"dot_pascal_case",
|
||||
"snake_camel_case",
|
||||
"kebab_camel_case",
|
||||
"space_camel_case",
|
||||
"dot_camel_case",
|
||||
"lower_case",
|
||||
"upper_case"
|
||||
]
|
||||
},
|
||||
// TODO
|
||||
"variable-conversion.disablePathFormat": {
|
||||
"order": 3,
|
||||
// markdownDescription 最多配置 11 行
|
||||
"markdownDescription": "定义哪些路径风格是禁用的\n\nDefine which path 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.disablePathFormat\": [ ... ],`\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)",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"windows_style",
|
||||
"unix_style"
|
||||
],
|
||||
"enumDescriptions": [
|
||||
"Windows 风格",
|
||||
"Unix 风格"
|
||||
]
|
||||
},
|
||||
"default": []
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"lint": "eslint src",
|
||||
"test": "vscode-test",
|
||||
"package": "vsce package",
|
||||
"publish": "vsce publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "20.x",
|
||||
"@types/vscode": "^1.102.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
"@vscode/test-electron": "^2.5.2",
|
||||
"eslint": "^9.25.1",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
2212
package-lock.json
generated
360
package.json
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"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": "2.1.0",
|
||||
"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, lower, upper case, and more.",
|
||||
"version": "1.0.8",
|
||||
"icon": "image/logo.png",
|
||||
"publisher": "coder-xiaomo",
|
||||
"engines": {
|
||||
"vscode": "^1.102.0"
|
||||
"vscode": "^1.87.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
@@ -52,27 +52,6 @@
|
||||
"arrowKey": "]"
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.convertPath",
|
||||
"key": "shift+alt+/",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.cyclicConvertPath.previous",
|
||||
"key": "ctrl+alt+shift+/",
|
||||
"args": {
|
||||
"direction": "<-"
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.cyclicConvertPath.next",
|
||||
"key": "ctrl+alt+/",
|
||||
"args": {
|
||||
"direction": "->"
|
||||
},
|
||||
"when": "editorTextFocus"
|
||||
}
|
||||
],
|
||||
"commands": [
|
||||
@@ -136,22 +115,6 @@
|
||||
"command": "variable-conversion.toSpaceCamelCase",
|
||||
"title": "空格分隔 + 小驼峰(驼峰)命名 (Space Camel Case) [ foo Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotCase",
|
||||
"title": "点分隔命名 (Dot Case) [ foo bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotUpperCase",
|
||||
"title": "点分隔 + 全大写命名 (Dot Upper Case) [ FOO BAR ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotPascalCase",
|
||||
"title": "点分隔 + 大驼峰(帕斯卡)命名 (Dot Pascal Case) [ Foo Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toDotCamelCase",
|
||||
"title": "点分隔 + 小驼峰(驼峰)命名 (Dot Camel Case) [ foo Bar ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.toLowerCase",
|
||||
"title": "全小写 (Lower Case) [ foobar ]"
|
||||
@@ -159,155 +122,85 @@
|
||||
{
|
||||
"command": "variable-conversion.toUpperCase",
|
||||
"title": "全大写 (Upper Case) [ FOOBAR ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.convertPath",
|
||||
"title": "路径转换"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.pathFormat.toWindowsStyle",
|
||||
"title": "Windows 风格 [ C:\\Windows\\System32 ]"
|
||||
},
|
||||
{
|
||||
"command": "variable-conversion.pathFormat.toUnixStyle",
|
||||
"title": "Unix 风格 [ /usr/bin ]"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"editor/context": [
|
||||
{
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"when": "editorTextFocus",
|
||||
"command": "variable-conversion.convertCase",
|
||||
"group": "navigation@10"
|
||||
"group": "navigation@9"
|
||||
},
|
||||
{
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"submenu": "variable-conversion.stringConversionMenu",
|
||||
"group": "navigation@11"
|
||||
},
|
||||
{
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"command": "variable-conversion.convertPath",
|
||||
"group": "navigation@12"
|
||||
},
|
||||
{
|
||||
"when": "editorTextFocus && _textSelectionLength >= 1",
|
||||
"submenu": "variable-conversion.pathConversionMenu",
|
||||
"group": "navigation@13"
|
||||
"group": "navigation@9"
|
||||
}
|
||||
],
|
||||
"variable-conversion.stringConversionMenu": [
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_camel_case",
|
||||
"command": "variable-conversion.toCamelCase",
|
||||
"group": "group-1-camel@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_pascal_case",
|
||||
"command": "variable-conversion.toPascalCase",
|
||||
"group": "group-1-camel@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_case",
|
||||
"command": "variable-conversion.toSnakeCase",
|
||||
"group": "group-2-snake@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_upper_case",
|
||||
"command": "variable-conversion.toSnakeUpperCase",
|
||||
"group": "group-2-snake@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_pascal_case",
|
||||
"command": "variable-conversion.toSnakePascalCase",
|
||||
"group": "group-2-snake@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_snake_camel_case",
|
||||
"command": "variable-conversion.toSnakeCamelCase",
|
||||
"group": "group-2-snake@4"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_case",
|
||||
"command": "variable-conversion.toKebabCase",
|
||||
"group": "group-3-kebab@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_upper_case",
|
||||
"command": "variable-conversion.toKebabUpperCase",
|
||||
"group": "group-3-kebab@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_pascal_case",
|
||||
"command": "variable-conversion.toKebabPascalCase",
|
||||
"group": "group-3-kebab@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_kebab_camel_case",
|
||||
"command": "variable-conversion.toKebabCamelCase",
|
||||
"group": "group-3-kebab@4"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_case",
|
||||
"command": "variable-conversion.toSpaceCase",
|
||||
"group": "group-4-space@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_upper_case",
|
||||
"command": "variable-conversion.toSpaceUpperCase",
|
||||
"group": "group-4-space@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_pascal_case",
|
||||
"command": "variable-conversion.toSpacePascalCase",
|
||||
"group": "group-4-space@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_space_camel_case",
|
||||
"command": "variable-conversion.toSpaceCamelCase",
|
||||
"group": "group-4-space@4"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_case",
|
||||
"command": "variable-conversion.toDotCase",
|
||||
"group": "group-5-dot@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_upper_case",
|
||||
"command": "variable-conversion.toDotUpperCase",
|
||||
"group": "group-5-dot@2"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_pascal_case",
|
||||
"command": "variable-conversion.toDotPascalCase",
|
||||
"group": "group-5-dot@3"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_dot_camel_case",
|
||||
"command": "variable-conversion.toDotCamelCase",
|
||||
"group": "group-5-dot@4"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_lower_case",
|
||||
"command": "variable-conversion.toLowerCase",
|
||||
"group": "group-6-upper-lower@1"
|
||||
"group": "group-5-upper-lower@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_upper_case",
|
||||
"command": "variable-conversion.toUpperCase",
|
||||
"group": "group-6-upper-lower@2"
|
||||
}
|
||||
],
|
||||
"variable-conversion.pathConversionMenu": [
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_windows_style",
|
||||
"command": "variable-conversion.pathFormat.toWindowsStyle",
|
||||
"group": "group-1-common-style@1"
|
||||
},
|
||||
{
|
||||
"when": "!_isHideSubMenuItem_unix_style",
|
||||
"command": "variable-conversion.pathFormat.toUnixStyle",
|
||||
"group": "group-1-common-style@2"
|
||||
"group": "group-5-upper-lower@2"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -315,239 +208,28 @@
|
||||
{
|
||||
"id": "variable-conversion.stringConversionMenu",
|
||||
"label": "将变量转换为..."
|
||||
},
|
||||
{
|
||||
"id": "variable-conversion.pathConversionMenu",
|
||||
"label": "将路径转换为..."
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"title": "Variable Conversion 变量转换",
|
||||
"properties": {
|
||||
"variable-conversion.enabledFormats": {
|
||||
"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.",
|
||||
"markdownDescription": "配置启用的变量命名方式\n\nConfiguration of Enabled Variable Naming Conventions.\n\n \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)",
|
||||
"scope": "window",
|
||||
"properties": {
|
||||
"lowerCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] lower case (全小写)\n 🌰e.g. mike like eat ice-cream"
|
||||
},
|
||||
"snakeCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] snake case (下划线)\n 🌰e.g. mike_like_eat_ice_cream"
|
||||
},
|
||||
"kebabCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] kebab case (连字符)\n 🌰e.g. mike-like-eat-ice-cream"
|
||||
},
|
||||
"spaceCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] space case (空格)\n 🌰e.g. mike like eat ice cream"
|
||||
},
|
||||
"dotCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全小写命名] dot case (点)\n 🌰e.g. mike.like.eat.ice.cream"
|
||||
},
|
||||
"upperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] upper case (全大写)\n 🌰e.g. MIKE LIKE EAT ICE-CREAM"
|
||||
},
|
||||
"snakeUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] snake upper case (下划线)\n 🌰e.g. MIKE_LIKE_EAT_ICE_CREAM"
|
||||
},
|
||||
"kebabUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] kebab upper case (连字符)\n 🌰e.g. MIKE-LIKE-EAT-ICE-CREAM"
|
||||
},
|
||||
"spaceUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] space upper case (空格)\n 🌰e.g. MIKE LIKE EAT ICE CREAM"
|
||||
},
|
||||
"dotUpperCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[全大写命名] dot upper case (点)\n 🌰e.g. MIKE.LIKE.EAT.ICE.CREAM"
|
||||
},
|
||||
"pascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] pascal case (大驼峰)\n 🌰e.g. MikeLikeEatIceCream"
|
||||
},
|
||||
"snakePascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] snake pascal case (下划线)\n 🌰e.g. Mike_Like_Eat_Ice_Cream"
|
||||
},
|
||||
"kebabPascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] kebab pascal case (连字符)\n 🌰e.g. Mike-Like-Eat-Ice-Cream"
|
||||
},
|
||||
"spacePascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] space pascal case (空格)\n 🌰e.g. Mike Like Eat Ice Cream"
|
||||
},
|
||||
"dotPascalCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[大驼峰命名] dot pascal case (点)\n 🌰e.g. Mike.Like.Eat.Ice.Cream"
|
||||
},
|
||||
"camelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] camel case (小驼峰)\n 🌰e.g. mikeLikeEatIceCream"
|
||||
},
|
||||
"snakeCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] snake camel case (下划线)\n 🌰e.g. mike_Like_Eat_Ice_Cream"
|
||||
},
|
||||
"kebabCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] kebab camel case (连字符)\n 🌰e.g. mike-Like-Eat-Ice-Cream"
|
||||
},
|
||||
"spaceCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] space camel case (空格)\n 🌰e.g. mike Like Eat Ice Cream"
|
||||
},
|
||||
"dotCamelCase.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[小驼峰命名] dot camel case (点)\n 🌰e.g. mike.Like.Eat.Ice.Cream"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"default": {
|
||||
"lowerCase.enabled": true,
|
||||
"snakeCase.enabled": true,
|
||||
"kebabCase.enabled": true,
|
||||
"spaceCase.enabled": true,
|
||||
"dotCase.enabled": false,
|
||||
"upperCase.enabled": true,
|
||||
"snakeUpperCase.enabled": true,
|
||||
"kebabUpperCase.enabled": false,
|
||||
"spaceUpperCase.enabled": true,
|
||||
"dotUpperCase.enabled": false,
|
||||
"pascalCase.enabled": true,
|
||||
"snakePascalCase.enabled": false,
|
||||
"kebabPascalCase.enabled": false,
|
||||
"spacePascalCase.enabled": false,
|
||||
"dotPascalCase.enabled": false,
|
||||
"camelCase.enabled": true,
|
||||
"snakeCamelCase.enabled": false,
|
||||
"kebabCamelCase.enabled": false,
|
||||
"spaceCamelCase.enabled": false,
|
||||
"dotCamelCase.enabled": false
|
||||
}
|
||||
},
|
||||
"variable-conversion.disableFormat": {
|
||||
"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)",
|
||||
"markdownDeprecationMessage": "**Deprecated**: Please use `#variable-conversion.enabledFormats#` instead.\n\n**已弃用**,请使用 `#variable-conversion.enabledFormats#`。",
|
||||
"type": "array",
|
||||
"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": [
|
||||
"小驼峰(驼峰)命名",
|
||||
"大驼峰(帕斯卡)命名",
|
||||
"下划线(蛇形)命名",
|
||||
"下划线(蛇形) + 小驼峰(驼峰)命名",
|
||||
"下划线(蛇形) + 大驼峰(帕斯卡)命名",
|
||||
"下划线(蛇形) + 全大写命名",
|
||||
"中划线(连字符/脊柱式)命名",
|
||||
"中划线(连字符/脊柱式) + 小驼峰(驼峰)命名",
|
||||
"中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名",
|
||||
"中划线(连字符/脊柱式) + 全大写命名",
|
||||
"空格分隔命名",
|
||||
"空格分隔 + 小驼峰(驼峰)命名",
|
||||
"空格分隔 + 大驼峰(帕斯卡)命名",
|
||||
"空格分隔 + 全大写命名",
|
||||
"点分隔命名",
|
||||
"点分隔 + 小驼峰(驼峰)命名",
|
||||
"点分隔 + 大驼峰(帕斯卡)命名",
|
||||
"点分隔 + 全大写命名",
|
||||
"全小写",
|
||||
"全大写"
|
||||
]
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"variable-conversion.disablePathFormat": {
|
||||
"order": 3,
|
||||
"markdownDescription": "定义哪些路径风格是禁用的\n\nDefine which path 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.disablePathFormat\": [ ... ],`\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)",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"windows_style",
|
||||
"unix_style"
|
||||
],
|
||||
"enumDescriptions": [
|
||||
"Windows 风格",
|
||||
"Unix 风格"
|
||||
]
|
||||
},
|
||||
"default": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"lint": "eslint src",
|
||||
"lint": "eslint src --ext ts",
|
||||
"test": "vscode-test",
|
||||
"package": "vsce package",
|
||||
"package": "echo \"start `vsce package`\" & vsce package",
|
||||
"publish": "vsce publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "20.x",
|
||||
"@types/vscode": "^1.102.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"@vscode/test-cli": "^0.0.11",
|
||||
"@vscode/test-electron": "^2.5.2",
|
||||
"eslint": "^9.25.1",
|
||||
"typescript": "^5.8.3"
|
||||
"@types/mocha": "^10.0.6",
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.87.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||
"@typescript-eslint/parser": "^7.4.0",
|
||||
"@vscode/test-cli": "^0.0.8",
|
||||
"@vscode/test-electron": "^2.3.9",
|
||||
"eslint": "^8.57.0",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
import { EOL } from "../../types/EOLType";
|
||||
import { SupportPathFormat } from "./types/SupportPathFormatType";
|
||||
import { TransformTextResult } from '../../types/TransformTextResultType';
|
||||
|
||||
/** / */
|
||||
const LEFT_SLASH = '/';
|
||||
/** \ */
|
||||
const RIGHT_SLASH = '\\';
|
||||
/** \\ */
|
||||
const DOUBLE_RIGHT_SLASH = '\\\\';
|
||||
|
||||
export function pathConversion(targetPathType: SupportPathFormat, input: string, eol: EOL, cutText: Array<TransformTextResult> | undefined = undefined): string {
|
||||
let resultPath;
|
||||
|
||||
let isSeperator = false;
|
||||
switch (targetPathType) {
|
||||
case SupportPathFormat.Windows:
|
||||
// 将其中的 / 替换为 \
|
||||
resultPath = Array.from(input).map((char: string) => {
|
||||
if (char !== LEFT_SLASH) {
|
||||
// 当前字符不是 /
|
||||
isSeperator = false;
|
||||
return char;
|
||||
} else {
|
||||
// 当前字符是 /
|
||||
if (!isSeperator) {
|
||||
// 上一字符不是 /
|
||||
isSeperator = true;
|
||||
return RIGHT_SLASH; // 替换成 \
|
||||
}
|
||||
// 上一字符是 /
|
||||
return '';
|
||||
}
|
||||
}).join('');
|
||||
break;
|
||||
case SupportPathFormat.Unix:
|
||||
// 将其中的 \\ 和 \ 替换为 /
|
||||
resultPath = Array.from(input).map((char: string) => {
|
||||
if (char !== RIGHT_SLASH) {
|
||||
// 当前字符不是 \
|
||||
isSeperator = false;
|
||||
return char;
|
||||
} else {
|
||||
// 当前字符是 \
|
||||
if (!isSeperator) {
|
||||
// 上一字符不是 \
|
||||
isSeperator = true;
|
||||
return LEFT_SLASH; // 替换成 /
|
||||
}
|
||||
// 上一字符是 \
|
||||
return '';
|
||||
}
|
||||
}).join('');
|
||||
break;
|
||||
// case SupportPathFormat.WindowsGitBash:
|
||||
// break;
|
||||
default:
|
||||
return input;
|
||||
}
|
||||
|
||||
return resultPath;
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from "../../types/EOLType";
|
||||
import { cyclicConvertPathOrder } from "./types/SupportPathFormatType";
|
||||
import { pathConversion } from "./conversion";
|
||||
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils';
|
||||
import { getUserConfigurations } from '../../utils/user-configuration';
|
||||
|
||||
interface UserSelection {
|
||||
currentEol: EOL
|
||||
currentSelections?: readonly vscode.Selection[]
|
||||
currentSelectionsText: string[]
|
||||
currentIndex: number
|
||||
isConverted: boolean
|
||||
conversionsTarget: Array<string[]>
|
||||
lastConvertedSelectionsText: string[] // 按快捷键后转换的值(如果下次触发 onUserSelectionUpdated 后传入值是这个,那么跳过,避免丢失当前循环转换记录)
|
||||
}
|
||||
|
||||
const userSelection: UserSelection = {
|
||||
currentEol: '\n',
|
||||
// currentSelections: undefined,
|
||||
currentSelectionsText: [],
|
||||
currentIndex: 0,
|
||||
isConverted: false,
|
||||
conversionsTarget: [], // 转换后去重 剩余转换目标
|
||||
lastConvertedSelectionsText: [],
|
||||
};
|
||||
|
||||
export function onUserSelectionUpdated(selections: readonly vscode.Selection[], textList: string[], eol: EOL): void {
|
||||
userSelection.currentSelections = selections;
|
||||
if (textList.length !== 0 && isStringArrayEqual(textList, userSelection.lastConvertedSelectionsText)) {
|
||||
// console.log('skip onUserSelectionUpdated');
|
||||
return;
|
||||
}
|
||||
// console.log('onUserSelectionUpdated', textList, userSelection.lastConvertedSelectionsText);
|
||||
userSelection.currentEol = eol;
|
||||
userSelection.currentSelectionsText = textList;
|
||||
userSelection.currentIndex = 0;
|
||||
userSelection.isConverted = false;
|
||||
userSelection.conversionsTarget = [textList];
|
||||
userSelection.lastConvertedSelectionsText = textList;
|
||||
}
|
||||
|
||||
export function previousOne() {
|
||||
lazyConvert();
|
||||
const length = userSelection.conversionsTarget.length;
|
||||
const oldIndex = userSelection.currentIndex;
|
||||
const newIndex = oldIndex === 0 ? (length - 1) : (oldIndex - 1);
|
||||
userSelection.currentIndex = newIndex;
|
||||
console.log('previousOne oldIndex', oldIndex, 'newIndex', newIndex);
|
||||
replaceTextEditorSelectedText();
|
||||
}
|
||||
|
||||
export function nextOne() {
|
||||
lazyConvert();
|
||||
const length = userSelection.conversionsTarget.length;
|
||||
const oldIndex = userSelection.currentIndex;
|
||||
const newIndex = oldIndex >= length - 1 ? 0 : (oldIndex + 1);
|
||||
userSelection.currentIndex = newIndex;
|
||||
console.log('nextOne oldIndex', oldIndex, 'newIndex', newIndex);
|
||||
replaceTextEditorSelectedText();
|
||||
}
|
||||
|
||||
function lazyConvert() {
|
||||
if (userSelection.isConverted) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取用户配置
|
||||
// TODO
|
||||
// const disablePathFormatList = getUserConfigurations<Array<string>>('disablePathFormat') || [];
|
||||
|
||||
const textList = userSelection.currentSelectionsText;
|
||||
// vscode.window.showInformationMessage('lazyConvert' + textList.join('\n'));
|
||||
const eol = userSelection.currentEol;
|
||||
const conversionsTarget: Array<string[]> = [textList];
|
||||
for (const cyclicConvertCase of cyclicConvertPathOrder) {
|
||||
// 跳过禁用的目标格式
|
||||
// TODO
|
||||
// if (disablePathFormatList.includes(cyclicConvertCase.settingsKey)) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// 每一个类型
|
||||
const conversionsTargetItem: string[] = [];
|
||||
for (const line of textList) {
|
||||
// 选中区块的每一行
|
||||
const conversionResult: string = pathConversion(cyclicConvertCase.type, line, eol);
|
||||
conversionsTargetItem.push(conversionResult);
|
||||
}
|
||||
conversionsTarget.push(conversionsTargetItem);
|
||||
}
|
||||
|
||||
// 按数组去重
|
||||
const noDuplicate = stringListArrayDuplicateRemoval(conversionsTarget);
|
||||
// console.log('noDuplicate', noDuplicate);
|
||||
|
||||
userSelection.conversionsTarget = noDuplicate;
|
||||
userSelection.isConverted = true;
|
||||
}
|
||||
|
||||
function replaceTextEditorSelectedText() {
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (editor) {
|
||||
const selections = userSelection.currentSelections || [];
|
||||
const textList = userSelection.conversionsTarget[userSelection.currentIndex];
|
||||
console.log('selections', selections, 'textList', textList);
|
||||
editor.edit(editBuilder => {
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
const selection = selections[i];
|
||||
const converted = textList[i];
|
||||
editBuilder.replace(selection, converted);
|
||||
}
|
||||
});
|
||||
userSelection.lastConvertedSelectionsText = textList;
|
||||
}
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* 路径转换类型
|
||||
*
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
export enum SupportPathFormat {
|
||||
|
||||
/**
|
||||
* Windows 风格
|
||||
*
|
||||
* @alias: windows / Windows
|
||||
* @since 2024-12-07
|
||||
*/
|
||||
Windows,
|
||||
|
||||
/**
|
||||
* Unix 风格
|
||||
*
|
||||
* @alias: unix / Unix
|
||||
* @since 2024-12-07
|
||||
*/
|
||||
Unix,
|
||||
};
|
||||
|
||||
const keyword = {
|
||||
windows: [
|
||||
'Windows', 'win',
|
||||
],
|
||||
unix: [
|
||||
'Unix',
|
||||
'Linux',
|
||||
'macOS',
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* 接管的变量转换命令
|
||||
*
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
export const commands: Array<{ command: string; targetCase: SupportPathFormat; settingsKey: string }> = [
|
||||
{
|
||||
command: 'variable-conversion.pathFormat.toWindowsStyle',
|
||||
targetCase: SupportPathFormat.Windows,
|
||||
settingsKey: 'windows_style'
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.pathFormat.toUnixStyle',
|
||||
targetCase: SupportPathFormat.Unix,
|
||||
settingsKey: 'unix_style'
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
export interface QuickPickSupportCaseItem {
|
||||
type: SupportPathFormat,
|
||||
name: string,
|
||||
shortName: string,
|
||||
keyword: string[],
|
||||
settingsKey: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有支持的路径风格
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
export const quickPickSupportCases: Array<QuickPickSupportCaseItem> = [
|
||||
{
|
||||
type: SupportPathFormat.Windows,
|
||||
name: 'Microsoft Windows 风格',
|
||||
shortName: 'Windows 风格',
|
||||
keyword: keyword.windows,
|
||||
settingsKey: 'windows_style',
|
||||
},
|
||||
{
|
||||
type: SupportPathFormat.Unix,
|
||||
name: 'Unix / 类 Unix 风格 (Linux, macOS, ...)',
|
||||
shortName: 'Unix 风格',
|
||||
keyword: keyword.unix,
|
||||
settingsKey: 'unix_style',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
export interface CyclicConvertPathOrderItem {
|
||||
type: SupportPathFormat,
|
||||
settingsKey: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过快捷键循环转换的顺序
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
export const cyclicConvertPathOrder: Array<CyclicConvertPathOrderItem> = [
|
||||
{ type: SupportPathFormat.Windows, settingsKey: 'windows' },
|
||||
{ type: SupportPathFormat.Unix, settingsKey: 'unix' },
|
||||
];
|
@@ -1,136 +0,0 @@
|
||||
import { EOL } from '../../types/EOLType';
|
||||
import { SupportVariableCase } from './types/SupportVariableCaseType';
|
||||
import { TransformTextResult } from '../../types/TransformTextResultType';
|
||||
import { transformMutliLineText, transformText } from '../../utils/transform';
|
||||
|
||||
/**
|
||||
* 统一文本转换函数
|
||||
*
|
||||
* @param {SupportVariableCase} targetCase 目标文本情况
|
||||
* @param {string} str 用户选择的文本 user selection
|
||||
* @param {EOL} eol 行结束符
|
||||
* @param {Array<TransformTextResult>?} cutText 行结束符
|
||||
* @returns 转换后的文本
|
||||
* @since 2024-04-04
|
||||
*/
|
||||
export function caseConversion(targetCase: SupportVariableCase, str: string, eol: EOL, cutText: Array<TransformTextResult> | undefined = undefined): string {
|
||||
let spaceCharacter: '-' | '_' | ' ' | '.' | undefined = undefined;
|
||||
switch (targetCase) {
|
||||
default:
|
||||
case SupportVariableCase.CAMEL_CASE: // 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
|
||||
spaceCharacter = undefined;
|
||||
break;
|
||||
case SupportVariableCase.SNAKE_CASE: // 下划线(蛇形)命名
|
||||
case SupportVariableCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
|
||||
spaceCharacter = '_';
|
||||
break;
|
||||
case SupportVariableCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
|
||||
case SupportVariableCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
|
||||
spaceCharacter = '-';
|
||||
break;
|
||||
case SupportVariableCase.SPACE_CASE: // 空格分隔命名
|
||||
case SupportVariableCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
|
||||
spaceCharacter = ' ';
|
||||
break;
|
||||
case SupportVariableCase.DOT_CASE: // 点分隔命名
|
||||
case SupportVariableCase.DOT_CAMEL_CASE: // 点分隔 + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.DOT_PASCAL_CASE: // 点分隔 + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.DOT_UPPER_CASE: // 点分隔 + 全大写命名
|
||||
spaceCharacter = '.';
|
||||
break;
|
||||
case SupportVariableCase.LOWER_CASE: // 全小写
|
||||
return str.toLowerCase();
|
||||
case SupportVariableCase.UPPER_CASE: // 全大写
|
||||
return str.toUpperCase();
|
||||
}
|
||||
|
||||
// Cut text 切割文本
|
||||
const results: Array<TransformTextResult> = cutText === undefined ? transformMutliLineText(str) : cutText;
|
||||
// console.log('results', results);
|
||||
|
||||
const transformedLines: Array<string> = [];
|
||||
for (const result of results) {
|
||||
// Post Process 后置处理
|
||||
const words = result.trimResult.split('|');
|
||||
|
||||
let isFirstWord: boolean = true;// [驼峰写法] 用于判断首词小写
|
||||
let isPreviousWordSpecial = true; // 用于判断上一个词是 单词 or 特殊字符
|
||||
const transformedWords: Array<string> = [];
|
||||
for (let index = 0; index < words.length; index++) {
|
||||
const word = words[index];
|
||||
|
||||
const firstLetter = word.charAt(0);
|
||||
const pascalCaseWord = firstLetter.toUpperCase() + word.slice(1);
|
||||
|
||||
// 当前 word 是否是特殊单词
|
||||
// const isCurrentWordNormal = firstLetter !== firstLetter.toUpperCase(); // 是小写 a-z (不是特殊字符)
|
||||
const isCurrentWordNormal = /^[A-Za-z]+$/.test(word);
|
||||
// /^[A-Za-z]+$/.test("") false
|
||||
// /^[A-Za-z]+$/.test("苹果") true
|
||||
// /^[A-Za-z]+$/.test("apple") true
|
||||
const isCurrentWordSpecial = !isCurrentWordNormal;
|
||||
|
||||
// 添加连字符
|
||||
if (!isPreviousWordSpecial && !isCurrentWordSpecial) {
|
||||
spaceCharacter !== undefined
|
||||
&& transformedWords.push(spaceCharacter);
|
||||
}
|
||||
|
||||
// 根据目标情况转换单词
|
||||
switch (targetCase) {
|
||||
case SupportVariableCase.CAMEL_CASE: // 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
|
||||
case SupportVariableCase.DOT_CAMEL_CASE: // 点分隔 + 小驼峰(驼峰)命名
|
||||
if (isFirstWord) {
|
||||
transformedWords.push(word);
|
||||
if (isCurrentWordNormal) {
|
||||
isFirstWord = false;
|
||||
}
|
||||
} else {
|
||||
transformedWords.push(pascalCaseWord);
|
||||
}
|
||||
break;
|
||||
case SupportVariableCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
|
||||
case SupportVariableCase.DOT_PASCAL_CASE: // 点分隔 + 大驼峰(帕斯卡)命名
|
||||
transformedWords.push(pascalCaseWord);
|
||||
break;
|
||||
case SupportVariableCase.SNAKE_CASE: // 下划线(蛇形)命名
|
||||
case SupportVariableCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
|
||||
case SupportVariableCase.SPACE_CASE: // 空格分隔命名
|
||||
case SupportVariableCase.DOT_CASE: // 点分隔命名
|
||||
transformedWords.push(word);
|
||||
break;
|
||||
case SupportVariableCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
|
||||
case SupportVariableCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
|
||||
case SupportVariableCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
|
||||
case SupportVariableCase.DOT_UPPER_CASE: // 点分隔 + 全大写命名
|
||||
transformedWords.push(word.toUpperCase());
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported case: ${targetCase}`);
|
||||
}
|
||||
|
||||
if (word === '\n' || word === '\r\n') {
|
||||
isFirstWord = true; // 换行后,重新计算首词
|
||||
}
|
||||
|
||||
isPreviousWordSpecial = isCurrentWordSpecial;
|
||||
}
|
||||
|
||||
const transformedLine = result.leadingSpace + transformedWords.join('') + result.trailingSpace;
|
||||
transformedLines.push(transformedLine);
|
||||
}
|
||||
return transformedLines.join(eol);
|
||||
}
|
@@ -1,609 +0,0 @@
|
||||
/**
|
||||
* When support a new variable case, there's something we need to do.
|
||||
*
|
||||
* 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/core/variable-convert/conversion.ts]
|
||||
*
|
||||
* Test:
|
||||
* - 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]
|
||||
*
|
||||
* Docs:
|
||||
* - Modify `description` in [package.json] and [package-comment.jsonc]
|
||||
* - Add changes in [CHANGELOG.md] and [README.md]
|
||||
*/
|
||||
export enum SupportVariableCase {
|
||||
|
||||
/**
|
||||
* 小驼峰(驼峰)命名
|
||||
* Camel Case
|
||||
* e.g. fooBar
|
||||
*
|
||||
* @alias: camelCase / CamelCase / camel case / camel_case / CAMEL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 大驼峰(帕斯卡)命名
|
||||
* Pascal Case
|
||||
* e.g. FooBar
|
||||
*
|
||||
* @alias: pascalCase / PascalCase / pascal case / pascal_case / PASCAL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形)命名
|
||||
* Snake Case
|
||||
* e.g. foo_bar
|
||||
*
|
||||
* @alias: snakeCase / SnakeCase / snake case / snake_case / SNAKE_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形) + 小驼峰(驼峰)命名
|
||||
* Snake Camel Case
|
||||
* e.g. foo_Bar
|
||||
*
|
||||
* @alias: snakeCamelCase / SnakeCamelCase / snake camel case / snake_camel_case / SNAKE_CAMEL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形) + 大驼峰(帕斯卡)命名
|
||||
* Snake Pascal Case
|
||||
* e.g. Foo_Bar
|
||||
*
|
||||
* @alias: snakePascalCase / SnakePascalCase / snake pascal case / snake_pascal_case / SNAKE_PASCAL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形) + 全大写命名
|
||||
* Snake Upper Case
|
||||
* e.g. FOO_BAR
|
||||
*
|
||||
* @alias: snakeUpperCase / SnakeUpperCase / snake upper case / snake_upper_case / SNAKE_UPPER_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式)命名
|
||||
* Kebab Case / Spinal Case
|
||||
* e.g. foo-bar
|
||||
*
|
||||
* @alias: kebabCase / KebabCase / kebab case / kebab_case / KEBAB_CASE
|
||||
* spinalCase / SpinalCase / spinal case / spinal_case / SPINAL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
KEBAB_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
|
||||
* Kebab Camel Case
|
||||
* e.g. foo-Bar
|
||||
*
|
||||
* @alias: kebabCamelCase / KebabCamelCase / kebab camel case / kebab_camel_case / KEBAB_CAMEL_CASE
|
||||
* @since 2024-04-03
|
||||
*/
|
||||
KEBAB_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
|
||||
* Kebab Pascal Case
|
||||
* e.g. Foo-Bar
|
||||
*
|
||||
* @alias: kebabPascalCase / KebabPascalCase / kebab pascal case / kebab_pascal_case / KEBAB_PASCAL_CASE
|
||||
* @since 2024-04-03
|
||||
*/
|
||||
KEBAB_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式) + 全大写命名
|
||||
* Kebab Upper Case
|
||||
* e.g. FOO-BAR
|
||||
*
|
||||
* @alias: kebabUpperCase / KebabUpperCase / kebab upper case / kebab_upper_case / KEBAB_UPPER_CASE
|
||||
* @since 2024-04-03
|
||||
*/
|
||||
KEBAB_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔命名
|
||||
* Space Case / Spinal Case
|
||||
* e.g. foo bar
|
||||
*
|
||||
* @alias: spaceCase / SpaceCase / space case / space_case / SPACE_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔 + 小驼峰(驼峰)命名
|
||||
* Space Camel Case
|
||||
* e.g. foo Bar
|
||||
*
|
||||
* @alias: spaceCamelCase / SpaceCamelCase / space camel case / space_camel_case / SPACE_CAMEL_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔 + 大驼峰(帕斯卡)命名
|
||||
* Space Pascal Case
|
||||
* e.g. Foo Bar
|
||||
*
|
||||
* @alias: spacePascalCase / SpacePascalCase / space pascal case / space_pascal_case / SPACE_PASCAL_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔 + 全大写命名
|
||||
* Space Upper Case
|
||||
* e.g. FOO BAR
|
||||
*
|
||||
* @alias: spaceUpperCase / SpaceUpperCase / space upper case / space_upper_case / SPACE_UPPER_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 点分隔命名
|
||||
* Dot Case / Spinal Case
|
||||
* e.g. foo bar
|
||||
*
|
||||
* @alias: dotCase / DotCase / dot case / dot_case / DOT_CASE
|
||||
* @since 2024-06-13
|
||||
*/
|
||||
DOT_CASE,
|
||||
|
||||
/**
|
||||
* 点分隔 + 小驼峰(驼峰)命名
|
||||
* Dot Camel Case
|
||||
* e.g. foo Bar
|
||||
*
|
||||
* @alias: dotCamelCase / DotCamelCase / dot camel case / dot_camel_case / DOT_CAMEL_CASE
|
||||
* @since 2024-06-13
|
||||
*/
|
||||
DOT_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 点分隔 + 大驼峰(帕斯卡)命名
|
||||
* Dot Pascal Case
|
||||
* e.g. Foo Bar
|
||||
*
|
||||
* @alias: dotPascalCase / DotPascalCase / dot pascal case / dot_pascal_case / DOT_PASCAL_CASE
|
||||
* @since 2024-06-13
|
||||
*/
|
||||
DOT_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 点分隔 + 全大写命名
|
||||
* Dot Upper Case
|
||||
* e.g. FOO BAR
|
||||
*
|
||||
* @alias: dotUpperCase / DotUpperCase / dot upper case / dot_upper_case / DOT_UPPER_CASE
|
||||
* @since 2024-06-13
|
||||
*/
|
||||
DOT_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 全小写
|
||||
* Lower Case
|
||||
* e.g. foo_bar / foobar
|
||||
*
|
||||
* @alias: lowerCase / LowerCase / lower case / lower_case / LOWER_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
LOWER_CASE,
|
||||
|
||||
/**
|
||||
* 全大写
|
||||
* Upper Case
|
||||
* e.g. FOO_BAR / FOOBAR
|
||||
*
|
||||
* @alias: upperCase / UpperCase / upper case / upper_case / UPPER_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
UPPER_CASE,
|
||||
}
|
||||
|
||||
const keyword = {
|
||||
camel: [
|
||||
'小驼峰', '驼峰',
|
||||
'Camel Case',
|
||||
'cc',
|
||||
'XiaoTuoFeng', 'TuoFeng',
|
||||
'xtf', 'tf',
|
||||
],
|
||||
pascal: [
|
||||
'大驼峰', '帕斯卡',
|
||||
'Pascal Case',
|
||||
'pc',
|
||||
'DaTuoFeng', 'PaSiKa',
|
||||
'dtf', 'psk',
|
||||
],
|
||||
snake: [
|
||||
'下划线', '蛇形', '_',
|
||||
'Snake Case', 'Underline Case',
|
||||
'sc', 'uc',
|
||||
'XiaHuaXian', 'SheXing',
|
||||
'xhx', 'sx',
|
||||
],
|
||||
kebab: [
|
||||
'连字符', '脊柱式', '-',
|
||||
'Kebab Case', 'Spinal Case',
|
||||
'kc', 'sc',
|
||||
'LianZiFu', 'JiZhuShi',
|
||||
'lzf', 'jzs',
|
||||
],
|
||||
space: [
|
||||
'空格', // ' ',
|
||||
'Space Case',
|
||||
'sc',
|
||||
'KongGe',
|
||||
'kg',
|
||||
],
|
||||
dot: [
|
||||
'点', '.',
|
||||
'Dot Case',
|
||||
'dc',
|
||||
'Dian',
|
||||
'd',
|
||||
],
|
||||
upper: [
|
||||
'全大写', '大写',
|
||||
'Upper Case',
|
||||
'uc',
|
||||
'QuanDaXie',
|
||||
'qdx',
|
||||
],
|
||||
lower: [
|
||||
'全小写', '小写',
|
||||
'Lower Case',
|
||||
'lc',
|
||||
'QuanXiaoXie',
|
||||
'qxx',
|
||||
],
|
||||
};
|
||||
|
||||
interface Command {
|
||||
command: string;
|
||||
targetCase: SupportVariableCase;
|
||||
settingsKey: string;
|
||||
// variable-conversion.enabledFormats 中的配置项
|
||||
enableSettingsKey: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接管的变量转换命令
|
||||
*/
|
||||
export const commands: Array<Command> = [
|
||||
{
|
||||
command: 'variable-conversion.toCamelCase',
|
||||
targetCase: SupportVariableCase.CAMEL_CASE,
|
||||
settingsKey: 'camel_case',
|
||||
enableSettingsKey: 'camelCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toPascalCase',
|
||||
targetCase: SupportVariableCase.PASCAL_CASE,
|
||||
settingsKey: 'pascal_case',
|
||||
enableSettingsKey: 'pascalCase.enabled',
|
||||
},
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
{
|
||||
command: 'variable-conversion.toSnakeCase',
|
||||
targetCase: SupportVariableCase.SNAKE_CASE,
|
||||
settingsKey: 'snake_case',
|
||||
enableSettingsKey: 'snakeCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toSnakeUpperCase',
|
||||
targetCase: SupportVariableCase.SNAKE_UPPER_CASE,
|
||||
settingsKey: 'snake_upper_case',
|
||||
enableSettingsKey: 'snakeUpperCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toSnakePascalCase',
|
||||
targetCase: SupportVariableCase.SNAKE_PASCAL_CASE,
|
||||
settingsKey: 'snake_pascal_case',
|
||||
enableSettingsKey: 'snakePascalCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toSnakeCamelCase',
|
||||
targetCase: SupportVariableCase.SNAKE_CAMEL_CASE,
|
||||
settingsKey: 'snake_camel_case',
|
||||
enableSettingsKey: 'snakeCamelCase.enabled',
|
||||
},
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
{
|
||||
command: 'variable-conversion.toKebabCase',
|
||||
targetCase: SupportVariableCase.KEBAB_CASE,
|
||||
settingsKey: 'kebab_case',
|
||||
enableSettingsKey: 'kebabCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toKebabUpperCase',
|
||||
targetCase: SupportVariableCase.KEBAB_UPPER_CASE,
|
||||
settingsKey: 'kebab_upper_case',
|
||||
enableSettingsKey: 'kebabUpperCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toKebabPascalCase',
|
||||
targetCase: SupportVariableCase.KEBAB_PASCAL_CASE,
|
||||
settingsKey: 'kebab_pascal_case',
|
||||
enableSettingsKey: 'kebabPascalCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toKebabCamelCase',
|
||||
targetCase: SupportVariableCase.KEBAB_CAMEL_CASE,
|
||||
settingsKey: 'kebab_camel_case',
|
||||
enableSettingsKey: 'kebabCamelCase.enabled',
|
||||
},
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
{
|
||||
command: 'variable-conversion.toSpaceCase',
|
||||
targetCase: SupportVariableCase.SPACE_CASE,
|
||||
settingsKey: 'space_case',
|
||||
enableSettingsKey: 'spaceCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toSpaceUpperCase',
|
||||
targetCase: SupportVariableCase.SPACE_UPPER_CASE,
|
||||
settingsKey: 'space_upper_case',
|
||||
enableSettingsKey: 'spaceUpperCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toSpacePascalCase',
|
||||
targetCase: SupportVariableCase.SPACE_PASCAL_CASE,
|
||||
settingsKey: 'space_pascal_case',
|
||||
enableSettingsKey: 'spacePascalCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toSpaceCamelCase',
|
||||
targetCase: SupportVariableCase.SPACE_CAMEL_CASE,
|
||||
settingsKey: 'space_camel_case',
|
||||
enableSettingsKey: 'spaceCamelCase.enabled',
|
||||
},
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
{
|
||||
command: 'variable-conversion.toDotCase',
|
||||
targetCase: SupportVariableCase.DOT_CASE,
|
||||
settingsKey: 'dot_case',
|
||||
enableSettingsKey: 'dotCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toDotUpperCase',
|
||||
targetCase: SupportVariableCase.DOT_UPPER_CASE,
|
||||
settingsKey: 'dot_upper_case',
|
||||
enableSettingsKey: 'dotUpperCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toDotPascalCase',
|
||||
targetCase: SupportVariableCase.DOT_PASCAL_CASE,
|
||||
settingsKey: 'dot_pascal_case',
|
||||
enableSettingsKey: 'dotPascalCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toDotCamelCase',
|
||||
targetCase: SupportVariableCase.DOT_CAMEL_CASE,
|
||||
settingsKey: 'dot_camel_case',
|
||||
enableSettingsKey: 'dotCamelCase.enabled',
|
||||
},
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
{
|
||||
command: 'variable-conversion.toLowerCase',
|
||||
targetCase: SupportVariableCase.LOWER_CASE,
|
||||
settingsKey: 'lower_case',
|
||||
enableSettingsKey: 'lowerCase.enabled',
|
||||
},
|
||||
{
|
||||
command: 'variable-conversion.toUpperCase',
|
||||
targetCase: SupportVariableCase.UPPER_CASE,
|
||||
settingsKey: 'upper_case',
|
||||
enableSettingsKey: 'upperCase.enabled',
|
||||
},
|
||||
];
|
||||
|
||||
export interface QuickPickSupportCaseItem {
|
||||
type: SupportVariableCase,
|
||||
name: string,
|
||||
shortName: string,
|
||||
keyword: string[],
|
||||
settingsKey: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有支持的命名方式
|
||||
* @since 2024-04-06
|
||||
*/
|
||||
export const quickPickSupportCases: Array<QuickPickSupportCaseItem> = [
|
||||
{
|
||||
type: SupportVariableCase.CAMEL_CASE,
|
||||
name: '小驼峰(驼峰)命名',
|
||||
shortName: '小驼峰',
|
||||
keyword: keyword.camel,
|
||||
settingsKey: 'camel_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.PASCAL_CASE,
|
||||
name: '大驼峰(帕斯卡)命名',
|
||||
shortName: '帕斯卡',
|
||||
keyword: keyword.pascal,
|
||||
settingsKey: 'pascal_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SNAKE_CASE,
|
||||
name: '下划线(蛇形)命名',
|
||||
shortName: '蛇形',
|
||||
keyword: [...keyword.snake, ...keyword.lower],
|
||||
settingsKey: 'snake_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SNAKE_CAMEL_CASE,
|
||||
name: '下划线(蛇形) + 小驼峰(驼峰)命名',
|
||||
shortName: '蛇形驼峰',
|
||||
keyword: [...keyword.snake, ...keyword.camel],
|
||||
settingsKey: 'snake_camel_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SNAKE_PASCAL_CASE,
|
||||
name: '下划线(蛇形) + 大驼峰(帕斯卡)命名',
|
||||
shortName: '蛇形帕斯卡',
|
||||
keyword: [...keyword.snake, ...keyword.pascal],
|
||||
settingsKey: 'snake_pascal_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SNAKE_UPPER_CASE,
|
||||
name: '下划线(蛇形) + 全大写命名',
|
||||
shortName: '蛇形大写',
|
||||
keyword: [...keyword.snake, ...keyword.upper],
|
||||
settingsKey: 'snake_upper_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.KEBAB_CASE,
|
||||
name: '中划线(连字符/脊柱式)命名',
|
||||
shortName: '脊柱',
|
||||
keyword: [...keyword.kebab, ...keyword.lower],
|
||||
settingsKey: 'kebab_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.KEBAB_CAMEL_CASE,
|
||||
name: '中划线(连字符/脊柱式) + 小驼峰(驼峰)命名',
|
||||
shortName: '脊柱驼峰',
|
||||
keyword: [...keyword.kebab, ...keyword.camel],
|
||||
settingsKey: 'kebab_camel_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.KEBAB_PASCAL_CASE,
|
||||
name: '中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名',
|
||||
shortName: '脊柱帕斯卡',
|
||||
keyword: [...keyword.kebab, ...keyword.pascal],
|
||||
settingsKey: 'kebab_pascal_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.KEBAB_UPPER_CASE,
|
||||
name: '中划线(连字符/脊柱式) + 全大写命名',
|
||||
shortName: '脊柱大写',
|
||||
keyword: [...keyword.kebab, ...keyword.upper],
|
||||
settingsKey: 'kebab_upper_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SPACE_CASE,
|
||||
name: '空格分隔命名',
|
||||
shortName: '脊柱',
|
||||
keyword: [...keyword.space, ...keyword.lower],
|
||||
settingsKey: 'space_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SPACE_CAMEL_CASE,
|
||||
name: '空格分隔 + 小驼峰(驼峰)命名',
|
||||
shortName: '脊柱驼峰',
|
||||
keyword: [...keyword.space, ...keyword.camel],
|
||||
settingsKey: 'space_camel_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SPACE_PASCAL_CASE,
|
||||
name: '空格分隔 + 大驼峰(帕斯卡)命名',
|
||||
shortName: '脊柱帕斯卡',
|
||||
keyword: [...keyword.space, ...keyword.pascal],
|
||||
settingsKey: 'space_pascal_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.SPACE_UPPER_CASE,
|
||||
name: '空格分隔 + 全大写命名',
|
||||
shortName: '脊柱大写',
|
||||
keyword: [...keyword.space, ...keyword.upper],
|
||||
settingsKey: 'space_upper_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.DOT_CASE,
|
||||
name: '点分隔命名',
|
||||
shortName: '脊柱',
|
||||
keyword: [...keyword.dot, ...keyword.lower],
|
||||
settingsKey: 'dot_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.DOT_CAMEL_CASE,
|
||||
name: '点分隔 + 小驼峰(驼峰)命名',
|
||||
shortName: '脊柱驼峰',
|
||||
keyword: [...keyword.dot, ...keyword.camel],
|
||||
settingsKey: 'dot_camel_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.DOT_PASCAL_CASE,
|
||||
name: '点分隔 + 大驼峰(帕斯卡)命名',
|
||||
shortName: '脊柱帕斯卡',
|
||||
keyword: [...keyword.dot, ...keyword.pascal],
|
||||
settingsKey: 'dot_pascal_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.DOT_UPPER_CASE,
|
||||
name: '点分隔 + 全大写命名',
|
||||
shortName: '脊柱大写',
|
||||
keyword: [...keyword.dot, ...keyword.upper],
|
||||
settingsKey: 'dot_upper_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.LOWER_CASE,
|
||||
name: '全小写',
|
||||
shortName: '小写',
|
||||
keyword: keyword.lower,
|
||||
settingsKey: 'lower_case',
|
||||
},
|
||||
{
|
||||
type: SupportVariableCase.UPPER_CASE,
|
||||
name: '全大写',
|
||||
shortName: '大写',
|
||||
keyword: keyword.upper,
|
||||
settingsKey: 'upper_case',
|
||||
},
|
||||
];
|
||||
|
||||
export interface CyclicConvertCaseOrderItem {
|
||||
type: SupportVariableCase,
|
||||
settingsKey: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过快捷键循环转换的顺序
|
||||
* @since 2024-04-08
|
||||
*/
|
||||
export const cyclicConvertCaseOrder: Array<CyclicConvertCaseOrderItem> = [
|
||||
{ type: SupportVariableCase.CAMEL_CASE, settingsKey: 'camel_case' },
|
||||
{ type: SupportVariableCase.SNAKE_CASE, settingsKey: 'snake_case' },
|
||||
{ type: SupportVariableCase.PASCAL_CASE, settingsKey: 'pascal_case' },
|
||||
{ type: SupportVariableCase.KEBAB_CASE, settingsKey: 'kebab_case' },
|
||||
{ type: SupportVariableCase.SPACE_CASE, settingsKey: 'space_case' },
|
||||
{ type: SupportVariableCase.DOT_CASE, settingsKey: 'dot_case' },
|
||||
|
||||
{ type: SupportVariableCase.SNAKE_UPPER_CASE, settingsKey: 'snake_upper_case' },
|
||||
{ type: SupportVariableCase.KEBAB_UPPER_CASE, settingsKey: 'kebab_upper_case' },
|
||||
{ type: SupportVariableCase.SPACE_UPPER_CASE, settingsKey: 'space_upper_case' },
|
||||
{ type: SupportVariableCase.DOT_UPPER_CASE, settingsKey: 'dot_upper_case' },
|
||||
|
||||
{ type: SupportVariableCase.SNAKE_PASCAL_CASE, settingsKey: 'snake_pascal_case' },
|
||||
{ type: SupportVariableCase.KEBAB_PASCAL_CASE, settingsKey: 'kebab_pascal_case' },
|
||||
{ type: SupportVariableCase.SPACE_PASCAL_CASE, settingsKey: 'space_pascal_case' },
|
||||
{ type: SupportVariableCase.DOT_PASCAL_CASE, settingsKey: 'dot_pascal_case' },
|
||||
|
||||
{ type: SupportVariableCase.SNAKE_CAMEL_CASE, settingsKey: 'snake_camel_case' },
|
||||
{ type: SupportVariableCase.KEBAB_CAMEL_CASE, settingsKey: 'kebab_camel_case' },
|
||||
{ type: SupportVariableCase.SPACE_CAMEL_CASE, settingsKey: 'space_camel_case' },
|
||||
{ type: SupportVariableCase.DOT_CAMEL_CASE, settingsKey: 'dot_camel_case' },
|
||||
|
||||
{ type: SupportVariableCase.LOWER_CASE, settingsKey: 'lower_case' },
|
||||
{ type: SupportVariableCase.UPPER_CASE, settingsKey: 'upper_case' },
|
||||
];
|
@@ -1,8 +1,8 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from '../../types/EOLType';
|
||||
import { caseConversion } from '../../core/variable-convert/conversion';
|
||||
import { SupportVariableCase } from '../../core/variable-convert/types/SupportVariableCaseType';
|
||||
import { isStringArrayEqual } from '../../utils/utils';
|
||||
import { EOL } from '../type-definition/EOLType';
|
||||
import { caseConversion } from '../main-code/conversion';
|
||||
import { SupportCase } from '../type-definition/SupportCaseType';
|
||||
import { isStringArrayEqual } from '../main-code/utils';
|
||||
|
||||
/**
|
||||
* 编辑器右键菜单
|
||||
@@ -10,7 +10,7 @@ import { isStringArrayEqual } from '../../utils/utils';
|
||||
* @param convertFunction
|
||||
* @returns
|
||||
*/
|
||||
const handleEditorReplace = (targetCase: SupportVariableCase) => {
|
||||
const handleEditorReplace = (targetCase: SupportCase) => {
|
||||
// 获取当前编辑器
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
@@ -1,12 +1,11 @@
|
||||
import * as vscode from 'vscode';
|
||||
import QuickPickItemEx from "../types/QuickPickItemExType";
|
||||
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../../core/variable-convert/types/SupportVariableCaseType';
|
||||
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';
|
||||
import QuickPickItemEx from "../type-definition/QuickPickItemExType";
|
||||
import { quickPickSupportCases } from '../type-definition/SupportCaseType';
|
||||
import { TransformTextResult } from '../type-definition/TransformTextResultType';
|
||||
import { transformMutliLineText, transformMutliSelectionText } from '../main-code/transform';
|
||||
import { EOL } from '../type-definition/EOLType';
|
||||
import { caseConversion } from '../main-code/conversion';
|
||||
import { isStringArrayEqual } from '../main-code/utils';
|
||||
|
||||
const QuickPickLabelMaxLength = 60;
|
||||
|
||||
@@ -19,12 +18,12 @@ interface RecommendItem {
|
||||
/**
|
||||
* 弹出的提示
|
||||
*/
|
||||
function generateOptionsBasedOnText(textList: string[], eol: EOL, enabledQuickPickSupportCases: Array<QuickPickSupportCaseItem>): Array<QuickPickItemEx> {
|
||||
function generateOptionsBasedOnText(textList: string[], eol: EOL): Array<QuickPickItemEx> {
|
||||
// Cut text 切割文本
|
||||
const resultsList: Array<TransformTextResult[]> = transformMutliSelectionText(textList);
|
||||
|
||||
const mergeResultList: Array<RecommendItem> = [];
|
||||
for (const quickPick of enabledQuickPickSupportCases) {
|
||||
for (const quickPick of quickPickSupportCases) {
|
||||
const conversionResults: Array<string> = [];
|
||||
for (let i = 0; i < textList.length; i++) {
|
||||
const text = textList[i];
|
||||
@@ -96,24 +95,8 @@ export function handleQuickPick() {
|
||||
return;
|
||||
}
|
||||
|
||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||
// 获取用户配置
|
||||
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
|
||||
// 排除禁用的选项
|
||||
const enabledQuickPickSupportCases = [];
|
||||
for (const quickPick of quickPickSupportCases) {
|
||||
if (enabledFormats[quickPick.settingsKey] === false) {
|
||||
continue;
|
||||
}
|
||||
enabledQuickPickSupportCases.push(quickPick);
|
||||
}
|
||||
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.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 基于选中的文本生成选项
|
||||
const options = generateOptionsBasedOnText(textList, eol, enabledQuickPickSupportCases);
|
||||
const options = generateOptionsBasedOnText(textList, eol);
|
||||
if (options.length === 0) {
|
||||
vscode.window.showInformationMessage('所选内容暂无可选转换,请尝试重新选择\nNo conversion candidates are available for the selected content, please try to select another text.');
|
||||
return;
|
||||
@@ -122,7 +105,7 @@ export function handleQuickPick() {
|
||||
// 显示推荐项列表
|
||||
vscode.window.showQuickPick(options, {
|
||||
matchOnDetail: true,
|
||||
title: '请选择需要转换的命名方式...',
|
||||
title: '请选择需要转换的命名类型...',
|
||||
placeHolder: '点击转换,输入关键词可快速选择'
|
||||
}).then(pickItem => {
|
||||
if (!editor || pickItem === undefined) {
|
36
src/extension-handler/status-bar-handler.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
// docs: https://code.visualstudio.com/api/references/vscode-api#StatusBarItem
|
||||
|
||||
let statusBar: vscode.StatusBarItem;
|
||||
|
||||
/**
|
||||
* 创建状态栏按钮
|
||||
*
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
export function createStatusBarItem() {
|
||||
statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||
statusBar.text = '$(find-replace)变量转换';
|
||||
statusBar.command = 'variable-conversion.convertCase';
|
||||
// statusBar.color = 'red';
|
||||
// statusBar.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否展示状态栏按钮
|
||||
*
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
export function updateStatusBarItemVisable(selectTextLength: number) {
|
||||
if (!statusBar) {
|
||||
return;
|
||||
}
|
||||
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (editor && selectTextLength > 0) {
|
||||
statusBar.show();
|
||||
return;
|
||||
}
|
||||
statusBar.hide();
|
||||
}
|
134
src/extension.ts
@@ -1,33 +1,12 @@
|
||||
/**
|
||||
* @file extension.ts
|
||||
* @description 该文件包含了 VS Code 插件的主要扩展逻辑,包括命令注册、菜单配置和编辑器事件监听等。
|
||||
* @author coder-xiaomo
|
||||
* @version 1.0.0
|
||||
* @license MIT
|
||||
*
|
||||
* 本文件是插件的核心文件,负责扩展命令的注册以及编辑器中各种事件的处理。通过监听编辑器的选择状态,
|
||||
* 动态更新命令行为。插件在启动时会初始化必要的命令,并根据编辑器状态决定是否启用相关功能。
|
||||
*
|
||||
* @see https://code.visualstudio.com/api
|
||||
*/
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
// Variable Convert
|
||||
import handleEditorReplaceVariable from './handler/variable-convert/editor-submenu-handler';
|
||||
import { handleQuickPick as handleQuickPickVariable } from './handler/variable-convert/quick-pick-handler';
|
||||
import { commands as variableCommands } from './core/variable-convert/types/SupportVariableCaseType';
|
||||
import * as CyclicConversionVariable from './core/variable-convert/cyclic-conversion';
|
||||
|
||||
// Path Convert
|
||||
import handleEditorReplacePath from './handler/path-convert/editor-submenu-handler';
|
||||
import { handleQuickPick as handleQuickPickPath } from './handler/path-convert/quick-pick-handler';
|
||||
import { commands as pathCommands } from './core/path-convert/types/SupportPathFormatType';
|
||||
import * as CyclicConversionPath from './core/path-convert/cyclic-conversion';
|
||||
|
||||
// Common
|
||||
import { createStatusBarItem, updateStatusBarItemVisible } from './handler/status-bar-handler';
|
||||
import { EOL } from './types/EOLType';
|
||||
import { getUserConfigurations } from './utils/user-configuration';
|
||||
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';
|
||||
|
||||
// This method is called when your extension is activated
|
||||
// Your extension is activated the very first time the command is executed
|
||||
@@ -62,29 +41,12 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// 更新 _textSelectionLength (用于判断是否展示右键菜单)
|
||||
vscode.commands.executeCommand('setContext', '_textSelectionLength', selectTextLength);
|
||||
|
||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||
// 获取用户配置
|
||||
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
|
||||
const disablePathFormatList = getUserConfigurations<Array<string>>('disablePathFormat') || [];
|
||||
// 更新右键菜单每一项是否展示
|
||||
// 变量转换右键菜单visible 2024.07.29
|
||||
for (const { settingsKey, enableSettingsKey } of variableCommands) {
|
||||
vscode.commands.executeCommand('setContext', '_isHideSubMenuItem_' + settingsKey, enabledFormats[enableSettingsKey] === false);
|
||||
}
|
||||
// 路径转换右键菜单visible 2024.12.14
|
||||
for (const { settingsKey } of pathCommands) {
|
||||
vscode.commands.executeCommand('setContext', '_isHideSubMenuItem_' + settingsKey, disablePathFormatList.includes(settingsKey));
|
||||
}
|
||||
|
||||
// 判断是否展示状态栏按钮
|
||||
updateStatusBarItemVisible(selectTextLength);
|
||||
updateStatusBarItemVisable(selectTextLength);
|
||||
|
||||
// 循环转换:记录当前选中内容,并且进行转换
|
||||
let eol: EOL = textEditor.document.eol === vscode.EndOfLine.CRLF ? '\r\n' : '\n';
|
||||
// 变量循环转换 2024.04.09
|
||||
CyclicConversionVariable.onUserSelectionUpdated(selections, textList, eol);
|
||||
// 路径循环转换 2024.12.14
|
||||
CyclicConversionPath.onUserSelectionUpdated(selections, textList, eol);
|
||||
CyclicConversion.onUserSelectionUpdated(selections, textList, eol);
|
||||
};
|
||||
|
||||
// 创建状态栏按钮
|
||||
@@ -95,17 +57,8 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
*/
|
||||
vscode.window.onDidChangeActiveTextEditor(event => {
|
||||
console.log('onDidChangeActiveTextEditor', event);
|
||||
|
||||
// 小窗中编辑器选中后,不做其他点击鼠标点击操作,直接点击主窗口任务栏[变量转换]按钮
|
||||
// 能够在主窗口 QuickPick 中对小窗中所选文字进行转换操作 (不太完美的兼容)
|
||||
let textEditor = vscode.window.activeTextEditor;
|
||||
if (textEditor) {
|
||||
const selections = textEditor.selections;
|
||||
onTextEditorSelectionChangeCallback(textEditor, selections);
|
||||
} else { // 进入 else 的场景举例: 从[代码编辑器]切换到[设置页]
|
||||
// 判断是否展示状态栏按钮
|
||||
updateStatusBarItemVisible(selectTextLength);
|
||||
}
|
||||
// 判断是否展示状态栏按钮
|
||||
updateStatusBarItemVisable(selectTextLength);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -124,70 +77,29 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
onTextEditorSelectionChangeCallback(editor, editor.selections);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 变量转换
|
||||
*
|
||||
* @since 2024-04
|
||||
*/
|
||||
|
||||
// 逐一注册右键菜单-子菜单项 command
|
||||
for (const { command, targetCase } of variableCommands) {
|
||||
for (const { command, targetCase } of commands) {
|
||||
let disposable = vscode.commands.registerCommand(command, () => {
|
||||
// 变量转换右键菜单 2024.04.05
|
||||
handleEditorReplaceVariable(targetCase);
|
||||
handleEditorReplace(targetCase);
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
// 注册变量转换 command 状态栏/快捷键/右键[变量转换]菜单均有用到
|
||||
let convertCaseDisposable = vscode.commands.registerCommand('variable-conversion.convertCase', handleQuickPickVariable);
|
||||
let convertCaseDisposable = vscode.commands.registerCommand('variable-conversion.convertCase', handleQuickPick);
|
||||
context.subscriptions.push(convertCaseDisposable);
|
||||
|
||||
// 注册循环转换 command
|
||||
let loopConvertCasePrevDisposable = vscode.commands.registerCommand('variable-conversion.cyclicConvertCase.previous', ({ arrowKey }) => {
|
||||
console.log('variable-conversion.cyclicConvertCase.previous', arrowKey);
|
||||
CyclicConversionVariable.previousOne();
|
||||
let disposableLoopConversionPrev = vscode.commands.registerCommand('variable-conversion.cyclicConvertCase.previous', ({ arrowKey }) => {
|
||||
console.log('variable-conversion.convertCase', arrowKey);
|
||||
CyclicConversion.previousOne();
|
||||
});
|
||||
context.subscriptions.push(loopConvertCasePrevDisposable);
|
||||
let loopConvertCaseNextDisposable = vscode.commands.registerCommand('variable-conversion.cyclicConvertCase.next', ({ arrowKey }) => {
|
||||
console.log('variable-conversion.cyclicConvertCase.next', arrowKey);
|
||||
CyclicConversionVariable.nextOne();
|
||||
context.subscriptions.push(disposableLoopConversionPrev);
|
||||
let disposableLoopConversionNext = vscode.commands.registerCommand('variable-conversion.cyclicConvertCase.next', ({ arrowKey }) => {
|
||||
console.log('variable-conversion.convertCase', arrowKey);
|
||||
CyclicConversion.nextOne();
|
||||
});
|
||||
context.subscriptions.push(loopConvertCaseNextDisposable);
|
||||
|
||||
|
||||
/**
|
||||
* 路径转换
|
||||
* issue: #3 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/3
|
||||
*
|
||||
* @since 2024-12
|
||||
*/
|
||||
|
||||
// 逐一注册右键菜单-子菜单项 command
|
||||
for (const { command, targetCase } of pathCommands) {
|
||||
let disposable = vscode.commands.registerCommand(command, () => {
|
||||
// 变量转换右键菜单 2024.12.14
|
||||
handleEditorReplacePath(targetCase);
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
// 注册路径转换 command 状态栏/快捷键/右键[路径转换]菜单均有用到
|
||||
let convertPathDisposable = vscode.commands.registerCommand('variable-conversion.convertPath', handleQuickPickPath);
|
||||
context.subscriptions.push(convertPathDisposable);
|
||||
|
||||
// 注册循环转换 command
|
||||
let loopConvertPathPrevDisposable = vscode.commands.registerCommand('variable-conversion.cyclicConvertPath.previous', ({ direction }) => {
|
||||
console.log('variable-conversion.cyclicConvertPath.previous', direction);
|
||||
CyclicConversionPath.previousOne();
|
||||
});
|
||||
context.subscriptions.push(loopConvertPathPrevDisposable);
|
||||
let loopConvertPathNextDisposable = vscode.commands.registerCommand('variable-conversion.cyclicConvertPath.next', ({ direction }) => {
|
||||
console.log('variable-conversion.cyclicConvertPath.next', direction);
|
||||
CyclicConversionPath.nextOne();
|
||||
});
|
||||
context.subscriptions.push(loopConvertPathNextDisposable);
|
||||
context.subscriptions.push(disposableLoopConversionNext);
|
||||
}
|
||||
|
||||
// This method is called when your extension is deactivated
|
||||
|
@@ -1,59 +0,0 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from '../../types/EOLType';
|
||||
import { pathConversion } from '../../core/path-convert/conversion';
|
||||
import { SupportPathFormat } from '../../core/path-convert/types/SupportPathFormatType';
|
||||
import { isStringArrayEqual } from '../../utils/utils';
|
||||
|
||||
/**
|
||||
* 编辑器右键菜单
|
||||
*
|
||||
* @param convertFunction
|
||||
* @returns
|
||||
*/
|
||||
const handleEditorReplace = (targetCase: SupportPathFormat) => {
|
||||
// 获取当前编辑器
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = editor.document;
|
||||
const selections = editor.selections;
|
||||
const eol: EOL = document.eol === vscode.EndOfLine.CRLF ? '\r\n' : '\n';
|
||||
|
||||
// 获取选中的文本
|
||||
const textList = selections.map(selection => document.getText(selection));
|
||||
|
||||
if (textList.filter(text => text.length > 0).length === 0) {
|
||||
vscode.window.showInformationMessage('请选择需要转换的路径后重试\nPlease select the path you want to convert and try again.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 转换文本
|
||||
const convertedList = textList.map(text => pathConversion(targetCase, text, eol));
|
||||
console.log('convertedList', convertedList);
|
||||
|
||||
// 无法转换时,跳过转换
|
||||
if (convertedList.filter(converted => converted !== undefined).length === 0) {
|
||||
console.log('converted text is undefined, skip replace contents.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 当转换后文本与转换前相同时,跳过转换,避免形成 Ctrl + Z 撤销历史记录
|
||||
if (isStringArrayEqual(convertedList, textList)) {
|
||||
console.log('selection text is same to converted text, skip replace contents.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 替换文本
|
||||
console.log('replace selection text', textList, 'to', convertedList);
|
||||
editor.edit(editBuilder => {
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
const selection = selections[i];
|
||||
const converted = convertedList[i];
|
||||
editBuilder.replace(selection, converted);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default handleEditorReplace;
|
@@ -1,144 +0,0 @@
|
||||
import * as vscode from 'vscode';
|
||||
import QuickPickItemEx from "../types/QuickPickItemExType";
|
||||
import { QuickPickSupportCaseItem, quickPickSupportCases } from '../../core/path-convert/types/SupportPathFormatType';
|
||||
import { TransformTextResult } from '../../types/TransformTextResultType';
|
||||
import { transformMutliSelectionText } from '../../utils/transform';
|
||||
import { EOL } from '../../types/EOLType';
|
||||
import { pathConversion } from '../../core/path-convert/conversion';
|
||||
import { isStringArrayEqual } from '../../utils/utils';
|
||||
import { getUserConfigurations } from '../../utils/user-configuration';
|
||||
|
||||
const QuickPickLabelMaxLength = 60;
|
||||
|
||||
interface RecommendItem {
|
||||
conversionText: Array<string>
|
||||
transforTo: string[]
|
||||
keyword: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出的提示
|
||||
*
|
||||
* @since 2024-12-14
|
||||
*/
|
||||
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 enabledQuickPickSupportCases) {
|
||||
const conversionResults: Array<string> = [];
|
||||
for (let i = 0; i < textList.length; i++) {
|
||||
const text = textList[i];
|
||||
const results = resultsList[i];
|
||||
const conversionResult: string = pathConversion(quickPick.type, text, eol, results);
|
||||
conversionResults.push(conversionResult);
|
||||
}
|
||||
const recommendItem: RecommendItem | undefined = mergeResultList.find(item => isStringArrayEqual(item.conversionText, conversionResults));
|
||||
|
||||
if (recommendItem === undefined) {
|
||||
let item: RecommendItem = {
|
||||
conversionText: conversionResults,
|
||||
transforTo: [quickPick.shortName], // quickPick.name
|
||||
keyword: quickPick.keyword,
|
||||
};
|
||||
mergeResultList.push(item);
|
||||
continue;
|
||||
}
|
||||
|
||||
recommendItem.transforTo.push(quickPick.shortName); // quickPick.name
|
||||
recommendItem.keyword = Array.from(new Set(recommendItem.keyword.concat(quickPick.keyword))); // 关键词去重
|
||||
}
|
||||
|
||||
// 根据文本生成选项的逻辑
|
||||
const quickPickList = [];
|
||||
|
||||
for (const recommendItem of mergeResultList) {
|
||||
if (isStringArrayEqual(textList, recommendItem.conversionText)) {
|
||||
continue; // 如果转换后与转换前相同,那么跳过这一项
|
||||
}
|
||||
const conversionTextForDisplay = recommendItem.conversionText.join(' ').replace(/\s+/g, " "); // 友好展示 将连续空格 \n \t 等替换为单一空格
|
||||
let quickPickItem: QuickPickItemEx = {
|
||||
label: conversionTextForDisplay.length >= QuickPickLabelMaxLength
|
||||
? (conversionTextForDisplay.substring(0, QuickPickLabelMaxLength - 3) + '...')
|
||||
: conversionTextForDisplay,
|
||||
description: `转换为 ${recommendItem.transforTo.join(' / ')}`,
|
||||
detail: `关键词 ${recommendItem.keyword.join(' ')}`,
|
||||
value: recommendItem.conversionText,
|
||||
};
|
||||
quickPickList.push(quickPickItem);
|
||||
}
|
||||
return quickPickList;
|
||||
}
|
||||
|
||||
export function handleQuickPick() {
|
||||
// 获取当前编辑器
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = editor.document;
|
||||
const selections = editor.selections;
|
||||
const eol: EOL = document.eol === vscode.EndOfLine.CRLF ? '\r\n' : '\n';
|
||||
|
||||
// 获取选中的文本
|
||||
const textList = selections.map(selection => document.getText(selection));
|
||||
|
||||
if (textList.filter(text => text.length > 0).length === 0) {
|
||||
vscode.window.showInformationMessage('请选择需要转换的路径后重试\nPlease select the path you want to convert and try again.');
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// 获取用户配置
|
||||
const disablePathFormatList = getUserConfigurations<Array<string>>('disablePathFormat') || [];
|
||||
// 排除禁用的选项
|
||||
const enabledQuickPickSupportCases = [];
|
||||
for (const quickPick of quickPickSupportCases) {
|
||||
if (disablePathFormatList.includes(quickPick.settingsKey)) {
|
||||
continue;
|
||||
}
|
||||
enabledQuickPickSupportCases.push(quickPick);
|
||||
}
|
||||
if (enabledQuickPickSupportCases.length === 0) {
|
||||
vscode.window.showInformationMessage('所有格式都已被配置为禁用,请修改配置 `variable-conversion.disablePathFormat` 后重试\nAll formats have been configured to disable. Modify the `variable-conversion.disablePathFormat` configuration and try again.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 基于选中的文本生成选项
|
||||
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;
|
||||
}
|
||||
|
||||
// 显示推荐项列表
|
||||
vscode.window.showQuickPick(options, {
|
||||
matchOnDetail: true,
|
||||
title: '请选择需要转换的路径风格...',
|
||||
placeHolder: '点击转换,输入关键词可快速选择'
|
||||
}).then(pickItem => {
|
||||
if (!editor || pickItem === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const convertedList = pickItem.value;
|
||||
|
||||
// 当转换后文本与转换前相同时,跳过转换,避免形成 Ctrl + Z 撤销历史记录
|
||||
if (isStringArrayEqual(convertedList, textList)) {
|
||||
console.log('selection text is same to converted text, skip replace contents.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 替换文本
|
||||
console.log('replace selection text', textList, 'to', convertedList);
|
||||
editor.edit(editBuilder => {
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
const selection = selections[i];
|
||||
const converted = convertedList[i];
|
||||
editBuilder.replace(selection, converted);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
// docs: https://code.visualstudio.com/api/references/vscode-api#StatusBarItem
|
||||
|
||||
let statusBarItemList: Array<vscode.StatusBarItem> = [];
|
||||
|
||||
/**
|
||||
* 创建状态栏按钮
|
||||
*
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
export function createStatusBarItem() {
|
||||
// 变量转换状态栏 2024.04.07
|
||||
const createVariableConvertStatusBarItem = () => {
|
||||
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||
// Icon Listing docs: https://code.visualstudio.com/api/references/icons-in-labels#icon-listing
|
||||
statusBarItem.text = '$(find-replace)变量转换';
|
||||
statusBarItem.command = 'variable-conversion.convertCase';
|
||||
// statusBarItem.color = 'red';
|
||||
// statusBarItem.show();
|
||||
return statusBarItem;
|
||||
};
|
||||
// 路径转换状态栏 2024.12.14
|
||||
const createPathConvertStatusBarItem = () => {
|
||||
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||
statusBarItem.text = '$(sync-ignored)路径转换'; // italic symbol-null
|
||||
statusBarItem.command = 'variable-conversion.convertPath';
|
||||
statusBarItemList.push(statusBarItem);
|
||||
return statusBarItem;
|
||||
};
|
||||
|
||||
statusBarItemList.push(
|
||||
createVariableConvertStatusBarItem(),
|
||||
createPathConvertStatusBarItem(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否展示状态栏按钮
|
||||
*
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
export function updateStatusBarItemVisible(selectTextLength: number) {
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (editor && selectTextLength > 0) {
|
||||
statusBarItemList.forEach(statusBarItem => {
|
||||
statusBarItem.show();
|
||||
});
|
||||
return;
|
||||
}
|
||||
statusBarItemList.forEach(statusBarItem => {
|
||||
statusBarItem.hide();
|
||||
});
|
||||
}
|
125
src/main-code/conversion.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { EOL } from '../type-definition/EOLType';
|
||||
import { SupportCase } from '../type-definition/SupportCaseType';
|
||||
import { TransformTextResult } from '../type-definition/TransformTextResultType';
|
||||
import { transformMutliLineText, transformText } from './transform';
|
||||
|
||||
/**
|
||||
* 统一文本转换函数
|
||||
*
|
||||
* @param {SupportCase} targetCase 目标文本情况
|
||||
* @param {string} str 用户选择的文本 user selection
|
||||
* @param {EOL} eol 行结束符
|
||||
* @returns 转换后的文本
|
||||
* @since 2024-04-04
|
||||
*/
|
||||
export function caseConversion(targetCase: SupportCase, str: string, eol: EOL, cutText: Array<TransformTextResult> | undefined = undefined): string {
|
||||
let spaceCharacter: '-' | '_' | ' ' | undefined = undefined;
|
||||
switch (targetCase) {
|
||||
default:
|
||||
case SupportCase.CAMEL_CASE: // 小驼峰(驼峰)命名
|
||||
case SupportCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
|
||||
spaceCharacter = undefined;
|
||||
break;
|
||||
case SupportCase.SNAKE_CASE: // 下划线(蛇形)命名
|
||||
case SupportCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
|
||||
case SupportCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
|
||||
case SupportCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
|
||||
spaceCharacter = '_';
|
||||
break;
|
||||
case SupportCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
|
||||
case SupportCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
|
||||
case SupportCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
|
||||
case SupportCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
|
||||
spaceCharacter = '-';
|
||||
break;
|
||||
case SupportCase.SPACE_CASE: // 空格分隔命名
|
||||
case SupportCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
|
||||
case SupportCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
|
||||
case SupportCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
|
||||
spaceCharacter = ' ';
|
||||
break;
|
||||
case SupportCase.LOWER_CASE: // 全小写
|
||||
return str.toLowerCase();
|
||||
case SupportCase.UPPER_CASE: // 全大写
|
||||
return str.toUpperCase();
|
||||
}
|
||||
|
||||
// Cut text 切割文本
|
||||
const results: Array<TransformTextResult> = cutText === undefined ? transformMutliLineText(str) : cutText;
|
||||
// console.log('results', results);
|
||||
|
||||
const transformedLines: Array<string> = [];
|
||||
for (const result of results) {
|
||||
// Post Process 后置处理
|
||||
const words = result.trimResult.split('|');
|
||||
|
||||
let isFirstWord: boolean = true;// [驼峰写法] 用于判断首词小写
|
||||
let isPreviousWordSpecial = true; // 用于判断上一个词是 单词 or 特殊字符
|
||||
const transformedWords: Array<string> = [];
|
||||
for (let index = 0; index < words.length; index++) {
|
||||
const word = words[index];
|
||||
|
||||
const firstLetter = word.charAt(0);
|
||||
const pascalCaseWord = firstLetter.toUpperCase() + word.slice(1);
|
||||
|
||||
// 当前 word 是否是特殊单词
|
||||
// const isCurrentWordNormal = firstLetter !== firstLetter.toUpperCase(); // 是小写 a-z (不是特殊字符)
|
||||
const isCurrentWordNormal = /^[A-Za-z]+$/.test(word);
|
||||
// /^[A-Za-z]+$/.test("") false
|
||||
// /^[A-Za-z]+$/.test("苹果") true
|
||||
// /^[A-Za-z]+$/.test("apple") true
|
||||
const isCurrentWordSpecial = !isCurrentWordNormal;
|
||||
|
||||
// 添加连字符
|
||||
if (!isPreviousWordSpecial && !isCurrentWordSpecial) {
|
||||
spaceCharacter !== undefined
|
||||
&& transformedWords.push(spaceCharacter);
|
||||
}
|
||||
|
||||
// 根据目标情况转换单词
|
||||
switch (targetCase) {
|
||||
case SupportCase.CAMEL_CASE: // 小驼峰(驼峰)命名
|
||||
case SupportCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
|
||||
case SupportCase.KEBAB_CAMEL_CASE: // 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
|
||||
case SupportCase.SPACE_CAMEL_CASE: // 空格分隔 + 小驼峰(驼峰)命名
|
||||
if (isFirstWord) {
|
||||
transformedWords.push(word);
|
||||
if (isCurrentWordNormal) {
|
||||
isFirstWord = false;
|
||||
}
|
||||
} else {
|
||||
transformedWords.push(pascalCaseWord);
|
||||
}
|
||||
break;
|
||||
case SupportCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
|
||||
case SupportCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
|
||||
case SupportCase.KEBAB_PASCAL_CASE: // 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
|
||||
case SupportCase.SPACE_PASCAL_CASE: // 空格分隔 + 大驼峰(帕斯卡)命名
|
||||
transformedWords.push(pascalCaseWord);
|
||||
break;
|
||||
case SupportCase.SNAKE_CASE: // 下划线(蛇形)命名
|
||||
case SupportCase.KEBAB_CASE: // 中划线(连字符/脊柱式)命名
|
||||
case SupportCase.SPACE_CASE: // 空格分隔命名
|
||||
transformedWords.push(word);
|
||||
break;
|
||||
case SupportCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
|
||||
case SupportCase.KEBAB_UPPER_CASE: // 中划线(连字符/脊柱式) + 全大写命名
|
||||
case SupportCase.SPACE_UPPER_CASE: // 空格分隔 + 全大写命名
|
||||
transformedWords.push(word.toUpperCase());
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported case: ${targetCase}`);
|
||||
}
|
||||
|
||||
if (word === '\n' || word === '\r\n') {
|
||||
isFirstWord = true; // 换行后,重新计算首词
|
||||
}
|
||||
|
||||
isPreviousWordSpecial = isCurrentWordSpecial;
|
||||
}
|
||||
|
||||
const transformedLine = result.leadingSpace + transformedWords.join('') + result.trailingSpace;
|
||||
transformedLines.push(transformedLine);
|
||||
}
|
||||
return transformedLines.join(eol);
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EOL } from "../../types/EOLType";
|
||||
import { cyclicConvertCaseOrder } from "./types/SupportVariableCaseType";
|
||||
import { EOL } from "../type-definition/EOLType";
|
||||
import { cyclicConvertCaseOrder } from "../type-definition/SupportCaseType";
|
||||
import { caseConversion } from "./conversion";
|
||||
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from '../../utils/utils';
|
||||
import { getUserConfigurations } from '../../utils/user-configuration';
|
||||
import { isStringArrayEqual, stringListArrayDuplicateRemoval } from './utils';
|
||||
|
||||
interface UserSelection {
|
||||
currentEol: EOL
|
||||
@@ -65,25 +64,16 @@ function lazyConvert() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取用户配置
|
||||
const enabledFormats = getUserConfigurations<Record<string, boolean>>('enabledFormats') || {};
|
||||
|
||||
const textList = userSelection.currentSelectionsText;
|
||||
// vscode.window.showInformationMessage('lazyConvert' + textList.join('\n'));
|
||||
const eol = userSelection.currentEol;
|
||||
const conversionsTarget: Array<string[]> = [textList];
|
||||
for (const cyclicConvertCase of cyclicConvertCaseOrder) {
|
||||
// issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1
|
||||
// 跳过禁用的目标格式
|
||||
if (enabledFormats[cyclicConvertCase.settingsKey] === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 每一个类型
|
||||
const conversionsTargetItem: string[] = [];
|
||||
for (const line of textList) {
|
||||
// 选中区块的每一行
|
||||
const conversionResult: string = caseConversion(cyclicConvertCase.type, line, eol);
|
||||
const conversionResult: string = caseConversion(cyclicConvertCase, line, eol);
|
||||
conversionsTargetItem.push(conversionResult);
|
||||
}
|
||||
conversionsTarget.push(conversionsTargetItem);
|
||||
@@ -112,4 +102,4 @@ function replaceTextEditorSelectedText() {
|
||||
});
|
||||
userSelection.lastConvertedSelectionsText = textList;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
import { TransformTextResult } from "../types/TransformTextResultType";
|
||||
import { TransformTextResult } from "../type-definition/TransformTextResultType";
|
||||
|
||||
const logDebugInfo = false;
|
||||
|
||||
@@ -54,9 +54,6 @@ export function transformText(input: string): TransformTextResult {
|
||||
// 替换连字符为 '|' (如有多个则合并)
|
||||
match = match.replace(/[-_ ]+/g, '|');
|
||||
|
||||
// // 替换.时跳过连续点(例如Happy.. angry)
|
||||
// match = match.replace(/([^.])([.])([^.])/g, '$1|$3');
|
||||
|
||||
// 拆分连续的小写字母和大写字母为多个单词
|
||||
match = match.replace(/([a-z])([A-Z])/g, '$1|$2');
|
||||
|
@@ -1,11 +1,3 @@
|
||||
/**
|
||||
* 比较两个字符串数组 `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;
|
||||
@@ -20,15 +12,6 @@ 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[]> = [];
|
||||
@@ -41,4 +24,4 @@ export function stringListArrayDuplicateRemoval(stringArr: Array<string[]>): Arr
|
||||
}
|
||||
}
|
||||
return newArr;
|
||||
}
|
||||
}
|
@@ -3,16 +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 { variableConvertTestGroups } from './test-case/variable-convert-test-case';
|
||||
import { pathConvertTestGroups } from './test-case/path-convert-test-case';
|
||||
import { VariableTestCase, VariableTestCaseGroup } from './test-case/types/VariableTestCaseType';
|
||||
import { PathTestCase, PathTestCaseGroup } from './test-case/types/PathTestCaseType';
|
||||
import { transformMutliLineText, transformText } from '../utils/transform';
|
||||
import { caseConversion } from '../core/variable-convert/conversion';
|
||||
import { pathConversion } from '../core/path-convert/conversion';
|
||||
import { SupportVariableCase } from '../core/variable-convert/types/SupportVariableCaseType';
|
||||
import { SupportPathFormat } from '../core/path-convert/types/SupportPathFormatType';
|
||||
import { TransformTextResult } from '../types/TransformTextResultType';
|
||||
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 * as myExtension from '../../extension';
|
||||
|
||||
/*
|
||||
@@ -26,18 +22,13 @@ suite('Extension Test Suite', () => {
|
||||
});
|
||||
*/
|
||||
|
||||
/**
|
||||
* 变量转换 测试函数
|
||||
*
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
suite('Extension Test: run variable convert test case', () => {
|
||||
vscode.window.showInformationMessage('Start all tests for variable conversion.');
|
||||
suite('Extension Test: run test case', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
const groups: Array<VariableTestCaseGroup> = variableConvertTestGroups;
|
||||
const groups: Array<TestCaseGroup> = testGroups;
|
||||
for (const testGroup of groups) {
|
||||
const testTitle = testGroup.testTitle;
|
||||
const testCases: Array<VariableTestCase> = testGroup.cases;
|
||||
const testCases: Array<TestCase> = testGroup.cases;
|
||||
for (const testCase of testCases) {
|
||||
// // 临时
|
||||
// if (testCase.title !== '') {
|
||||
@@ -57,35 +48,30 @@ suite('Extension Test: run variable convert test case', () => {
|
||||
assert.strictEqual(correctValue, currentValue);
|
||||
}
|
||||
// 验证转换
|
||||
for (const eol of eolList) {
|
||||
assert.strictEqual(testCase.output.camelCase, caseConversion(SupportVariableCase.CAMEL_CASE, input, eol), 'camel case test failed.');
|
||||
assert.strictEqual(testCase.output.pascalCase, caseConversion(SupportVariableCase.PASCAL_CASE, input, eol), 'pascal case test failed.');
|
||||
for (let eol of eolList) {
|
||||
assert.strictEqual(testCase.output.camelCase, caseConversion(SupportCase.CAMEL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.pascalCase, caseConversion(SupportCase.PASCAL_CASE, input, eol));
|
||||
|
||||
assert.strictEqual(testCase.output.snakeCase, caseConversion(SupportVariableCase.SNAKE_CASE, input, eol), 'snake case test failed.');
|
||||
assert.strictEqual(testCase.output.snakeCamelCase, caseConversion(SupportVariableCase.SNAKE_CAMEL_CASE, input, eol), 'snake camel case test failed.');
|
||||
assert.strictEqual(testCase.output.snakePascalCase, caseConversion(SupportVariableCase.SNAKE_PASCAL_CASE, input, eol), 'snake pascal case test failed.');
|
||||
assert.strictEqual(testCase.output.snakeUpperCase, caseConversion(SupportVariableCase.SNAKE_UPPER_CASE, input, eol), 'snake upper case test failed.');
|
||||
|
||||
assert.strictEqual(testCase.output.kebabCase, caseConversion(SupportVariableCase.KEBAB_CASE, input, eol), 'kebab case test failed.');
|
||||
assert.strictEqual(testCase.output.kebabCamelCase, caseConversion(SupportVariableCase.KEBAB_CAMEL_CASE, input, eol), 'kebab camel case test failed.');
|
||||
assert.strictEqual(testCase.output.kebabPascalCase, caseConversion(SupportVariableCase.KEBAB_PASCAL_CASE, input, eol), 'kebab pascal case test failed.');
|
||||
assert.strictEqual(testCase.output.kebabUpperCase, caseConversion(SupportVariableCase.KEBAB_UPPER_CASE, input, eol), 'kebab upper case test failed.');
|
||||
|
||||
assert.strictEqual(testCase.output.spaceCase, caseConversion(SupportVariableCase.SPACE_CASE, input, eol), 'space case test failed.');
|
||||
assert.strictEqual(testCase.output.spaceCamelCase, caseConversion(SupportVariableCase.SPACE_CAMEL_CASE, input, eol), 'space camel case test failed.');
|
||||
assert.strictEqual(testCase.output.spacePascalCase, caseConversion(SupportVariableCase.SPACE_PASCAL_CASE, input, eol), 'space pascal case test failed.');
|
||||
assert.strictEqual(testCase.output.spaceUpperCase, caseConversion(SupportVariableCase.SPACE_UPPER_CASE, input, eol), 'space upper case test failed.');
|
||||
|
||||
assert.strictEqual(testCase.output.dotCase, caseConversion(SupportVariableCase.DOT_CASE, input, eol), 'dot case test failed.');
|
||||
assert.strictEqual(testCase.output.dotCamelCase, caseConversion(SupportVariableCase.DOT_CAMEL_CASE, input, eol), 'dot camel case test failed.');
|
||||
assert.strictEqual(testCase.output.dotPascalCase, caseConversion(SupportVariableCase.DOT_PASCAL_CASE, input, eol), 'dot pascal case test failed.');
|
||||
assert.strictEqual(testCase.output.dotUpperCase, caseConversion(SupportVariableCase.DOT_UPPER_CASE, input, eol), 'dot upper case test failed.');
|
||||
assert.strictEqual(testCase.output.snakeCase, caseConversion(SupportCase.SNAKE_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.snakeCamelCase, caseConversion(SupportCase.SNAKE_CAMEL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.snakePascalCase, caseConversion(SupportCase.SNAKE_PASCAL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.snakeUpperCase, caseConversion(SupportCase.SNAKE_UPPER_CASE, input, eol));
|
||||
|
||||
assert.strictEqual(testCase.output.kebabCase, caseConversion(SupportCase.KEBAB_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.kebabCamelCase, caseConversion(SupportCase.KEBAB_CAMEL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.kebabPascalCase, caseConversion(SupportCase.KEBAB_PASCAL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.kebabUpperCase, caseConversion(SupportCase.KEBAB_UPPER_CASE, input, eol));
|
||||
|
||||
assert.strictEqual(testCase.output.spaceCase, caseConversion(SupportCase.SPACE_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.spaceCamelCase, caseConversion(SupportCase.SPACE_CAMEL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.spacePascalCase, caseConversion(SupportCase.SPACE_PASCAL_CASE, input, eol));
|
||||
assert.strictEqual(testCase.output.spaceUpperCase, caseConversion(SupportCase.SPACE_UPPER_CASE, input, eol));
|
||||
|
||||
if (testCase.output.lowerCase !== undefined) {
|
||||
assert.strictEqual(testCase.output.lowerCase, caseConversion(SupportVariableCase.LOWER_CASE, input, eol), 'lower case test failed.');
|
||||
assert.strictEqual(testCase.output.lowerCase, caseConversion(SupportCase.LOWER_CASE, input, eol));
|
||||
}
|
||||
if (testCase.output.upperCase !== undefined) {
|
||||
assert.strictEqual(testCase.output.upperCase, caseConversion(SupportVariableCase.UPPER_CASE, input, eol), 'upper case test failed.');
|
||||
assert.strictEqual(testCase.output.upperCase, caseConversion(SupportCase.UPPER_CASE, input, eol));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,36 +79,3 @@ suite('Extension Test: run variable convert test case', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 路径转换 测试函数
|
||||
*
|
||||
* @since 2024-12-07
|
||||
*/
|
||||
suite('Extension Test: run path convert test case', () => {
|
||||
vscode.window.showInformationMessage('Start all tests for path conversion.');
|
||||
|
||||
const groups: Array<PathTestCaseGroup> = pathConvertTestGroups;
|
||||
for (const testGroup of groups) {
|
||||
const testTitle = testGroup.testTitle;
|
||||
const testCases: Array<PathTestCase> = testGroup.cases;
|
||||
for (const testCase of testCases) {
|
||||
// // 临时
|
||||
// if (testCase.title !== '') {
|
||||
// continue;
|
||||
// }
|
||||
test(testTitle + ' - ' + testCase.title, () => {
|
||||
const inputList = Array.isArray(testCase.input) ? testCase.input : [testCase.input];
|
||||
const eolList = Array.isArray(testCase.eol) ? testCase.eol : [testCase.eol];
|
||||
for (const input of inputList) {
|
||||
// console.log('input', '->' + input + '<-');
|
||||
// 验证转换
|
||||
for (const eol of eolList) {
|
||||
assert.strictEqual(testCase.output.Windows.unEscape, pathConversion(SupportPathFormat.Windows, input, eol), 'Windows path format test failed.');
|
||||
assert.strictEqual(testCase.output.Unix.unEscape, pathConversion(SupportPathFormat.Unix, input, eol), 'Unix path format test failed.');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,108 +0,0 @@
|
||||
import { PathTestCaseGroup } from "./types/PathTestCaseType";
|
||||
|
||||
const LF = '\n';
|
||||
const CRLF = '\r\n';
|
||||
|
||||
export const pathConvertTestGroups: Array<PathTestCaseGroup> = [
|
||||
{
|
||||
group: 'Normal Path Format Convert',
|
||||
testTitle: 'Normal Path Format Convert (常规路径风格转换)',
|
||||
cases: [
|
||||
{
|
||||
title: 'Windows 风格',
|
||||
input: // E:\Project\variable-conversion-vscode-extension
|
||||
'E:\\Project\\variable-conversion-vscode-extension',
|
||||
eol: [LF, CRLF],
|
||||
output: {
|
||||
Windows: {
|
||||
unEscape: // E:\Project\variable-conversion-vscode-extension
|
||||
'E:\\Project\\variable-conversion-vscode-extension',
|
||||
|
||||
escape: // E:\\Project\\variable-conversion-vscode-extension
|
||||
'E:\\\\Project\\\\variable-conversion-vscode-extension',
|
||||
},
|
||||
Unix: {
|
||||
unEscape:
|
||||
'E:/Project/variable-conversion-vscode-extension',
|
||||
escape: // E:\/Project\/variable-conversion-vscode-extension
|
||||
'E:\\/Project\\/variable-conversion-vscode-extension',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Unix 风格',
|
||||
input: '/home/user/file.txt',
|
||||
eol: [LF, CRLF],
|
||||
output: {
|
||||
Windows: {
|
||||
unEscape: // \home\user\file.txt
|
||||
'\\home\\user\\file.txt',
|
||||
escape: // \\home\\user\\file.txt
|
||||
'\\\\home\\\\user\\\\file.txt',
|
||||
},
|
||||
Unix: {
|
||||
unEscape:
|
||||
'/home/user/file.txt',
|
||||
escape: // \/home\/user\/file.txt
|
||||
'\\/home\\/user\\/file.txt',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Windows (Git Bash) 风格',
|
||||
input: '/c/Users/test/file.txt',
|
||||
eol: [LF, CRLF],
|
||||
output: {
|
||||
Windows: {
|
||||
unEscape: // \c\Users\test/file.txt
|
||||
'\\c\\Users\\test\\file.txt',
|
||||
escape: // \\c\\Users\\test\\file.txt
|
||||
'\\\\c\\\\Users\\\\test\\\\file.txt',
|
||||
// TODO need to transform to ↓
|
||||
/*
|
||||
unEscape: // C:\Users\test\file.txt
|
||||
'C:\\Users\\test\\file.txt',
|
||||
escape: // C:\\Users\\test\\file.txt
|
||||
'C:\\\\Users\\\\test\\\\file.txt',
|
||||
*/
|
||||
},
|
||||
Unix: {
|
||||
unEscape:
|
||||
'/c/Users/test/file.txt',
|
||||
escape: // \/c\/Users\/test\/file.txt
|
||||
'\\/c\\/Users\\/test\\/file.txt',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// TODO
|
||||
// Windows 局域网主机名风格
|
||||
// \\ComputerName
|
||||
// 路径带空格
|
||||
// /home/user/hello world.txt
|
||||
// /home/user/hello world.txt
|
||||
// and more ...
|
||||
|
||||
// {
|
||||
// title: '',
|
||||
// input: //
|
||||
// '',
|
||||
// eol: [LF, CRLF],
|
||||
// output: {
|
||||
// Windows: {
|
||||
// unEscape: //
|
||||
// '',
|
||||
// escape: //
|
||||
// '',
|
||||
// },
|
||||
// Unix: {
|
||||
// unEscape: //
|
||||
// '',
|
||||
// escape: //
|
||||
// '',
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
],
|
||||
},
|
||||
];
|
@@ -1,22 +0,0 @@
|
||||
import { EOL } from "../../../types/EOLType";
|
||||
|
||||
export type PathTestCaseGroup = {
|
||||
group: string
|
||||
testTitle: string
|
||||
cases: Array<PathTestCase>
|
||||
};
|
||||
|
||||
export type PathTestOutputResult = {
|
||||
unEscape: string;
|
||||
escape: string;
|
||||
};
|
||||
|
||||
export type PathTestCase = {
|
||||
title: string
|
||||
input: string | Array<string>
|
||||
eol: EOL | Array<EOL>
|
||||
output: {
|
||||
Windows: PathTestOutputResult
|
||||
Unix: PathTestOutputResult
|
||||
}
|
||||
};
|
389
src/type-definition/SupportCaseType.ts
Normal file
@@ -0,0 +1,389 @@
|
||||
/**
|
||||
* When support a new case, there's something we need to do.
|
||||
*
|
||||
* Code:
|
||||
* - Add type definition in below `SupportCase` enum and following array
|
||||
* - Add `commands`, `menus` parts in [package.json] and [package-comment.jsonc]
|
||||
* - Add main conversion logic in [src/main-code/conversion.ts]
|
||||
*
|
||||
* Test:
|
||||
* - Add test case type definition in [src/type-definition/TestCaseType.ts]
|
||||
* - Add test case in [src/test/test-case.ts]
|
||||
* - Add test code in [src/test/extension.test.ts]
|
||||
*
|
||||
* Docs:
|
||||
* - Modify `description` in [package.json] and [package-comment.jsonc]
|
||||
* - Add changes in [CHANGELOG.md] and [README.md]
|
||||
*/
|
||||
export enum SupportCase {
|
||||
|
||||
/**
|
||||
* 小驼峰(驼峰)命名
|
||||
* Camel Case
|
||||
* e.g. fooBar
|
||||
*
|
||||
* @alias: camelCase / CamelCase / camel case / camel_case / CAMEL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 大驼峰(帕斯卡)命名
|
||||
* Pascal Case
|
||||
* e.g. FooBar
|
||||
*
|
||||
* @alias: pascalCase / PascalCase / pascal case / pascal_case / PASCAL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形)命名
|
||||
* Snake Case
|
||||
* e.g. foo_bar
|
||||
*
|
||||
* @alias: snakeCase / SnakeCase / snake case / snake_case / SNAKE_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形) + 小驼峰(驼峰)命名
|
||||
* Snake Camel Case
|
||||
* e.g. foo_Bar
|
||||
*
|
||||
* @alias: snakeCamelCase / SnakeCamelCase / snake camel case / snake_camel_case / SNAKE_CAMEL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形) + 大驼峰(帕斯卡)命名
|
||||
* Snake Pascal Case
|
||||
* e.g. Foo_Bar
|
||||
*
|
||||
* @alias: snakePascalCase / SnakePascalCase / snake pascal case / snake_pascal_case / SNAKE_PASCAL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 下划线(蛇形) + 全大写命名
|
||||
* Snake Upper Case
|
||||
* e.g. FOO_BAR
|
||||
*
|
||||
* @alias: snakeUpperCase / SnakeUpperCase / snake upper case / snake_upper_case / SNAKE_UPPER_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
SNAKE_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式)命名
|
||||
* Kebab Case / Spinal Case
|
||||
* e.g. foo-bar
|
||||
*
|
||||
* @alias: kebabCase / KebabCase / kebab case / kebab_case / KEBAB_CASE
|
||||
* spinalCase / SpinalCase / spinal case / spinal_case / SPINAL_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
KEBAB_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式) + 小驼峰(驼峰)命名
|
||||
* Kebab Camel Case
|
||||
* e.g. foo-Bar
|
||||
*
|
||||
* @alias: kebabCamelCase / KebabCamelCase / kebab camel case / kebab_camel_case / KEBAB_CAMEL_CASE
|
||||
* @since 2024-04-03
|
||||
*/
|
||||
KEBAB_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名
|
||||
* Kebab Pascal Case
|
||||
* e.g. Foo-Bar
|
||||
*
|
||||
* @alias: kebabPascalCase / KebabPascalCase / kebab pascal case / kebab_pascal_case / KEBAB_PASCAL_CASE
|
||||
* @since 2024-04-03
|
||||
*/
|
||||
KEBAB_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 中划线(连字符/脊柱式) + 全大写命名
|
||||
* Kebab Upper Case
|
||||
* e.g. FOO-BAR
|
||||
*
|
||||
* @alias: kebabUpperCase / KebabUpperCase / kebab upper case / kebab_upper_case / KEBAB_UPPER_CASE
|
||||
* @since 2024-04-03
|
||||
*/
|
||||
KEBAB_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔命名
|
||||
* Space Case / Spinal Case
|
||||
* e.g. foo bar
|
||||
*
|
||||
* @alias: spaceCase / SpaceCase / space case / space_case / SPACE_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔 + 小驼峰(驼峰)命名
|
||||
* Space Camel Case
|
||||
* e.g. foo Bar
|
||||
*
|
||||
* @alias: spaceCamelCase / SpaceCamelCase / space camel case / space_camel_case / SPACE_CAMEL_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_CAMEL_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔 + 大驼峰(帕斯卡)命名
|
||||
* Space Pascal Case
|
||||
* e.g. Foo Bar
|
||||
*
|
||||
* @alias: spacePascalCase / SpacePascalCase / space pascal case / space_pascal_case / SPACE_PASCAL_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_PASCAL_CASE,
|
||||
|
||||
/**
|
||||
* 空格分隔 + 全大写命名
|
||||
* Space Upper Case
|
||||
* e.g. FOO BAR
|
||||
*
|
||||
* @alias: spaceUpperCase / SpaceUpperCase / space upper case / space_upper_case / SPACE_UPPER_CASE
|
||||
* @since 2024-04-07
|
||||
*/
|
||||
SPACE_UPPER_CASE,
|
||||
|
||||
/**
|
||||
* 全小写
|
||||
* Lower Case
|
||||
* e.g. foo_bar / foobar
|
||||
*
|
||||
* @alias: lowerCase / LowerCase / lower case / lower_case / LOWER_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
LOWER_CASE,
|
||||
|
||||
/**
|
||||
* 全大写
|
||||
* Upper Case
|
||||
* e.g. FOO_BAR / FOOBAR
|
||||
*
|
||||
* @alias: upperCase / UpperCase / upper case / upper_case / UPPER_CASE
|
||||
* @since 2024-04-02
|
||||
*/
|
||||
UPPER_CASE,
|
||||
}
|
||||
|
||||
const keyword = {
|
||||
camel: [
|
||||
'小驼峰', '驼峰',
|
||||
'Camel Case',
|
||||
'cc',
|
||||
'XiaoTuoFeng', 'TuoFeng',
|
||||
'xtf', 'tf',
|
||||
],
|
||||
pascal: [
|
||||
'大驼峰', '帕斯卡',
|
||||
'Pascal Case',
|
||||
'pc',
|
||||
'DaTuoFeng', 'PaSiKa',
|
||||
'dtf', 'psk',
|
||||
],
|
||||
snake: [
|
||||
'下划线', '蛇形', '_',
|
||||
'Snake Case', 'Underline Case',
|
||||
'sc', 'uc',
|
||||
'XiaHuaXian', 'SheXing',
|
||||
'xhx', 'sx',
|
||||
],
|
||||
kebab: [
|
||||
'连字符', '脊柱式', '-',
|
||||
'Kebab Case', 'Spinal Case',
|
||||
'kc', 'sc',
|
||||
'LianZiFu', 'JiZhuShi',
|
||||
'lzf', 'jzs',
|
||||
],
|
||||
space: [
|
||||
'空格', // ' ',
|
||||
'Space Case',
|
||||
'sc',
|
||||
'KongGe',
|
||||
'kg',
|
||||
],
|
||||
upper: [
|
||||
'全大写', '大写',
|
||||
'Upper Case',
|
||||
'uc',
|
||||
'QuanDaXie',
|
||||
'qdx',
|
||||
],
|
||||
lower: [
|
||||
'全小写', '小写',
|
||||
'Lower Case',
|
||||
'lc',
|
||||
'QuanXiaoXie',
|
||||
'qxx',
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* 接管的变量转换命令
|
||||
*/
|
||||
export const commands: Array<{ command: string; targetCase: SupportCase }> = [
|
||||
{ command: 'variable-conversion.toCamelCase', targetCase: SupportCase.CAMEL_CASE },
|
||||
{ command: 'variable-conversion.toPascalCase', targetCase: SupportCase.PASCAL_CASE },
|
||||
|
||||
{ command: 'variable-conversion.toSnakeCase', targetCase: SupportCase.SNAKE_CASE },
|
||||
{ command: 'variable-conversion.toSnakeUpperCase', targetCase: SupportCase.SNAKE_UPPER_CASE },
|
||||
{ command: 'variable-conversion.toSnakePascalCase', targetCase: SupportCase.SNAKE_PASCAL_CASE },
|
||||
{ command: 'variable-conversion.toSnakeCamelCase', targetCase: SupportCase.SNAKE_CAMEL_CASE },
|
||||
|
||||
{ command: 'variable-conversion.toKebabCase', targetCase: SupportCase.KEBAB_CASE },
|
||||
{ command: 'variable-conversion.toKebabUpperCase', targetCase: SupportCase.KEBAB_UPPER_CASE },
|
||||
{ command: 'variable-conversion.toKebabPascalCase', targetCase: SupportCase.KEBAB_PASCAL_CASE },
|
||||
{ command: 'variable-conversion.toKebabCamelCase', targetCase: SupportCase.KEBAB_CAMEL_CASE },
|
||||
|
||||
{ command: 'variable-conversion.toSpaceCase', targetCase: SupportCase.SPACE_CASE },
|
||||
{ command: 'variable-conversion.toSpaceUpperCase', targetCase: SupportCase.SPACE_UPPER_CASE },
|
||||
{ command: 'variable-conversion.toSpacePascalCase', targetCase: SupportCase.SPACE_PASCAL_CASE },
|
||||
{ command: 'variable-conversion.toSpaceCamelCase', targetCase: SupportCase.SPACE_CAMEL_CASE },
|
||||
|
||||
{ command: 'variable-conversion.toLowerCase', targetCase: SupportCase.LOWER_CASE },
|
||||
{ command: 'variable-conversion.toUpperCase', targetCase: SupportCase.UPPER_CASE },
|
||||
];
|
||||
|
||||
/**
|
||||
* 所有支持的命名方式
|
||||
* @since 2024-04-06
|
||||
*/
|
||||
export const quickPickSupportCases = [
|
||||
{
|
||||
type: SupportCase.CAMEL_CASE,
|
||||
name: '小驼峰(驼峰)命名',
|
||||
shortName: '小驼峰',
|
||||
keyword: keyword.camel,
|
||||
},
|
||||
{
|
||||
type: SupportCase.PASCAL_CASE,
|
||||
name: '大驼峰(帕斯卡)命名',
|
||||
shortName: '帕斯卡',
|
||||
keyword: keyword.pascal,
|
||||
},
|
||||
{
|
||||
type: SupportCase.SNAKE_CASE,
|
||||
name: '下划线(蛇形)命名',
|
||||
shortName: '蛇形',
|
||||
keyword: [...keyword.snake, ...keyword.lower],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SNAKE_CAMEL_CASE,
|
||||
name: '下划线(蛇形) + 小驼峰(驼峰)命名',
|
||||
shortName: '蛇形驼峰',
|
||||
keyword: [...keyword.snake, ...keyword.camel],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SNAKE_PASCAL_CASE,
|
||||
name: '下划线(蛇形) + 大驼峰(帕斯卡)命名',
|
||||
shortName: '蛇形帕斯卡',
|
||||
keyword: [...keyword.snake, ...keyword.pascal],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SNAKE_UPPER_CASE,
|
||||
name: '下划线(蛇形) + 全大写命名',
|
||||
shortName: '蛇形大写',
|
||||
keyword: [...keyword.snake, ...keyword.upper],
|
||||
},
|
||||
{
|
||||
type: SupportCase.KEBAB_CASE,
|
||||
name: '中划线(连字符/脊柱式)命名',
|
||||
shortName: '脊柱',
|
||||
keyword: [...keyword.kebab, ...keyword.lower],
|
||||
},
|
||||
{
|
||||
type: SupportCase.KEBAB_CAMEL_CASE,
|
||||
name: '中划线(连字符/脊柱式) + 小驼峰(驼峰)命名',
|
||||
shortName: '脊柱驼峰',
|
||||
keyword: [...keyword.kebab, ...keyword.camel],
|
||||
},
|
||||
{
|
||||
type: SupportCase.KEBAB_PASCAL_CASE,
|
||||
name: '中划线(连字符/脊柱式) + 大驼峰(帕斯卡)命名',
|
||||
shortName: '脊柱帕斯卡',
|
||||
keyword: [...keyword.kebab, ...keyword.pascal],
|
||||
},
|
||||
{
|
||||
type: SupportCase.KEBAB_UPPER_CASE,
|
||||
name: '中划线(连字符/脊柱式) + 全大写命名',
|
||||
shortName: '脊柱大写',
|
||||
keyword: [...keyword.kebab, ...keyword.upper],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SPACE_CASE,
|
||||
name: '空格分隔命名',
|
||||
shortName: '脊柱',
|
||||
keyword: [...keyword.space, ...keyword.lower],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SPACE_CAMEL_CASE,
|
||||
name: '空格分隔 + 小驼峰(驼峰)命名',
|
||||
shortName: '脊柱驼峰',
|
||||
keyword: [...keyword.space, ...keyword.camel],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SPACE_PASCAL_CASE,
|
||||
name: '空格分隔 + 大驼峰(帕斯卡)命名',
|
||||
shortName: '脊柱帕斯卡',
|
||||
keyword: [...keyword.space, ...keyword.pascal],
|
||||
},
|
||||
{
|
||||
type: SupportCase.SPACE_UPPER_CASE,
|
||||
name: '空格分隔 + 全大写命名',
|
||||
shortName: '脊柱大写',
|
||||
keyword: [...keyword.space, ...keyword.upper],
|
||||
},
|
||||
{
|
||||
type: SupportCase.LOWER_CASE,
|
||||
name: '全小写',
|
||||
shortName: '小写',
|
||||
keyword: keyword.lower,
|
||||
},
|
||||
{
|
||||
type: SupportCase.UPPER_CASE,
|
||||
name: '全大写',
|
||||
shortName: '大写',
|
||||
keyword: keyword.upper,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 通过快捷键循环转换的顺序
|
||||
* @since 2024-04-08
|
||||
*/
|
||||
export const cyclicConvertCaseOrder = [
|
||||
SupportCase.CAMEL_CASE,
|
||||
SupportCase.PASCAL_CASE,
|
||||
|
||||
SupportCase.SNAKE_CASE,
|
||||
SupportCase.KEBAB_CASE,
|
||||
SupportCase.SPACE_CASE,
|
||||
|
||||
SupportCase.SNAKE_UPPER_CASE,
|
||||
SupportCase.KEBAB_UPPER_CASE,
|
||||
SupportCase.SPACE_UPPER_CASE,
|
||||
|
||||
SupportCase.SNAKE_PASCAL_CASE,
|
||||
SupportCase.KEBAB_PASCAL_CASE,
|
||||
SupportCase.SPACE_PASCAL_CASE,
|
||||
|
||||
SupportCase.SNAKE_CAMEL_CASE,
|
||||
SupportCase.KEBAB_CAMEL_CASE,
|
||||
SupportCase.SPACE_CAMEL_CASE,
|
||||
|
||||
SupportCase.LOWER_CASE,
|
||||
SupportCase.UPPER_CASE,
|
||||
];
|
@@ -1,12 +1,12 @@
|
||||
import { EOL } from "../../../types/EOLType";
|
||||
import { EOL } from "./EOLType";
|
||||
|
||||
export type VariableTestCaseGroup = {
|
||||
export type TestCaseGroup = {
|
||||
group: string
|
||||
testTitle: string
|
||||
cases: Array<VariableTestCase>
|
||||
cases: Array<TestCase>
|
||||
};
|
||||
|
||||
export type VariableTestCase = {
|
||||
export type TestCase = {
|
||||
title: string
|
||||
input: string | Array<string>
|
||||
eol: EOL | Array<EOL>
|
||||
@@ -30,11 +30,6 @@ export type VariableTestCase = {
|
||||
spacePascalCase: string
|
||||
spaceUpperCase: string
|
||||
|
||||
dotCase: string
|
||||
dotCamelCase: string
|
||||
dotPascalCase: string
|
||||
dotUpperCase: string
|
||||
|
||||
lowerCase?: string
|
||||
upperCase?: string
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
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
|
||||
};
|
24
test-code.md
@@ -1,24 +0,0 @@
|
||||
```javascript
|
||||
// 小驼峰
|
||||
const helloWorld = ''
|
||||
// 大驼峰
|
||||
const HelloWorld = ''
|
||||
// 下划线 + 首字母大写
|
||||
const Hello_World = ''
|
||||
// 下划线 + 全小写
|
||||
const hello_world = ''
|
||||
// 下划线 + 全大写
|
||||
const HELLO_WORLD = ''
|
||||
// 小写
|
||||
const helloworld = ''
|
||||
// 大写
|
||||
const HELLOWORLD = ''
|
||||
// 加空格
|
||||
const a = 'hello world'
|
||||
```
|
||||
|
||||
```
|
||||
D:\Project\variable-conversion-vscode-extension\README.md
|
||||
D:\\Project\\variable-conversion-vscode-extension\\README.md
|
||||
D:/Project/variable-conversion-vscode-extension/README.md
|
||||
```
|
@@ -8,7 +8,7 @@
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true, /* enable all strict type-checking options */
|
||||
"strict": true /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|