mirror of
https://github.com/any86/any-rule.git
synced 2025-07-14 15:38:58 +08:00
Merge remote-tracking branch 'origin/develop'
* origin/develop: docs: 更新文档 chore: 删除语言配置功能 chore: 更新文档 0.3.0 0.3.0-beta chore: 更新日志 feat: 增加通过菜单唤醒列表 refactor: 修改文案 chore: 修改默认触发字符串为"@zz"
This commit is contained in:
commit
eee0c13d93
@ -1,6 +1,11 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
🚀 [提交问题](https://github.com/any86/any-rule/issues/new)
|
🚀 [提交问题](https://github.com/any86/any-rule/issues/new)
|
||||||
|
|
||||||
|
### 0.3.0 (2020-02-28)
|
||||||
|
- 修改"zz."触发为"@zz"触发.
|
||||||
|
- 增加右键唤醒正则菜单.
|
||||||
|

|
||||||
|
|
||||||
### 0.2.0 (2020-02-21)
|
### 0.2.0 (2020-02-21)
|
||||||
|
|
||||||
- 优化"zz."体验, 改用"quickPick"组件以支持"模糊搜索".
|
- 优化"zz."体验, 改用"quickPick"组件以支持"模糊搜索".
|
||||||
|
31
README.md
31
README.md
@ -11,29 +11,38 @@ vscode应用商店中搜索"**any-rule**".
|
|||||||
|
|
||||||
### 使用
|
### 使用
|
||||||
**方式1:**
|
**方式1:**
|
||||||
1. 安装完毕后按**F1**(或者ctrl+shift+p).
|
|
||||||
2. 输入"**zz**"弹出正则列表.
|
|
||||||
3. **输入关键词搜索**, 比如"手机".
|
|
||||||
|
|
||||||

|
1. 按**F1**(mac下fn+F1)打开正则列表.
|
||||||
|
2. **输入关键词搜索**, 比如"手机".
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
**方式2:**
|
**方式2:**
|
||||||
|
|
||||||
1. 在代码的任意位置输入"**zz.**"弹出正则列表.
|
右键选择"🦕正则大全".
|
||||||
2. **输入关键词搜索**, 比如"手机".
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 🦕图解正则
|
**方式3:**
|
||||||
在vscode中选择正则后, 可点击"🦕图解正则".
|
|
||||||
|
|
||||||

|
在代码任意位置输入"**@zz**".
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🤖图解正则
|
||||||
|
<details>
|
||||||
|
<summary>查看详情</summary>
|
||||||
|
在vscode中选择正则后, 可点击"🤖图解正则".
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
点击后可以看到正则解析, 方便大家学习.
|
点击后可以看到正则解析, 方便大家学习.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
**注意**: 图解直接使用了https://regexper.com, 在此对作者表示敬意和感谢.
|
**注意**: 图解直接使用了https://regexper.com, 在此对作者表示敬意和感谢.
|
||||||
|
</details>
|
||||||
|
|
||||||
## :fire:关于PR
|
## :fire:关于PR
|
||||||
欢迎大家PR, 步骤如下:
|
欢迎大家PR, 步骤如下:
|
||||||
|
24
package.json
24
package.json
@ -3,7 +3,7 @@
|
|||||||
"publisher": "russell",
|
"publisher": "russell",
|
||||||
"displayName": "any-rule",
|
"displayName": "any-rule",
|
||||||
"description": "你要的\"正则\"都在这!",
|
"description": "你要的\"正则\"都在这!",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:md": "node ./scripts/md.js",
|
"build:md": "node ./scripts/md.js",
|
||||||
"build": "npm run test:rules && npm version patch && node ./scripts/genCommond.js && vsce package && npm run build:md",
|
"build": "npm run test:rules && npm version patch && node ./scripts/genCommond.js && vsce package && npm run build:md",
|
||||||
@ -37,18 +37,22 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "any-rule",
|
"title": "any-rule",
|
||||||
"properties": {
|
"properties": {
|
||||||
"AnyRule.triggerString": {
|
"any-rule.triggerString": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "zz.",
|
"default": "@zz",
|
||||||
"description": "触发字符串"
|
"description": "触发字符串"
|
||||||
},
|
|
||||||
"AnyRule.supportedLanguages": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "*, javascript, typescript, javascriptreact, typescriptreact, markdown, jsx, vue, html, json, plaintext, coffeescript",
|
|
||||||
"description": "如果您的文件格式未被支持, 请在此处添加(⚡添加成功后需要重启vscode)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"menus": {
|
||||||
|
"editor/context": [
|
||||||
|
{
|
||||||
|
"when": "editorFocus",
|
||||||
|
"command": "extension.rule.callByMenu",
|
||||||
|
"group": "navigation"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "extension.rule0",
|
"command": "extension.rule0",
|
||||||
@ -293,6 +297,10 @@
|
|||||||
{
|
{
|
||||||
"command": "extension.rule60",
|
"command": "extension.rule60",
|
||||||
"title": "$(rocket) zz: java包名"
|
"title": "$(rocket) zz: java包名"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "extension.rule.callByMenu",
|
||||||
|
"title": "🦕正则大全(61条)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,11 @@ pkg.contributes.commands = RULES.map((rule, index) => ({
|
|||||||
title: `$(rocket) zz: ${rule.title}`
|
title: `$(rocket) zz: ${rule.title}`
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
pkg.contributes.commands.push({
|
||||||
|
command: 'extension.rule.callByMenu',
|
||||||
|
title: `🦕正则大全(${RULES.length}条)`
|
||||||
|
});
|
||||||
|
|
||||||
// console.log(JSON.stringify(pkg));
|
// console.log(JSON.stringify(pkg));
|
||||||
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 4), 'utf8');
|
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 4), 'utf8');
|
||||||
console.log(chalk.green('🚀 pkg文件修改完毕, 请等待生成vsc包...'));
|
console.log(chalk.green('🚀 pkg文件修改完毕, 请等待生成vsc包...'));
|
@ -35,29 +35,38 @@ vscode应用商店中搜索"**any-rule**".
|
|||||||
|
|
||||||
### 使用
|
### 使用
|
||||||
**方式1:**
|
**方式1:**
|
||||||
1. 安装完毕后按**F1**(或者ctrl+shift+p).
|
|
||||||
2. 输入"**zz**"弹出正则列表.
|
|
||||||
3. **输入关键词搜索**, 比如"手机".
|
|
||||||
|
|
||||||

|
1. 按**F1**(mac下fn+F1)打开正则列表.
|
||||||
|
2. **输入关键词搜索**, 比如"手机".
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
**方式2:**
|
**方式2:**
|
||||||
|
|
||||||
1. 在代码的任意位置输入"**zz.**"弹出正则列表.
|
右键选择"🦕正则大全".
|
||||||
2. **输入关键词搜索**, 比如"手机".
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 🦕图解正则
|
**方式3:**
|
||||||
在vscode中选择正则后, 可点击"🦕图解正则".
|
|
||||||
|
|
||||||

|
在代码任意位置输入"**@zz**".
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🤖图解正则
|
||||||
|
<details>
|
||||||
|
<summary>查看详情</summary>
|
||||||
|
在vscode中选择正则后, 可点击"🤖图解正则".
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
点击后可以看到正则解析, 方便大家学习.
|
点击后可以看到正则解析, 方便大家学习.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
**注意**: 图解直接使用了https://regexper.com, 在此对作者表示敬意和感谢.
|
**注意**: 图解直接使用了https://regexper.com, 在此对作者表示敬意和感谢.
|
||||||
|
</details>
|
||||||
|
|
||||||
## :fire:关于PR
|
## :fire:关于PR
|
||||||
欢迎大家PR, 步骤如下:
|
欢迎大家PR, 步骤如下:
|
||||||
|
@ -6,10 +6,12 @@ import {
|
|||||||
const RULES: { title: string, rule: RegExp, examples: string[] }[] = require('../packages/www/src/RULES.js');
|
const RULES: { title: string, rule: RegExp, examples: string[] }[] = require('../packages/www/src/RULES.js');
|
||||||
import useCommand from './useCommand';
|
import useCommand from './useCommand';
|
||||||
import useQuickPick from './useQuickPick';
|
import useQuickPick from './useQuickPick';
|
||||||
|
import useMenuCommand from './useMenuCommand';
|
||||||
|
|
||||||
export function activate(context: ExtensionContext) {
|
export function activate(context: ExtensionContext) {
|
||||||
useCommand(context, RULES);
|
useCommand(context, RULES);
|
||||||
useQuickPick(context, RULES);
|
useQuickPick(context, RULES);
|
||||||
|
useMenuCommand(context, RULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate() { }
|
export function deactivate() { }
|
||||||
|
@ -2,8 +2,8 @@ import { extensions, window, version, env, Uri, languages } from 'vscode';
|
|||||||
import { getCodeLanguage, getExtensionVersion } from './shared'
|
import { getCodeLanguage, getExtensionVersion } from './shared'
|
||||||
import insertLog from './insertLog';
|
import insertLog from './insertLog';
|
||||||
|
|
||||||
const BUTTON_FEEDBACK = '🚀反馈问题';
|
const BUTTON_FEEDBACK = '✋意见反馈';
|
||||||
const BUTTON_DIAGRAMMATIZE = '🦕图解正则';
|
const BUTTON_DIAGRAMMATIZE = '🤖图解正则';
|
||||||
const BUTTON_CANCEL = '关闭';
|
const BUTTON_CANCEL = '关闭';
|
||||||
|
|
||||||
export default function (title: string, rule: string): void {
|
export default function (title: string, rule: string): void {
|
||||||
|
55
src/useMenuCommand.ts
Normal file
55
src/useMenuCommand.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import { window, commands, Range, ExtensionContext } from "vscode";
|
||||||
|
import { Rule } from './interface';
|
||||||
|
import insertLog from './insertLog';
|
||||||
|
import showResultMessage from './showResultMessage';
|
||||||
|
|
||||||
|
export default function (context: ExtensionContext, RULES: Rule[]) {
|
||||||
|
|
||||||
|
const disposable = commands.registerCommand(`extension.rule.callByMenu`, () => {
|
||||||
|
// showQuickPick
|
||||||
|
window.showQuickPick(RULES.map(({ examples, title, rule }) => {
|
||||||
|
// const match = title.match(/\((.+)\)/);
|
||||||
|
return {
|
||||||
|
label: title,
|
||||||
|
// description: null !== match ? match[1] : '',
|
||||||
|
rule: String(rule), // 非标准字段, 仅仅为了传值
|
||||||
|
detail: `例如: ${examples.join(' 或 ')}`
|
||||||
|
};
|
||||||
|
}), {
|
||||||
|
placeHolder: '请输入关键词',
|
||||||
|
// onDidSelectItem(item){
|
||||||
|
// console.log(item)
|
||||||
|
// }
|
||||||
|
}).then(item => {
|
||||||
|
if (!item) return
|
||||||
|
|
||||||
|
const editor = window.activeTextEditor;
|
||||||
|
if (editor) {
|
||||||
|
const ruleString = String(item.rule);
|
||||||
|
const title = item.label;
|
||||||
|
const { selections } = editor;
|
||||||
|
|
||||||
|
editor.edit(editBuilder => {
|
||||||
|
selections.forEach(selection => {
|
||||||
|
const { start, end } = selection;
|
||||||
|
const range = new Range(start, end);
|
||||||
|
editBuilder.replace(range, ruleString);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
insertLog({
|
||||||
|
rule: ruleString,
|
||||||
|
title,
|
||||||
|
method: 'Menu'
|
||||||
|
});
|
||||||
|
|
||||||
|
showResultMessage(title, ruleString);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
context.subscriptions.push(disposable);
|
||||||
|
}
|
@ -43,7 +43,7 @@ export default function (context: ExtensionContext, RULES: Rule[]) {
|
|||||||
title: item.label,
|
title: item.label,
|
||||||
method: 'QuickPick'
|
method: 'QuickPick'
|
||||||
});
|
});
|
||||||
showResultMessage(item.label,item.rule);
|
showResultMessage(item.label, item.rule);
|
||||||
});
|
});
|
||||||
}, 10)
|
}, 10)
|
||||||
return [];
|
return [];
|
||||||
@ -81,12 +81,12 @@ function insertRule(document: TextDocument, position: Position, ruleString: stri
|
|||||||
// 获取配置
|
// 获取配置
|
||||||
function getConfig() {
|
function getConfig() {
|
||||||
const configuration = workspace.getConfiguration();
|
const configuration = workspace.getConfiguration();
|
||||||
const { triggerString, supportedLanguages = '*' } = configuration.AnyRule;
|
const { triggerString } = configuration.AnyRule;
|
||||||
const { length } = triggerString;
|
const { length } = triggerString;
|
||||||
const triggerStringStart = triggerString.substr(0, length - 1);
|
const triggerStringStart = triggerString.substr(0, length - 1);
|
||||||
const triggerStringEnd = triggerString.substr(-1);
|
const triggerStringEnd = triggerString.substr(-1);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
triggerStringStart, triggerStringEnd, triggerString, supportedLanguages
|
triggerStringStart, triggerStringEnd, triggerString, supportedLanguages: '*'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user