Overview
This document outlines the coding guidelines for contributing to Visual Studio Code. Following these standards ensures consistency across the codebase and makes it easier for everyone to read and maintain the code.All contributors are expected to follow these guidelines. Pull requests that don’t adhere to these standards may be asked to make revisions.
Indentation
EditorConfig Settings
The project uses EditorConfig to maintain consistent coding styles:Why Tabs?
Why Tabs?
Tabs allow developers to choose their preferred visual width while maintaining consistency in the actual file content. This is a deliberate choice for the VS Code project.
Naming Conventions
Consistent naming makes code more readable and maintainable.Type Names
Use PascalCase for type names:Enum Values
Use PascalCase for enum values:Functions and Methods
Use camelCase for function and method names:Properties and Variables
Use camelCase for property names and local variables:Naming Best Practices
1
Use Whole Words
Prefer complete words over abbreviations when possible:
2
Be Descriptive
Names should clearly indicate what the variable or function does:
3
Follow Domain Conventions
Use terminology consistent with VS Code’s domain and existing codebase.
Types
Avoid Polluting Global Namespace
Export Minimally
Avoid any and unknown
Comments
Use JSDoc style comments for functions, interfaces, enums, and classes:When to Write Comments
When to Write Comments
- Public APIs: Always document with JSDoc
- Complex logic: Explain the “why” not the “what”
- Non-obvious behavior: Document surprising or unintuitive code
- Workarounds: Explain why a workaround is necessary
Strings
Quote Style
VS Code has specific rules for string quotes:- Double Quotes
- Single Quotes
Use double quotes for strings shown to the user that need to be externalized (localized):
Localization
All strings visible to users must be externalized using thevs/nls module:
UI Labels
Capitalization
Use title-style capitalization for command labels, buttons, and menu items:- Correct
- Incorrect
- Open File
- Save All
- Find in Files
- Toggle Developer Tools
- Replace with Copy
Don’t capitalize prepositions of four or fewer letters (in, with, for, from) unless it’s the first or last word.
Code Style
Arrow Functions
Prefer arrow functions over anonymous function expressions:Arrow Function Parameters
Only surround arrow function parameters when necessary:Curly Braces
Always surround loop and conditional bodies with curly braces:Brace Placement
Open curly braces always go on the same line:Whitespace in Constructs
Parenthesized constructs should have no surrounding whitespace. Single space follows commas, colons, and semicolons:Function Declaration Style
Using thefunction keyword provides better stack traces when debugging:
Code Quality
Async/Await
Preferasync and await over Promise and then calls:
Disposables Management
Use helpers such asDisposableStore, MutableDisposable, or DisposableMap:
File Watching
When adding file watching, prefer correlated file watchers:Tooltips
When adding tooltips to UI elements, prefer theIHoverService:
Code Reuse
1
Search Existing Code
Use grep or file search to find similar implementations
2
Check Common Utilities
Look in
src/vs/base/common/ for common utilities3
Extend When Possible
Extend existing utilities rather than creating duplicates
4
Refactor if Needed
If you find duplication, consider refactoring to share code
Storage Keys
Import Management
Testing
Test Organization
Look for existing test patterns before creating new structures:Test Assertions
Minimize the number of assertions in tests:Regular Expressions
Prefer named capture groups over numbered ones:Copyright Header
Cleanup
If you create any temporary files, scripts, or helper files during development:1
Document Temporary Files
Keep track of any temporary files you create
2
Remove Before Committing
Clean up these files before submitting your pull request
3
Check Git Status
Use
git status to ensure no unwanted files are includedSummary
Key Points
- Use tabs for indentation
- Follow naming conventions (PascalCase for types, camelCase for functions)
- Avoid
anytype - Externalize user-facing strings
Best Practices
- Prefer async/await
- Manage disposables properly
- Reuse existing code
- Write comprehensive tests
These guidelines help maintain code quality and consistency across the VS Code codebase. When in doubt, look at existing code for examples.