- 编辑器
- Visual Studio Code 基础
- 安装Visual Studio Code
- VS Code 扩展市场 VS Code Extension Marketplace
- 通过任务集成外部工具 Integrate with External Tools via Tasks
- 调试
- Why Visual Studio Code? - 为什么选用VSCode
- 版本控制(Version Control)
- Accessibility 易用性
- Editing Evolved - 与时俱进的编辑体验
- 定制化
- 定制化Visual Studio Code(Customize Visual Studio Code)
- 用户和工作区设置(User and Workspace Settings)
- VS Code 的快捷按键(Key Bindings for Visual Studio Code)
- 向 VSC 添加代码段(Adding Snippets to Visual Studio Code)
- Color Themes - 颜色主题
- Display Language - 语言区域
- 工具
- vsce - Publishing Tool Reference
- Yo Code - Extension Generator
- VS Code Extension Samples
- 技术支持
- Visual Studio Code FAQ
- Common Error Cases
- 如何升级到最新版 How to update to the latest release
- Requirements for Visual Studio Code
- 扩展
- Visual Studio Code 扩展 Extending Visual Studio Code
- 示例 - Hello World Example - Hello World
- 示例 - 单词数统计 Example - Word Count
- 示例 - 语言服务 Example - Language Server
- 示例 - 调试器 Example - Debuggers
- Running and Debugging Your Extension
- 安装扩展
- Extensibility Principles and Patterns
- Testing Your Extension
- Our Approach to Extensibility
- 扩展API
- 可扩展性参考
- 扩展清单文件 - package.json
- Contribution Points - package.json
- Activation Events - package.json
- vscode namespace API
- Complex Commands API
- Debugging API
- 语言
- 语言 Languages
- JavaScript
- 用C#进行工作 Working with C#
- C/C++ for VS Code (预览)(Preview)
- JSON
- VS Code对HTML的相关 HTML Programming in VS Code
- VS Code中的PHP编程 PHP Programming in VS Code
- VS Code 对 Python 的支持
- Markdown and VS Code - Markdown与VS Code
- Editing TypeScript
- CSS, Sass and Less
- 使用Docker工作
- 运行时
- Node.js Applications with VS Code
- ASP.NET Core with VS Code
- Unity Development with VS Code
- Office Add-ins with VS Code
- 开始(Getting Started)
Extensibility Principles and Patterns
The extension API of Visual Studio Code follows some guiding patterns and principles which are applied throughout the whole API.
Promises
The VS Code API represents asynchronous operations with promises. From extensions, any type of promise can be returned, like ES6, WinJS, A+, etc.
Being independent of a specific promise library is expressed in the API by the Thenable
-type. Thenable
represents the common denominator which is the then
-property.
In most cases the use of promises is optional and when VS Code calls into an extension, it can handle the result type as well as a Thenable
of the result type. When the use of a promise is optional, the API indicates this by returning or
-types.
provideNumber(): number | Thenable<number>
Cancellation Tokens
Often operations are started on volatile state which changes before operations can finish. For instance, computing IntelliSense starts and the user continues to type making the result of that operation obsolete.
APIs that are exposed to such behavior will get passed a CancellationToken
on which you can check for cancellation (isCancellationRequested
) or get notified when cancellation occurs (onCancellationRequested
). The cancellation token is usually the last parameter of a function call and optional.
Disposables
The VS Code API uses the dispose pattern for resources that are obtained from VS Code. This applies to event listening, commands, interacting with the UI, and various language contributions.
For instance, the setStatusBarMessage(value: string)
function returns a Disposable
which upon calling dispose
removes the message again.
Events
Events in the VS Code API are exposed as functions which you call with a listener-function to subscribe. Calls to subscribe return a Disposable
which removes the event listener upon dispose.
var listener = function(event) {
console.log(“It happened”, event);
};
// start listening
var subscription = fsWatcher.onDidDelete(listener);
// do more stuff
subscriptions.dispose(); // stop listening
Names of events follow the on[Will|Did]VerbNoun?
pattern. The name signals if the event is going to happens (onWill) or already happened (onDid), what happened (verb), and the context (noun) unless obvious from the context.
An example from the VS Code API is window.onDidChangeActiveTextEditor
which is an event fired when the active text editor (noun) has been (onDid) changed (verb).
Using Node.js Modules with Extensions
Your extension can depend on Node.js modules at runtime. Similarly to a node module itself, you can add those dependencies to your package.json
extension manifest using the dependencies
field.
Installation and Packaging
Visual Studio Code will not install your extension's dependencies when a user installs it, so you must npm install
before publishing. The extension's publishing package will contain all of its dependencies within. You can run vsce ls
to list all the files that vsce
will include in the package.
Next Steps
- Extension Manifest File - VS Code package.json extension manifest file reference
- Contribution Points - VS Code contribution points reference
- Activation Events - VS Code activation events reference
Common Questions
Q: Can I use native Node.js modules with my extension?
A: A Visual Studio Code extension package contains all of its dependencies. This means that if you develop your extension on Windows and depend on a native Node.js module when you publish that extension, the Windows compiled native dependency will be contained in your extension. Users on OS X or Linux won't be able to use the extension.
The only way to make this work for now is to include binaries for all four platforms of VS Code (Windows x86 and x64, Linux, OS X) in your extension and have code that dynamically loads the right one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论