code --help
code -r
code -r -g package.json:128
code -r -d a.txt b.txt
ls | code -
光标移动至javascript
Ctrl + Left/Right
,Cmd + Shift + \
Ctrl + Home/End
文本html
Ctrl A/X/C/V/S
Shift + 上述光标操做
Alt + Shift + F
Ctrl + K
+ Ctrl + F
行java
Ctrl + Shift + K
Ctrl + X/C/V
Ctrl ( + Shift) + Enter
Alt + 上/下
文档node
Ctrl + F/H/T
Ctrl + G
Ctrl + P
Ctrl + Shift + O
Ctrl + Shift + P
窗体linux
Ctrl + W
Ctrl + B
toggle side bar pos
Ctrl + K V
Ctrl + 1/2/3
Shift + Alt + 0
2x2
Ctrl + Pagedown/Pageup
Ctrl + /-
(reset zoom 恢复)Ctrl + K
+ Ctrl + S
鼠标操做git
双击
三击/单击行号
Alt + 单击
编码github
Ctrl + 空格
Ctrl + Shift + [/]
Ctrl + Shift + Space
Ctrl + .
Ctrl + Shift + `
Ctrl + J
go to last edit
Ctrl + R
用户设置chrome
其余用户设置shell
editor font, 字体npm
连字字体
"editor.fontFamily": "Fira Code", "editor.fontLigatures": true
https://docs.emmet.io/abbrevi...
命令面板输入conf task
{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "echo Hello" } ] }
{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "echo", "args": [ { "value": "Hello World", "quoting": "escape" } ] } ] }
{ "version": "2.0.0", "tasks": [ { "label": "chrome", "type": "process", "command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "windows": { "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" }, "linux": { "command": "/usr/bin/google-chrome" } } ] }
{ "version": "2.0.0", "tasks": [ { "label": "test shell", "type": "shell", "command": "./scripts/test.sh", "windows": { "command": ".\\scripts\\test.cmd" }, "group": "test", "presentation": { "reveal": "always", "panel": "new" }, "options": { "cwd": "", "env": {}, "shell": { "executable": "bash" } } } ] }
安装 quick task插件便于可视化
{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "echo", "args": [ { "value": "index.js:5:3: warning: unused variable", "quoting": "escape" } ], "problemMatcher": { "owner": "echo", "fileLocation": ["relative", "${workspaceFolder}"], "pattern": { "regexp": "^(.*):(\\d + ):(\\d + ):\\s + (warning|error):\\s + (.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } } ] }
{ "taskName": "compile", "dependsOn": [ "frontend", "backend" ], "group": { "kind": "build", "isDefault": true } }
https://code.visualstudio.com...
VS Code 为插件做者提供了一套统一的接口,叫作Debug Adapter Protocol(DAP),插件最终实现调试功能。
自带node调试插件Node Debug
需安装chrome调试插件Debugger for Chrome
Visual Studio Code / Egret Wing 技术架构
基于Electron(Chromium + node) electron应用结构
3个主要进程:
还有两种特殊的进程:
- 调试进程(Debug Adapter),渲染进程会经过 VS Code Debug Protocol 跟 Debug Adapter 进程通信。 - 语言支持(Language Server)
确保安装了Node.js和Git
而后安装Yeoman和VS Code Extension Generator和VSCE:
npm install -g yo@latest generator-code vsce
注册帐号 https://aka.ms/SignupAzureDevOps
登陆后User settings选择Security,添加token,注意备份,以后要用
yo code myextension
建立一个 VS Code 的插件模板,选择类型cd myextension && code .
开始编辑
重要文件
- package.json 记录了node应用和插件的信息 - extension.js 当前插件的所有代码 - .vscode 官方提供的调试配置、任务配置等
extension.js
const vscode = require('vscode'); //激活扩展程序时会调用此方法 //您的扩展程序在第一次执行命令时被激活 function activate(context) { //使用控制台输出诊断信息(console.log)和错误(console.error) //此代码行仅在激活扩展程序时执行一次 console.log('Congratulations, your extension "mdf" is now active!'); //该命令已在package.json文件中定义 //如今使用registerCommand提供命令的实现 //commandId参数必须与package.json中的命令字段匹配 let disposable = vscode.commands.registerCommand('extension.helloWorld', function () { //每次执行命令时,都会执行此处放置的代码 vscode.window.showInformationMessage('Hello World!');//向用户显示消息框 }); context.subscriptions.push(disposable); } exports.activate = activate; //停用扩展程序时会调用此方法 function deactivate() {} module.exports = { activate, deactivate }
package.json
engines 指定了运行这个插件须要的 VS Code 版本
"vscode": "^1.29.0"
activationEvents 指定了什么状况下这个插件应该被加载而且激活
"activationEvents": [ "onCommand:extension.sayHello" ]
contributes VS Code 会把这个command命令注册到命令面板中
"contributes": { "commands": [ { "command": "extension.sayHello", "title": "Hello World" } ] },
调试 F5
(会再开一个vscode,请确保电脑内存充足)
查询 API vscode.languages
定义文件 vscode.d.ts
只需编写package.json
"contributes": { "commands": [ { "command": "extension.sayHello", "title": "Hello World" } ], "keybindings": [ { "key": "ctrl + t", "command": "extension.sayHello", "when": "editorTextFocus" } ] },
示例:Notepad + + 源码
注意事项:"activationEvents": ["*"]
永远激活插件可能影响性能,慎用。
只需编写 snippets/snippets.json
(若不分享插件则本地命令面板输入snippets
便可编写)
snippets.json
{ "Print to console": { "prefix": "log", "body": [ "console.log(${1:i});", "console.log(${1:i} + 1); // ${1:i} + 1", "$2" ], "description": "Log output to console" } }
package.json
"contributes": { "snippets": [ { "language": "javascript", "path": "./snippets/snippets.json" } ] }
编写themes/mytheme-color-theme.json
以及package.json
"contributes": { "themes": [ { "label": "mytheme", "uiTheme": "vs-dark", "path": "./themes/mytheme-color-theme.json" } ] }
package.json
configurations:./ language-configuration.json
语言的配置信息所在文件的相对地址 language-configuration.json
语言相关信息的模板{ "comments": { "lineComment": "//",// 单行注释 "blockComment": [ "/*", "*/" ]//多行注释 }, "brackets": [// 支持的括号类型 ["{", "}"], ["[", "]"], ["(", ")"] ], "autoClosingPairs": [// 键入时自动关闭的符号 ["{", "}"], ["[", "]"], ["(", ")"], ["\"", "\""], ["'", "'"] ], "surroundingPairs": [// 可用于包围选区的符号 ["{", "}"], ["[", "]"], ["(", ")"], ["\"", "\""], ["'", "'"] ], "folding": {//可被折叠的代码段的开头和结尾 "markers": { "start": "^\\s*//#region", "end": "^\\s*//#endregion" } }, "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\ + \\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s] + )",//一个单词 "indentationRules": {//如何根据一行的内容来控制缩进 "increaseIndentPattern": "^\\s*((begin|class|(private|protected)\\s + def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while|case)|([^#]*\\sdo\\b)|([^#]*=\\s*(case|if|unless)))\\b([^#\\{;]|(\"|'|\/).*\\4)*(#.*)?$", "decreaseIndentPattern": "^\\s*(}\\]]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif|when)\\b)" } }
插件市场
使用vsce工具命令建立发布帐号vsce create-publisher your-publisher-name
登陆帐号vsce login your-publisher-name
发布vsce publish
发布-官方文档
https://github.com/Microsoft/...
vscode.window.showInformationMessage('Hello World', 'Yes', 'No').then(value => { value=='Yes'&&vscode.window.showWarningMessage('User press ' + value); value=='No'&&vscode.window.showErrorMessage('User press ' + value); })
给用户提供了一系列选项,而后根据用户选择的选项进行下一步的操做。
vscode.window.showQuickPick(['first', 'second', 'third']).then(value => { vscode.window.showInformationMessage('User choose ' + value); })
vscode.commands.registerCommand('extension.sayHello', () => { vscode.window.showQuickPick([{ label: 'first', description: 'first item', detail: 'first item details' }, { label: 'second', description: 'second item', detail: 'second item details' }]).then(value => { vscode.window.showInformationMessage('User choose ' + value.label); }) });
let collection = vscode.languages.createDiagnosticCollection('myextension'); let uri = vscode.window.activeTextEditor.document.uri; collection.set(uri, [ { range: new vscode.Range(0, 0, 0, 1), message: 'We found an error' } ]);
let channel =vscode.window.createOutputChannel('MyExtension'); channel.appendLine('Hello World');
调试面板
终端面板
vscode.window.registerTreeDataProvider('myextension', { getChildren: (element) => { if (element) { return null; } return ['first', 'second', 'third']; }, getTreeItem: (element) => { return { label: element, tooltip: 'my ' + element + ' item' } } })
package.json的contributes
"contributes": { "views": { "explorer": [ { "id": "myextension", "name": "My Extension" } ] } }
WebView API 来生成任意的编辑器内容
FileSystemProvider 或者 TextDocumentContentProvider 来为 VS Code 提供相似于本地文件的文本内容
let decorationType = vscode.window.createTextEditorDecorationType({ backgroundColor: '#fff', border: '1px solid red;', fontStyle: 'italic', letterSpacing: '3px' }); let editor = vscode.window.activeTextEditor; editor.setDecorations(decorationType, [new vscode.Range(0, 0, 0, 1)]);
createTextEditorDecorationType(DecorationRenderOptions)
DecorationRenderOptions={ //颜色和背景相关 backgroundColor?: string | ThemeColor; color?: string | ThemeColor; overviewRulerColor?: string | ThemeColor; //边框 border?: string; borderColor?: string | ThemeColor; borderRadius?: string; borderSpacing?: string; borderStyle?: string; borderWidth?: string; //轮廓 outline?: string; outlineColor?: string | ThemeColor; outlineStyle?: string; outlineWidth?: string; //字体 fontStyle?: string; fontWeight?: string; opacity?: string; letterSpacing?: string; //其余 gutterIconPath?: string | Uri; gutterIconSize?: string; before?: ThemableDecorationAttachmentRenderOptions; after?: ThemableDecorationAttachmentRenderOptions; }
ThemeColor
new vscode.ThemeColor('editorWarning.foreground')
插件参考:Rainbow Brackets 和 Indent Rainbow
发布流程:
维护团队review,要点:
Node.js 模块使用:
极客时间-玩转vscode