You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md
+4-1
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,8 @@ We have a bulk test recorder for scope tests. You can use it by running Cursorle
48
48
49
49
When you're done, say `"cursorless save scope"` to save the tests to the appropriate files in the `data/fixtures/recorded/scopes` directory.
50
50
51
+
This step will create partial tests for each of the facets of the given scope. Once you've implemented the scopes in step 5 below, you can automatically update these tests to include the scope ranges, as described in step 6.
52
+
51
53
## 5. Add parse tree patterns for the given scope
52
54
53
55
Launch your extension in debug mode and open a file in your language. You can create one or more files in [`playground/`](../../../../../data/playground) and feel free to include those in your PR.
@@ -61,14 +63,15 @@ Then add parse tree patterns for the given scope to your language's `.scm` file
61
63
- Use the [scope visualizer](../user/scope-visualizer.md) to see your scope highlighted in real time every time you save the `.scm` file.
62
64
- Use the command `"parse tree <target>"` to see the parse tree for a given target. For example `"parse tree line"` will show you the parse tree for the current line, as well as all of its ancestors. This will generate a markdown file with parse tree info, which you can then use to write your patterns. You might find it helpful to open a markdown preview of the file.
63
65
- You will likely want to look at `node-types.json` for your language, (eg [java](https://github.com/tree-sitter/tree-sitter-java/blob/master/src/node-types.json)). This file is generated from the language's `grammar.js`, which might also be helpful to look at (eg [java](https://github.com/tree-sitter/tree-sitter-java/blob/master/grammar.js)).
66
+
- Documentation for the [scope test format](./scope-test-format.md)
64
67
65
68
## 6. Update the tests
66
69
67
70
The tests generated in step 4 only include the code example. Now that you've told Cursorless how to find the scope, we can automatically update the test cases to indicate where the scope should appear in your code examples.
68
71
69
72
1. Say `"debug edit subset"` and alter the file to include just the name of your language
70
73
2. Run the `Update fixtures subset` launch configuration to update your fixtures.
71
-
3. Check that the fixtures now look as expected, and no other tests for your language have been altered. The VSCode source control side bar is useful for this purpose.
74
+
3. Check that the fixtures now look as expected, and no other tests for your language have been altered. The VSCode source control side bar is useful for this purpose. For help understanding the scope test format, see the [scope test format docs](./scope-test-format.md)
Copy file name to clipboardexpand all lines: packages/cursorless-org-docs/src/docs/contributing/parse-tree-patterns.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Parse tree pattern matcher
1
+
# Parse tree pattern matcher[DEPRECATED]
2
2
3
3
We have a small domain-specific language that we use to define patterns to look for in tree-sitter parse trees. This DSL enables us to rapidly define new syntactic scope types and support new programming languages.
We have a custom format we use to test that our scopes are correct. The format is automatically generated, so you shouldn't need to edit it yourself. See [Step 6 of the adding a new scope guide](./adding-a-new-scope.md#6-update-the-tests) for more information.
4
+
5
+
## Example
6
+
7
+
Example of `.scope` file for the javascript if statement scope.
8
+
9
+
```
10
+
if (true) {
11
+
12
+
}
13
+
---
14
+
15
+
[Content] =
16
+
[Removal] =
17
+
[Domain] = 0:0-2:1
18
+
>-----------
19
+
0| if (true) {
20
+
1|
21
+
2| }
22
+
-<
23
+
24
+
[Insertion delimiter] = "\n"
25
+
```
26
+
27
+
## Understanding the format
28
+
29
+
General layout of a `.scope` file is:
30
+
31
+
```
32
+
Source code
33
+
---
34
+
Scopes
35
+
```
36
+
37
+
## Source code
38
+
39
+
The code that you want to generate scopes for. We try to keep this as short and simple as possible while still containing the syntax you want to test.
40
+
41
+
## Scopes
42
+
43
+
One or more scopes found in the source code. Each scope is a collection of ranges as well as an insertion delimiter.
44
+
45
+
A description of the different ranges and how they are used is available in our [glossary](../user/glossary.md).
46
+
47
+
### Scope ranges
48
+
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.
50
+
51
+
```
52
+
[Content] =
53
+
[Removal] =
54
+
[Domain] = 0:0-2:1
55
+
```
56
+
57
+
Each range is also visualized:
58
+
59
+
```
60
+
>-----------
61
+
0| if (true) {
62
+
1|
63
+
2| }
64
+
-<
65
+
```
66
+
67
+
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 `><`.
0 commit comments