Skip to content

Commit b6f391a

Browse files
DanielRosenwasserRyanCavanaughCopilot
authored
Add a basic copilot-instructions.md. (#1272)
Co-authored-by: Ryan Cavanaugh <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 5a79b0c commit b6f391a

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

.github/copilot-instructions.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
This is the codebase for a native port of the TypeScript compiler and language server.
2+
The source directories of interest that we have are:
3+
4+
- `internal` - Contains the compiler and language server code.
5+
- `_extension` - Contains a preview VS Code extension code that integrates with the language server.
6+
- `_submodules/TypeScript` - the stable TypeScript repository, checked out at the appropriate commit.
7+
8+
Most of our development takes place in the `internal` directory, and most behaviors can be tested via compiler tests.
9+
10+
Most development on the codebase is in Go.
11+
Standard Go commands and practices apply, but we primarily use a tool called `hereby` to build, run tests, and other tasks.
12+
Feel free to install `hereby` globally (`npm install -g hereby`) if it is easier, and run `hereby --list` to see all available commands.
13+
14+
```sh
15+
hereby build # Build the project
16+
hereby test # Run tests
17+
hereby format # Format the code
18+
hereby lint # Run linters
19+
```
20+
21+
Always make sure code is formatted, linted, and tested before sending a pull request.
22+
23+
## Compiler Features, Fixes, and Tests
24+
25+
When fixing a bug or implementing a new feature, at least one minimal test case should always be added in advance to verify the fix.
26+
This project primarily uses snapshot/baseline/golden tests rather than unit tests.
27+
New compiler tests are written in `.ts`/`.tsx` files in the directory `testdata/tests/cases/compiler/`, and are written in the following format:
28+
29+
```ts
30+
// @target: esnext
31+
// @module: preserve
32+
// @moduleResolution: bundler
33+
// @strict: true
34+
// @checkJs: true
35+
36+
// @filename: fileA.ts
37+
38+
export interface Person {
39+
name: string;
40+
age: number;
41+
}
42+
43+
// @filename: fileB.js
44+
45+
/** @import { Person } from "./fileA" */
46+
47+
/**
48+
* @param {Person} person
49+
*/
50+
function greet(person) {
51+
console.log(`Hello, ${person.name}!`);
52+
}
53+
```
54+
55+
Tests don't always need the above `@option`s specified, but they are common to specify or modify.
56+
Tests can be run with multiple settings for a given option by using a comma-separated list (e.g. `@option: settingA,settingB`).
57+
`@filename` is only required when a test has multiple files, or when writing a test for a single JavaScript file (where `allowJs` or `checkJs` is enabled).
58+
You can see more tests in `_submodules/TypeScript/tests/cases/{compiler,conformance}`.
59+
60+
When tests are run, they will produce output files in the `testdata/baselines/local` directory.
61+
**Test failures are fine** if they are just differences in output files.
62+
A reduction/removal of `.diff` file baselines is **ideal** because it indicates the port has converged in behavior with the stable TypeScript codebase.
63+
The new outputs can be diffed against `testdata/baselines/reference` to see if the output has changed.
64+
65+
Running
66+
67+
```sh
68+
npx hereby baseline-accept
69+
```
70+
71+
will update the baselines/snapshots, and `git diff` can be used to see what has changed.
72+
73+
It is ideal to implement features and fixes in the following order, and commit code after each step:
74+
75+
1. Write a minimal test case, or test cases, that demonstrate the bug or feature.
76+
1. Run the tests to ensure it fails (for a bug) or passes (for a feature). Then accept generated baselines (not applicable in the case of a crash).
77+
1. Implement the fix or feature.
78+
1. Run the tests again to ensure everything is working correctly. Accept the baselines.
79+
80+
It is fine to implement more and more of a feature across commits, but be sure to update baselines every time so that reviewers can measure progress.
81+
82+
# Other Instructions
83+
84+
- Do not add or change existing dependencies unless asked to.
85+

0 commit comments

Comments
 (0)