Visual Studio Code 高亮扩展项目教程
1. 项目的目录结构及介绍
vscode-highlight/
├── media/
│ └── icon.png
├── src/
│ ├── commands/
│ │ └── force_decorate.ts
│ ├── test/
│ │ └── extension.test.ts
│ ├── types/
│ │ └── index.d.ts
│ ├── utils/
│ │ └── index.ts
│ ├── extension.ts
│ └── package.json
├── .gitignore
├── .vscodeignore
├── CHANGELOG.md
├── LICENSE
├── README.md
└── package.json
- media/: 包含项目的图标文件。
- src/: 项目的源代码目录。
- commands/: 包含命令相关的文件,如强制装饰命令。
- test/: 包含测试文件。
- types/: 包含类型定义文件。
- utils/: 包含工具函数文件。
- extension.ts: 扩展的主入口文件。
- package.json: 项目的配置文件,包含依赖和脚本等。
- .gitignore: Git忽略文件。
- .vscodeignore: VSCode忽略文件。
- CHANGELOG.md: 变更日志。
- LICENSE: 许可证文件。
- README.md: 项目说明文档。
- package.json: 项目的配置文件,包含依赖和脚本等。
2. 项目的启动文件介绍
项目的启动文件是 src/extension.ts
。这个文件是扩展的主入口点,负责初始化扩展和注册命令。以下是 extension.ts
的主要内容:
import * as vscode from 'vscode';
import { forceDecorate } from './commands/force_decorate';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('highlight.forceDecorate', forceDecorate)
);
}
export function deactivate() {}
- activate: 当扩展被激活时调用,注册命令
highlight.forceDecorate
。 - deactivate: 当扩展被停用时调用。
3. 项目的配置文件介绍
项目的配置文件是 package.json
。这个文件包含了扩展的所有配置信息,包括依赖、命令、设置等。以下是 package.json
的部分内容:
{
"name": "vscode-highlight",
"displayName": "Highlight",
"description": "Advanced text highlighter based on regexes",
"version": "1.0.0",
"publisher": "fabiospampinato",
"engines": {
"vscode": "^1.50.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:highlight.forceDecorate"
],
"main": "./src/extension.ts",
"contributes": {
"commands": [
{
"command": "highlight.forceDecorate",
"title": "Highlight: Force Decorate"
}
],
"configuration": {
"type": "object",
"title": "Highlight Configuration",
"properties": {
"highlight.regexes": {
"type": "array",
"default": [],
"description": "List of regexes to highlight"
},
"highlight.regexFlags": {
"type": "string",
"default": "gi",
"description": "Flags for the regexes"
},
"highlight.minDelay": {
"type": "number",
"default": 50,
"description": "Minimum delay before highlighting"
},
"highlight.maxMatches": {
"type": "number",
"default": 250,
"description": "Maximum number of matches to decorate"
}
}
}
}
}
- name: 扩展的名称。
- displayName: 扩展的显示名称。
- description: 扩展的描述。
- version: 扩展的版本。
- publisher: 扩展的发布者。