扩展指南

一旦你在Hello World示例中学习了Visual Studio Code扩展API的基础知识,是时候构建一些实际扩展了。虽然扩展功能部分提供了扩展可以做什么的高级概述,但本节包含了一系列详细的代码指南和示例,解释了如何使用特定的VS Code API。

在每个指南或示例中,您可以期望找到:

  • 详细注释的源代码。
  • 一个展示示例扩展使用情况的gif或图像。
  • 运行示例扩展的说明。
  • 列出正在使用的VS Code API。
  • 列出正在使用的贡献点。
  • 与现实世界扩展相似的示例。
  • API概念的说明。

指南与示例

以下是VS Code网站上的指南,包括它们对VS Code APIContribution Points的使用。别忘了参考UX Guidelines,了解创建扩展时的用户界面最佳实践。

Guide on VS Code Website API & Contribution
Command commands
contributes.commands
Color Theme contributes.themes
File Icon Theme contributes.iconThemes
Product Icon Theme contributes.productIconThemes
Tree View window.createTreeView
window.registerTreeDataProvider
TreeView
TreeDataProvider
contributes.views
contributes.viewsContainers
Webview window.createWebviewPanel
window.registerWebviewPanelSerializer
Custom Editors window.registerCustomEditorProvider
CustomTextEditorProvider
contributes.customEditors
Virtual Documents workspace.registerTextDocumentContentProvider
commands.registerCommand
window.showInputBox
Virtual Workspaces workspace.fs
capabilities.virtualWorkspaces
Workspace Trust workspace.isTrusted
workspace.onDidGrantWorkspaceTrust
capabilities.untrustedWorkspaces
Task Provider tasks.registerTaskProvider
Task
ShellExecution
contributes.taskDefinitions
Source Control workspace.workspaceFolders
SourceControl
SourceControlResourceGroup
scm.createSourceControl
TextDocumentContentProvider
contributes.menus
Debugger Extension contributes.breakpoints
contributes.debuggers
debug
Markdown Extension markdown.previewStyles
markdown.markdownItPlugins
markdown.previewScripts
Test Extension TestController
TestItem
Custom Data Extension contributes.html.customData
contributes.css.customData

以下是来自VS Code 扩展示例仓库的额外示例列表。

Sample on GitHub Repo API & Contribution
Webview Sample window.createWebviewPanel
window.registerWebviewPanelSerializer
Status Bar Sample window.createStatusBarItem
StatusBarItem
Tree View Sample window.createTreeView
window.registerTreeDataProvider
TreeView
TreeDataProvider
contributes.views
contributes.viewsContainers
Task Provider Sample tasks.registerTaskProvider
Task
ShellExecution
contributes.taskDefinitions
Multi Root Sample workspace.getWorkspaceFolder
workspace.onDidChangeWorkspaceFolders
Completion Provider Sample languages.registerCompletionItemProvider
CompletionItem
SnippetString
File System Provider Sample workspace.registerFileSystemProvider
Editor Decorator Sample TextEditor.setDecorations
DecorationOptions
DecorationInstanceRenderOptions
ThemableDecorationInstanceRenderOptions
window.createTextEditorDecorationType
TextEditorDecorationType
contributes.colors
L10N Sample
Terminal Sample window.createTerminal
window.onDidChangeActiveTerminal
window.onDidCloseTerminal
window.onDidOpenTerminal
window.Terminal
window.terminals
Vim Sample commands
StatusBarItem
window.createStatusBarItem
TextEditorCursorStyle
window.activeTextEditor
Position
Range
Selection
TextEditor
TextEditorRevealType
TextDocument
Source Control Sample workspace.workspaceFolders
SourceControl
SourceControlResourceGroup
scm.createSourceControl
TextDocumentContentProvider
contributes.menus
Commenting API Sample
Document Editing Sample commands
contributes.commands
Getting Started Sample contributes.walkthroughs
Test extension TestController
TestItem

语言扩展示例

这些示例是语言扩展示例:

Sample Guide on VS Code Website
Snippet Sample /api/language-extensions/snippet-guide
Language Configuration Sample /api/language-extensions/language-configuration-guide
LSP Sample /api/language-extensions/language-server-extension-guide
LSP Log Streaming Sample N/A
LSP Multi Root Server Sample https://github.com/microsoft/vscode/wiki/Adopting-Multi-Root-Workspace-APIs#language-client--language-server (GitHub repo wiki)
LSP Web Extension Sample /api/language-extensions/language-server-extension-guide