Skip to main content

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

VS Code uses tabs, not spaces. This is enforced via .editorconfig.

EditorConfig Settings

The project uses EditorConfig to maintain consistent coding styles:
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

Do not introduce new types or values to the global namespace unless absolutely necessary.

Export Minimally

Only export types or functions when you need to share them across multiple components. Keep internal implementation details private.

Avoid any and unknown

Do not use any or unknown as types for variables, parameters, or return values unless absolutely necessary. Always prefer proper type definitions.

Comments

Use JSDoc style comments for functions, interfaces, enums, and classes:
  • 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
Avoid comments that simply restate what the code does:

Strings

Quote Style

VS Code has specific rules for string 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 the vs/nls module:
Externalized strings must not use string concatenation. Always use placeholders like {0}, {1}, etc.

UI Labels

Capitalization

Use title-style capitalization for command labels, buttons, and menu items:
  • 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

In top-level scopes, prefer export function x() {} over export const x = () => {}.
Using the function keyword provides better stack traces when debugging:

Code Quality

Async/Await

Prefer async and await over Promise and then calls:

Disposables Management

You MUST deal with disposables by registering them immediately after creation for later disposal.
Use helpers such as DisposableStore, MutableDisposable, or DisposableMap:
Do NOT register a disposable to the containing class if the object is created within a method that is called repeatedly. Instead, return an IDisposable and let the caller register it.

File Watching

When adding file watching, prefer correlated file watchers:

Tooltips

When adding tooltips to UI elements, prefer the IHoverService:

Code Reuse

Do not duplicate code. Always look for existing utility functions, helpers, or patterns before implementing new functionality.
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 utilities
3

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

You MUST NOT use storage keys of another component only to make changes to that component. Create proper APIs instead.

Import Management

Never duplicate imports. Always reuse existing imports if they are present.

Testing

Test Organization

Don’t add tests to the wrong test suite (e.g., adding to end of file instead of inside relevant suite).
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:
All files must include the Microsoft copyright header at the top.

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 included

Summary

Key Points

  • Use tabs for indentation
  • Follow naming conventions (PascalCase for types, camelCase for functions)
  • Avoid any type
  • 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.