|
1 |
| -# Coding Guidelines |
2 |
| - |
3 |
| -## Introduction |
4 |
| - |
5 |
| -These are VS Code coding guidelines. Please also review our [Source Code Organisation](https://github.com/microsoft/vscode/wiki/Source-Code-Organization) page. |
6 |
| - |
7 |
| -## Indentation |
| 1 | +# VS Code Copilot Instructions |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Visual Studio Code is built with a layered architecture using TypeScript, web APIs and Electron, combining web technologies with native app capabilities. The codebase is organized into key architectural layers: |
| 6 | + |
| 7 | +### Root Folders |
| 8 | +- `src/`: Main TypeScript source code with unit tests in `src/vs/*/test/` folders |
| 9 | +- `build/`: Build scripts and CI/CD tools |
| 10 | +- `extensions/`: Built-in extensions that ship with VS Code |
| 11 | +- `test/`: Integration tests and test infrastructure |
| 12 | +- `scripts/`: Development and build scripts |
| 13 | +- `resources/`: Static resources (icons, themes, etc.) |
| 14 | +- `out/`: Compiled JavaScript output (generated during build) |
| 15 | + |
| 16 | +### Core Architecture (`src/` folder) |
| 17 | +- `src/vs/base/` - Foundation utilities and cross-platform abstractions |
| 18 | +- `src/vs/platform/` - Platform services and dependency injection infrastructure |
| 19 | +- `src/vs/editor/` - Text editor implementation with language services, syntax highlighting, and editing features |
| 20 | +- `src/vs/workbench/` - Main application workbench for web and desktop |
| 21 | + - `workbench/browser/` - Core workbench UI components (parts, layout, actions) |
| 22 | + - `workbench/services/` - Service implementations |
| 23 | + - `workbench/contrib/` - Feature contributions (git, debug, search, terminal, etc.) |
| 24 | + - `workbench/api/` - Extension host and VS Code API implementation |
| 25 | +- `src/vs/code/` - Electron main process specific implementation |
| 26 | +- `src/vs/server/` - Server specific implementation |
| 27 | + |
| 28 | +The core architecture follows these principles: |
| 29 | +- **Layered architecture** - from `base`, `platform`, `editor`, to `workbench` |
| 30 | +- **Dependency injection** - Services are injected through constructor parameters |
| 31 | +- **Contribution model** - Features contribute to registries and extension points |
| 32 | +- **Cross-platform compatibility** - Abstractions separate platform-specific code |
| 33 | + |
| 34 | +### Built-in Extensions (`extensions/` folder) |
| 35 | +The `extensions/` directory contains first-party extensions that ship with VS Code: |
| 36 | +- **Language support** - `typescript-language-features/`, `html-language-features/`, `css-language-features/`, etc. |
| 37 | +- **Core features** - `git/`, `debug-auto-launch/`, `emmet/`, `markdown-language-features/` |
| 38 | +- **Themes** - `theme-*` folders for default color themes |
| 39 | +- **Development tools** - `extension-editing/`, `vscode-api-tests/` |
| 40 | + |
| 41 | +Each extension follows the standard VS Code extension structure with `package.json`, TypeScript sources, and contribution points to extend the workbench through the Extension API. |
| 42 | + |
| 43 | +### Finding Related Code |
| 44 | +1. **Semantic search first**: Use file search for general concepts |
| 45 | +2. **Grep for exact strings**: Use grep for error messages or specific function names |
| 46 | +3. **Follow imports**: Check what files import the problematic module |
| 47 | +4. **Check test files**: Often reveal usage patterns and expected behavior |
| 48 | + |
| 49 | +## Coding Guidelines |
| 50 | + |
| 51 | +### Indentation |
8 | 52 |
|
9 | 53 | We use tabs, not spaces.
|
10 | 54 |
|
11 |
| -## Naming Conventions |
| 55 | +### Naming Conventions |
| 56 | + |
| 57 | +- Use PascalCase for `type` names |
| 58 | +- Use PascalCase for `enum` values |
| 59 | +- Use camelCase for `function` and `method` names |
| 60 | +- Use camelCase for `property` names and `local variables` |
| 61 | +- Use whole words in names when possible |
12 | 62 |
|
13 |
| -* Use PascalCase for `type` names |
14 |
| -* Use PascalCase for `enum` values |
15 |
| -* Use camelCase for `function` and `method` names |
16 |
| -* Use camelCase for `property` names and `local variables` |
17 |
| -* Use whole words in names when possible |
| 63 | +### Types |
18 | 64 |
|
19 |
| -## Types |
| 65 | +- Do not export `types` or `functions` unless you need to share it across multiple components |
| 66 | +- Do not introduce new `types` or `values` to the global namespace |
20 | 67 |
|
21 |
| -* Do not export `types` or `functions` unless you need to share it across multiple components |
22 |
| -* Do not introduce new `types` or `values` to the global namespace |
| 68 | +### Comments |
23 | 69 |
|
24 |
| -## Comments |
| 70 | +- Use JSDoc style comments for `functions`, `interfaces`, `enums`, and `classes` |
25 | 71 |
|
26 |
| -* When there are comments for `functions`, `interfaces`, `enums`, and `classes` use JSDoc style comments |
| 72 | +### Strings |
27 | 73 |
|
28 |
| -## Strings |
| 74 | +- Use "double quotes" for strings shown to the user that need to be externalized (localized) |
| 75 | +- Use 'single quotes' otherwise |
| 76 | +- All strings visible to the user need to be externalized |
29 | 77 |
|
30 |
| -* Use "double quotes" for strings shown to the user that need to be externalized (localized) |
31 |
| -* Use 'single quotes' otherwise |
32 |
| -* All strings visible to the user need to be externalized |
| 78 | +### UI labels |
| 79 | +- Use title-style capitalization for command labels, buttons and menu items (each word is capitalized). |
| 80 | +- Don't capitalize prepositions of four or fewer letters unless it's the first or last word (e.g. "in", "with", "for"). |
33 | 81 |
|
34 |
| -## Style |
| 82 | +### Style |
35 | 83 |
|
36 |
| -* Use arrow functions `=>` over anonymous function expressions |
37 |
| -* Only surround arrow function parameters when necessary. For example, `(x) => x + x` is wrong but the following are correct: |
| 84 | +- Use arrow functions `=>` over anonymous function expressions |
| 85 | +- Only surround arrow function parameters when necessary. For example, `(x) => x + x` is wrong but the following are correct: |
38 | 86 |
|
39 |
| -```javascript |
| 87 | +```typescript |
40 | 88 | x => x + x
|
41 | 89 | (x, y) => x + y
|
42 | 90 | <T>(x: T, y: T) => x === y
|
43 | 91 | ```
|
44 | 92 |
|
45 |
| -* Always surround loop and conditional bodies with curly braces |
46 |
| -* Open curly braces always go on the same line as whatever necessitates them |
47 |
| -* Parenthesized constructs should have no surrounding whitespace. A single space follows commas, colons, and semicolons in those constructs. For example: |
| 93 | +- Always surround loop and conditional bodies with curly braces |
| 94 | +- Open curly braces always go on the same line as whatever necessitates them |
| 95 | +- Parenthesized constructs should have no surrounding whitespace. A single space follows commas, colons, and semicolons in those constructs. For example: |
48 | 96 |
|
49 |
| -```javascript |
| 97 | +```typescript |
50 | 98 | for (let i = 0, n = str.length; i < 10; i++) {
|
51 | 99 | if (x < 10) {
|
52 | 100 | foo();
|
53 | 101 | }
|
54 | 102 | }
|
55 |
| - |
56 | 103 | function f(x: number, y: string): void { }
|
57 | 104 | ```
|
| 105 | + |
| 106 | +- Whenever possible, use in top-level scopes `export function x(…) {…}` instead of `export const x = (…) => {…}`. One advantage of using the `function` keyword is that the stack-trace shows a good name when debugging. |
| 107 | + |
| 108 | +### Code Quality |
| 109 | + |
| 110 | +- All files must include Microsoft copyright header |
| 111 | +- Prefer async/await over Promises, handle cancellation with `CancellationToken` |
| 112 | +- All user facing messages must be localized using the applicable localization framework (for example `nls.localize()` method) |
| 113 | +- Don't add tests to the wrong test suite (e.g., adding to end of file instead of inside relevant suite) |
| 114 | +- Look for existing test patterns before creating new structures |
| 115 | +- Use `describe` and `test` consistently with existing patterns |
0 commit comments