How to Contribute
Relevant source files
The following files were used as context for generating this wiki page:
- extensions/prompt-basics/syntaxes/prompt.tmLanguage.json
- extensions/yaml/syntaxes/yaml.tmLanguage.json
- extensions/git-base/syntaxes/git-commit.tmLanguage.json
- extensions/github/package.json
- extensions/gulp/package.json
- extensions/markdown-language-features/schemas/package.schema.json
- extensions/markdown-math/package.json
- extensions/typescript-language-features/package.nls.json
- extensions/git-base/syntaxes/git-rebase.tmLanguage.json
- extensions/github/package.nls.json
Contributing to the Visual Studio Code ecosystem involves various pathways, from enhancing core language features to improving individual extensions and syntax grammars. A significant portion of VS Code's functionality is encapsulated in extensions, many of which are maintained in their own repositories.
This guide outlines the key contribution models found within the VS Code project, focusing on how to contribute to extensions, particularly syntax highlighting grammars. It details the structure of extension packages, configuration points, and the specific process for submitting fixes and improvements, which often involves interacting with upstream, original repositories.
Contributing to Extensions and Grammars
Many extensions, especially those providing syntax highlighting (.tmLanguage.json files), are converted from other open-source projects. Contributions should be directed to the original repository first. Once a change is accepted upstream, an update can be requested for the VS Code repository.
Sources: extensions/prompt-basics/syntaxes/prompt.tmLanguage.json:2-5, extensions/yaml/syntaxes/yaml.tmLanguage.json:2-5, extensions/git-base/syntaxes/git-commit.tmLanguage.json:2-5
Grammar Contribution Flow
The following diagram illustrates the standard workflow for contributing to a syntax grammar that is sourced from an external repository.
This diagram shows the process of finding the source repository for a grammar, making a pull request there, and then requesting an update in the main VS Code project.
Sources: extensions/prompt-basics/syntaxes/prompt.tmLanguage.json:2-5, extensions/docker/syntaxes/docker.tmLanguage.json:2-5, extensions/git-base/syntaxes/git-rebase.tmLanguage.json:2-5
Examples of Upstream Repositories
| Grammar/Extension | Original Repository URL |
|---|---|
| Prompt | https://github.com/microsoft/vscode-markdown-tm-grammar |
| YAML | https://github.com/RedCMD/YAML-Syntax-Highlighter |
| Git Commit | https://github.com/walles/git-commit-message-plus |
| Git Rebase | https://github.com/textmate/git.tmbundle |
| Dockerfile | https://github.com/moby/moby |
Sources: extensions/prompt-basics/syntaxes/prompt.tmLanguage.json:2, extensions/yaml/syntaxes/yaml.tmLanguage.json:2, extensions/git-base/syntaxes/git-commit.tmLanguage.json:2, extensions/git-base/syntaxes/git-rebase.tmLanguage.json:2, extensions/docker/syntaxes/docker.tmLanguage.json:2
Understanding Extension Structure (package.json)
The package.json file is the manifest for a VS Code extension. It defines the extension's metadata, activation events, dependencies, and contribution points.
Key package.json Properties
| Property | Description | Example from github extension |
|---|---|---|
name | The identifier for the extension. | github |
displayName | The user-friendly name shown in the UI. | %displayName% (points to package.nls.json) |
publisher | The publisher of the extension. | vscode |
activationEvents | Events that trigger the extension's activation. | * (activates on startup) |
extensionDependencies | A list of other extensions this one depends on. | ["vscode.git-base"] |
main | The entry point file for the extension's code. | ./out/extension.js |
contributes | An object defining how the extension adds to VS Code's functionality. | Commands, menus, configuration, etc. |
Sources: extensions/github/package.json:2-20, 24-158, extensions/gulp/package.json:2-13, 23-60
Contribution Points
The contributes object in package.json is crucial for integrating an extension with VS Code. It can define commands, configuration settings, language grammars, and more.
This diagram shows the relationship between the main package.json and its contributes section.
Markdown Extension Contributions
Markdown extensions have specific contribution points defined by a schema. This allows them to add preview styles, scripts, and markdown-it plugins.
| Contribution Point | Type | Description |
|---|---|---|
markdown.previewStyles | array | CSS files to change the look of the Markdown preview. |
markdown.previewScripts | array | JavaScript files to be executed in the Markdown preview. |
markdown.markdownItPlugins | boolean | Indicates if the extension contributes a markdown-it plugin. |
Sources: extensions/markdown-language-features/schemas/package.schema.json:7-22, extensions/markdown-math/package.json:89-92
GitHub Extension Contributions
The github extension contributes commands for publishing repositories and interacting with GitHub, along with configuration settings.
- Commands:
github.publish,github.copyVscodeDevLink,github.openOnGitHub. - Configuration:
github.branchProtection,github.gitAuthentication,github.gitProtocol. - Welcome View: It adds a "Publish to GitHub" message in the SCM view for uninitialized repositories.
Sources: extensions/github/package.json:25-40, 116-143, 145-158, extensions/github/package.nls.json:4-6, 8-11
Syntax Highlighting Grammars
Syntax highlighting is defined using TextMate grammar files (.tmLanguage.json). These files use regular expressions to assign scopes to different parts of the code, which are then mapped to colors by the theme.
Git Rebase Grammar Example
The grammar for git-rebase interactive messages defines patterns for commands like pick, reword, squash, etc.
| Command | Scope Name | Description |
|---|---|---|
pick, p, reword, r, etc. | support.function.git-rebase | The rebase command itself. |
[0-9a-f]+ | constant.sha.git-rebase | The commit SHA. |
.* | meta.commit-message.git-rebase | The commit message summary. |
^#.* | comment.line.number-sign.git-rebase | Comment lines to be ignored. |
Sources: extensions/git-base/syntaxes/git-rebase.tmLanguage.json:11-30
Git Commit Grammar Example
Similarly, the git-commit grammar distinguishes between the user-supplied message and Git's metadata.
- Subject Line:
meta.scope.subject.git-commit. It marks lines longer than 50 characters asinvalid.deprecatedand longer than 72 asinvalid.illegal. - Metadata:
meta.scope.metadata.git-commit. This scope applies to the commented-out section. - File Status: It defines specific scopes for file changes, such as
markup.changed.git-commitfor modified files andmarkup.inserted.git-commitfor new files.
Sources: extensions/git-base/syntaxes/git-commit.tmLanguage.json:24-42, 47-75
Localized Strings (package.nls.json)
To support multiple languages, user-facing strings from package.json and code are stored in package.nls.json files. In package.json, placeholders like %displayName% are used, which correspond to keys in the nls file.
For example, the TypeScript extension defines its display name and numerous configuration descriptions in package.nls.json.
// extensions/typescript-language-features/package.nls.json
{
"displayName": "TypeScript and JavaScript Language Features",
"description": "Provides rich language support for JavaScript and TypeScript.",
"configuration.suggest.completeFunctionCalls": "Complete functions with their parameter signature."
}
This shows how human-readable strings are managed for localization, a key part of contributing user-facing features.
Sources: extensions/typescript-language-features/package.nls.json:2-5, extensions/github/package.nls.json:2-3