diff --git a/CHANGELOG.md b/CHANGELOG.md index dff5804..fe0514b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,29 @@ All notable changes to the "text-conversion" extension will be documented in thi Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +All notable changes to this extension will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + ## [Unreleased] +### Added + + +### Changed + + +### Removed + + + +## 1.0.0 + +### Added + +- Adds an editor context menu with submenu +- Implement conversion to Camel Case, Pascal Case, Upper Case, Lower Case +- Add test cases - Initial release \ No newline at end of file diff --git a/GPT.md b/GPT.md index 73ed8eb..30d6b81 100644 --- a/GPT.md +++ b/GPT.md @@ -198,3 +198,78 @@ vsce package (4) vscode插件打包流程 - 知乎 - 知乎专栏. https://zhuanlan.zhihu.com/p/643962235. (5) VSCode打包插件及安装vsix包方法 - 马克队长 - 博客园. https://bing.com/search?q=%e5%a6%82%e4%bd%95%e6%89%93%e5%8c%85VSCode%e6%8f%92%e4%bb%b6. +========== + +谢谢你,那么打包完毕后,如何上架到VSCode插件市场呢 + +将 VSCode 插件发布到插件市场需要以下几个步骤¹²³: + +1. **准备工作**:确保你已经安装了 Node.js 和 npm。 + +2. **安装 VS Code Extension CLI 工具**:运行以下命令来安装 `vsce`,这是一个用于打包和发布 VSCode 插件的命令行工具: +```bash +npm install -g vsce +``` + +3. **创建一个 Microsoft 账户并获取发布者身份**:访问 Visual Studio Marketplace 并创建一个发布者身份。 + +4. **准备你的插件代码**:确保你的 `package.json` 文件中有所有必要的字段(例如,`name`,`version`,`description`等)。 + +5. **打包插件**:在插件的根目录中运行以下命令来打包插件: +```bash +vsce package +``` +这将生成一个 `.vsix` 文件,这就是你的插件的安装包。 + +6. **发布插件**:首次发布前,运行以下命令来创建一个发布者: +```bash +vsce create-publisher [publisher name] +``` +然后运行以下命令来发布插件: +```bash +vsce publish +``` +这个过程中,`vsce` 会检查 `package.json` 的一些必填项。如果一切无误,你的插件就会被成功发布到插件市场。 + +7. **更新插件**:当你需要更新插件时,修改 `package.json` 中的版本号,然后重新运行 `vsce package` 和 `vsce publish`。 + +8. **管理插件**:你可以在 Visual Studio Marketplace 管理界面中管理你的插件。 + +以上就是将 VSCode 插件发布到插件市场的基本流程。希望这个答案对你有所帮助! + +源: 与必应的对话, 2024/4/3 +(1) 如何发行你的插件 | 跟我学 VSCode 插件开发 - 知乎. https://zhuanlan.zhihu.com/p/339695661. +(2) 如何将插件发布到vs code插件市场_vscode插件市场-CSDN博客. https://blog.csdn.net/m0_57236802/article/details/132755535. +(3) 如何将插件发布到vs code插件市场_vscode插件市场-CSDN博客. https://bing.com/search?q=%e5%a6%82%e4%bd%95%e4%b8%8a%e6%9e%b6VSCode%e6%8f%92%e4%bb%b6%e5%88%b0%e6%8f%92%e4%bb%b6%e5%b8%82%e5%9c%ba. +(4) visual-studio-code - VScode技巧 | 如何开发一个插件 - 个人文章 - SegmentFault 思否. https://segmentfault.com/a/1190000043764128. + +========== + +如何配置VSCode插件logo + +在Visual Studio Code中创建插件时,你可以为你的插件设置一个图标,这个图标会在VS Code的插件市场和插件侧边栏中显示。以下是设置插件图标的步骤²: + +1. **准备图标文件**:准备一个你想用作插件图标的图片文件。确保这个文件是一个PNG或者JPEG格式,并且推荐至少为128x128像素的分辨率²。 +2. **添加图标到你的插件项目中**:将图标文件放入你的插件项目的某个目录中,通常是项目的根目录²。 +3. **在 package.json 中指定图标路径**:在你的插件项目的 package.json 文件中,使用 icon 字段来指定图标文件的路径。路径是相对于 package.json 文件的。例如²: +```json +{ + "name": "your-extension-name", + "displayName": "Your Extension", + "description": "Your extension description", + "version": "0.0.1", + "publisher": "your-publisher-name", + "icon": "images/your-icon.png", // 其他字段... +} +``` +在这个例子中,假设你的图标文件名为 your-icon.png ,并且它位于项目根目录下的 images 文件夹中²。 +4. **发布或更新你的插件**:当你发布或更新你的插件到VS Code插件市场时, package.json 文件中的 icon 字段会被用来显示你的插件图标。 确保在发布或更新插件之前测试图标显示是否正确。 你可以通过在本地VS Code中加载你的插件来预览图标。 如果一切看起来都好,你就可以按照VS Code插件发布的正常流程来发布你的插件了²。 + +源: 与必应的对话, 2024/4/3 +(1) 【vscode插件】之插件图标设置 - CSDN博客. https://blog.csdn.net/liyananweb/article/details/135181787. +(2) vscode-更换图标主题VSCode Icons._vscode更改不了icon-CSDN博客. https://bing.com/search?q=%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aeVSCode%e6%8f%92%e4%bb%b6logo. +(3) 让你的 VSCode 文件图标更好看的10个文件 ... - 掘金. https://juejin.cn/post/7247569496696389691. +(4) vscode-更换图标主题VSCode Icons._vscode更改不了icon-CSDN博客. https://blog.csdn.net/xiaomizhou66a/article/details/81260347. +(5) 【VSCode插件】之插件图标设置 - 掘金. https://juejin.cn/post/7315373969833754624. + + diff --git a/package-comment.jsonc b/package-comment.jsonc new file mode 100644 index 0000000..70eab1f --- /dev/null +++ b/package-comment.jsonc @@ -0,0 +1,208 @@ +{ + // 插件 id 及名称 + "name": "variable-conversion", + "displayName": "Variable Conversion", + "description": "", + // 版本号 + "version": "0.0.1", + "engines": { + "vscode": "^1.87.0" + }, + "categories": [ + "Other" + ], + // 仓库地址 + "repository": { + "type": "git", + "url": "https://github.com/coder-xiaomo/text-conversion-vscode-extension.git" + }, + "main": "./out/extension.js", + "activationEvents": [], + "contributes": { + "commands": [ + // { + // "command": "extension.convertCase", + // "title": "字符串转换" + // }, + { + "command": "extension.toCamelCase", + "title": "小驼峰 / 驼峰命名 (Camel Case) [ fooBar ]" + }, + { + "command": "extension.toPascalCase", + "title": "大驼峰 / 帕斯卡命名 (Pascal Case) [ FooBar ]" + }, + { + "command": "extension.toKebabCase", + "title": "连字符 / 脊柱式命名 (Kebab Case / Spinal Case) [ foo-bar ]" + }, + { + "command": "extension.toSnakeCase", + "title": "下划线 / 蛇形命名 (Snake Case) [ foo_bar ]" + }, + { + "command": "extension.toSnakeUpperCase", + "title": "下划线大写 (Snake Upper Case) [ FOO_BAR ]" + }, + { + "command": "extension.toUpperCase", + "title": "全大写 (Upper Case) [ FOOBAR ]" + }, + { + "command": "extension.toLowerCase", + "title": "全小写 (Lower Case) [ foobar ]" + }, + { + "command": "extension.toCamelSnakeCase", + "title": "驼峰蛇形命名 (Camel Snake Case) [ Foo_Bar ]" + } + // 隐藏命令 + // { + // "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" + // } + ], + "keybindings": [ + // 绑定快捷键 + { + "command": "extension.convertCase", + "key": "shift+alt+t", + "when": "editorTextFocus" + } + ], + // docs: https://code.visualstudio.com/api/references/contribution-points#contributes.menus + "menus": { + // 编辑器右键菜单 + "editor/context": [ + // { + // "when": "editorTextFocus", + // "command": "extension.convertCase", + // "group": "1_modification@9" + // }, + { + "submenu": "extension.stringConversionMenu", + // docs: https://code.visualstudio.com/api/references/contribution-points#Sorting-of-groups + // "group": "1_modification@9" + "group": "navigation@9" + } + ], + "extension.stringConversionMenu": [ + { + "command": "extension.toCamelCase", + "group": "group-extension" + }, + { + "command": "extension.toPascalCase", + "group": "group-extension" + }, + { + "command": "extension.toKebabCase", + "group": "group-extension" + }, + { + "command": "extension.toSnakeCase", + "group": "group-extension" + }, + { + "command": "extension.toSnakeUpperCase", + "group": "group-extension" + }, + { + "command": "extension.toUpperCase", + "group": "group-extension" + }, + { + "command": "extension.toLowerCase", + "group": "group-extension" + }, + { + "command": "extension.toCamelSnakeCase", + "group": "group-extension" + }, + // { + // "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" + // } + ] + }, + // docs: https://code.visualstudio.com/api/references/contribution-points#contributes.submenus + "submenus": [ + { + "id": "extension.stringConversionMenu", + "label": "将字符串转换为..." + } + ] + }, + "scripts": { + "vscode:prepublish": "npm run compile", + "compile": "tsc -p ./", + "watch": "tsc -watch -p ./", + "pretest": "npm run compile && npm run lint", + "lint": "eslint src --ext ts", + "test": "vscode-test", + "package": "echo \"start `vsce package`\" & vsce package" + }, + "devDependencies": { + "@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" + } +} \ No newline at end of file diff --git a/package.json b/package.json index 83a7ff1..3f713ab 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,6 @@ "activationEvents": [], "contributes": { "commands": [ - { - "command": "extension.convertCase", - "title": "字符串转换" - }, { "command": "extension.toCamelCase", "title": "小驼峰 / 驼峰命名 (Camel Case) [ fooBar ]" @@ -52,30 +48,6 @@ { "command": "extension.toCamelSnakeCase", "title": "驼峰蛇形命名 (Camel Snake Case) [ Foo_Bar ]" - }, - { - "command": "editor.action.transformToCamelcase", - "title": "[VSCode 自带] 驼峰式大小写 (Camel Case) [ fooBar ]" - }, - { - "command": "editor.action.transformToKebabcase", - "title": "[VSCode 自带] Kebab 命名 (Kebab Case) [ foo-bar ]" - }, - { - "command": "editor.action.transformToTitlecase", - "title": "[VSCode 自带] 词首字母大写 (Title Case) [ Foo Bar ]" - }, - { - "command": "editor.action.transformToLowercase", - "title": "[VSCode 自带] 转换为小写 (Lower Case) [ foo bar ]" - }, - { - "command": "editor.action.transformToUppercase", - "title": "[VSCode 自带] 转换为大写 (Upper Case) [ FOO BAR ]" - }, - { - "command": "editor.action.transformToSnakecase", - "title": "[VSCode 自带] 转换为蛇形命名法 (Snake Case) [ foo_bar ]" } ], "keybindings": [ @@ -87,14 +59,9 @@ ], "menus": { "editor/context": [ - { - "when": "editorTextFocus", - "command": "extension.convertCase", - "group": "1_modification@9" - }, { "submenu": "extension.stringConversionMenu", - "group": "1_modification@9" + "group": "navigation@9" } ], "extension.stringConversionMenu": [ @@ -129,30 +96,6 @@ { "command": "extension.toCamelSnakeCase", "group": "group-extension" - }, - { - "command": "editor.action.transformToCamelcase", - "group": "group-vscode" - }, - { - "command": "editor.action.transformToKebabcase", - "group": "group-vscode" - }, - { - "command": "editor.action.transformToTitlecase", - "group": "group-vscode" - }, - { - "command": "editor.action.transformToLowercase", - "group": "group-vscode" - }, - { - "command": "editor.action.transformToUppercase", - "group": "group-vscode" - }, - { - "command": "editor.action.transformToSnakecase", - "group": "group-vscode" } ] }, diff --git a/src/test/test-text-split.js b/src/test/test-text-split.js deleted file mode 100644 index b4c1ae5..0000000 --- a/src/test/test-text-split.js +++ /dev/null @@ -1,120 +0,0 @@ -// 请帮我写一个 js 函数,实现如下功能:建议使用正则实现,难以实现的可以使用代码逻辑配合操作 -// 统一将所有单词转为小写,连字符转换为|便于后续操作 -// 具体转换逻辑: -// - 如果有多个连字符,将其合并为1个连字符,例如 ice-_-cream -> ice|cream -// - 如果连续小写字母存在大写字母,将其拆分为多个单词,例如 TomLikes eat iceCream. -> tom|likes|eat|ice|cream|. -// - 对于1个或连续多个除了A-Z a-z - _ 空格等的特殊字符,或表情符号等,不做处理,将其视为独立单词,例如 -// takeARest😊haPPy,😢triSTE,ENFADADO, 驚きました,❤️, 笑, 😎COol, 😳-Embarrassed -// -> take|a|rest|😊|ha|p|py|,😢|tri|s|t|e|,|enfadado|,| |驚きました,❤️,| |笑|,| |😎|c|ool|,| |😳|embarrassed - -// 注意,你不可以直接用toLowerCase,因为TomLikes eat iceCream. 这种情况下iceCream变成icecream就无法分词了 -// 另外,通过检查每个字母,如果它是大写的,我们就在它前面添加一个分隔符,然后再将整个字符串转换为小写,这样也有点问题,比如ENFADADO就会被分开。 -// 需要实现 takeARest-> take|a|rest , triSTE -> tri|s|t|e , ENFADADO -> enfadado , COol -> c|ool 或许按照单词首尾字母大小写判断可以解决这个问题? - -// 参考思路:只操作修改其中符合我们替换条件的部分,主要是中英文字母-_和空格,可以用正则匹配出来逐一进行操作后再回填回去,对于其他字符部分不做操作? - - -// 请将如下代码改写成 TypeScript 的格式,并移除 logDebugInfo 参数,需要保留注释内容 - -const logDebugInfo = false; - -function transformText(input) { - console.log(); - console.log('input ', '->' + input + '<-'); - - // 记录首尾空格 - const leadingSpaces = input.match(/^ +/); - const trailingSpaces = input.match(/ +$/); - - // 去除首尾空格 - input = input.trim(); - logDebugInfo && console.log('Trimmed input', input); - - // 使用正则表达式匹配中英文字母、连字符、下划线和空格 - let result = input.replace(/([A-Za-z\-_ ]+)/g, (match) => { - logDebugInfo && console.log('callback', match); - - // 替换连字符为 '|' (如有多个则合并) - match = match.replace(/[-_ ]+/g, '|'); - logDebugInfo && console.log('match', match); - - // 拆分连续的小写字母和大写字母为多个单词 - match = match.replace(/([a-z])([A-Z])/g, '$1|$2'); - logDebugInfo && console.log('match', match); - - // 分割 - let words = match.split('|'); - logDebugInfo && console.log('words', words); - - // 处理特殊情况,如 'ENFADADO' 不应该被拆分 - words = words.map(word => { - // if (word.toUpperCase() === word) { - // return word.toLowerCase(); - // } - // return word/*.replace(/([A-Z])/g, '|$1')*/.toLowerCase(); - if (word.toUpperCase() === word && word.length > 1) { - return word.toLowerCase(); - } - return word.replace(/([A-Z])/g, '|$1').toLowerCase(); - }); - logDebugInfo && console.log('words', words); - - // 重新组合单词 - return '|' + words.join('|') + '|'; - }); - logDebugInfo && console.log('result', result); - - // 如果有多个 | 将其合并 - result = result.replace(/[\|]+/g, '|'); - logDebugInfo && console.log('result', result); - - // 如果首尾有 | 将其替换掉 - result = result.replace(/(^[\|]+|[\|]+$)/g, ''); - logDebugInfo && console.log('result', result); - - // 还原首尾空格 - // result = (leadingSpaces ? (leadingSpaces[0] + '|') : '') + result + (trailingSpaces ? ('|' + trailingSpaces[0]) : ''); - result = (leadingSpaces ? leadingSpaces[0] : '') + result + (trailingSpaces ? trailingSpaces[0] : ''); - logDebugInfo && console.log('Final result', result); - - console.log('output ', '->' + result + '<-'); - return result; -} - -// 示例用法 -transformText(' ANiceDay!'); -transformText(' A----NiCe_Day_-_-- \''); -transformText('TomLikes eat iceCream.'); -transformText('takeARest😊haPPy,😢triSTE,ENFADADO, 驚きました,❤️, 笑, 😎COol, 😳-Embarrassed'); -transformText(' Julius_Caesar, William_Shakespeare, Albert_Einstein, Marie_Curie, WolfgangAmadeusMozart, Vincent-van-Gogh. '); -transformText(' 🥰 a-cup/_of Coffee🍻,-_please!. '); -transformText('--担心你dAf_=coffee—爸妈不在家_— '); -transformText(' NHDAs--+90-usz&* '); - -/* 输出: - -input -> ANiceDay!<- -output -> a|nice|day|!<- - -input -> A----NiCe_Day_-_-- '<- -output -> a|ni|ce|day|'<- - -input ->TomLikes eat iceCream.<- -output ->tom|likes|eat|ice|cream|.<- - -input ->takeARest😊haPPy,😢triSTE,ENFADADO, 驚きました,❤️, 笑, 😎COol, 😳-Embarrassed<- -output ->take|a|rest|😊|ha|p|py|,😢|tri|ste|,|enfadado|,|驚きました,❤️,|笑,|😎|c|ool|,|😳|embarrassed<- - -input -> Julius_Caesar, William_Shakespeare, Albert_Einstein, Marie_Curie, WolfgangAmadeusMozart, Vincent-van-Gogh. <- -output -> julius|caesar|,|william|shakespeare|,|albert|einstein|,|marie|curie|,|wolfgang|amadeus|mozart|,|vincent|van|gogh|. <- - -input -> 🥰 a-cup/_of Coffee🍻,-_please!. <- -output -> 🥰|a|cup|/|of|coffee|🍻,|please|!. <- - -input ->--担心你dAf_=coffee—爸妈不在家_— <- -output ->担心你|d|af|=|coffee|—爸妈不在家|— <- - -input -> NHDAs--+90-usz&* <- -output -> n|h|d|as|+90|usz|&* <- - -*/ \ No newline at end of file