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