Skip to content

Commit 26621a8

Browse files
Added documentation describing guidelines for writing scope tests (#3019)
1 parent d53a450 commit 26621a8

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
".busted": "lua"
2929
},
3030
"files.eol": "\n",
31+
"github.copilot.chat.codeGeneration.instructions": [
32+
{
33+
"file": "./packages/cursorless-org-docs/src/docs/contributing/scope-test-format.md"
34+
}
35+
],
3136
"typescript.enablePromptUseWorkspaceTsdk": true,
3237
"typescript.tsdk": "node_modules/typescript/lib",
3338
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts

packages/cursorless-org-docs/src/docs/contributing/scope-test-format.md

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@ We have a custom format we use to test that our scopes are correct. The format i
44

55
## Example
66

7-
Example of `.scope` file for the javascript if statement scope.
7+
Example of `.scope` file for the javascript statement scope.
88

99
```
10-
if (true) {
11-
12-
}
10+
const value = 0;
1311
---
14-
1512
[Content] =
1613
[Removal] =
17-
[Domain] = 0:0-2:1
18-
>-----------
19-
0| if (true) {
20-
1|
21-
2| }
22-
-<
14+
[Domain] = 0:0-0:16
15+
>----------------<
16+
0| const value = 0;
2317
2418
[Insertion delimiter] = "\n"
2519
```
@@ -46,16 +40,34 @@ A description of the different ranges and how they are used is available in our
4640

4741
### Scope ranges
4842

49-
The below example indicates that the content range, removal range, and domain range was the same. Line 0, column 0, to line 2, column 1. These ranges could also be different and in that case each show up as a separate range.
43+
The below example indicates that the content range, removal range, and domain range was the same. Line 0, column 0, to line 0, column 16.
5044

5145
```
5246
[Content] =
5347
[Removal] =
5448
[Domain] = 0:0-2:1
5549
```
5650

51+
These ranges could also be different and in that case each show up as a separate range.
52+
53+
```
54+
[Removal] =
55+
[Content] = 0:0-0:6
56+
57+
[Domain] = 0:0-2:1
58+
```
59+
5760
Each range is also visualized:
5861

62+
Single line range
63+
64+
```
65+
>------------<
66+
0| if (true) {}
67+
```
68+
69+
Multi line range
70+
5971
```
6072
>-----------
6173
0| if (true) {
@@ -65,3 +77,38 @@ Each range is also visualized:
6577
```
6678

6779
On the left hand side we first have the line numbers, a pipe separator, and finally the source code. The range is visualized by starting after `>` and ending before `<`. Note that `>` and `<` is excluded from the range. That means a range of length one is `>-<` and an empty range is `><`.
80+
81+
## Style guidelines
82+
83+
For ease of readability we want all scope test to follow the recommended style guidelines.
84+
85+
### Naming convention and values
86+
87+
- For classes, functions and variables we use the classic: `foo`, `bar`, `baz`, `bongo`. Language specific formatting still applies. eg `Foo` for a class in Java, `IFoo` for an interface in C# etc.
88+
- For arguments and parameters we usually use: `aaa`, `bbb`, `ccc` and so on.
89+
- For data type we usually use `int` or `number`.
90+
- For value we usually use `0`, `1`, `2` and so on.
91+
92+
Examples:
93+
94+
```
95+
class Foo {}
96+
int foo = 0;
97+
foo(aaa, bbb);
98+
```
99+
100+
### Keep it compact
101+
102+
Don't add more lines than the example actually needs. For example if the test is about the class name, the facet `name.class`: there is no point having a lot of code in the class body or having its span multiple lines.
103+
104+
```
105+
>---<
106+
0| class Foo {}
107+
```
108+
109+
Sometimes we actually need a body but that doesn't mean that we need it to be multiple lines. The facet `interior.class` can look like this:
110+
111+
```
112+
>-<
113+
0| class Foo { }
114+
```

0 commit comments

Comments
 (0)