Skip to content

Commit 7b3db14

Browse files
authored
Add docs for adding a new language (#187)
1 parent 76cff68 commit 7b3db14

File tree

3 files changed

+75
-16
lines changed

3 files changed

+75
-16
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ yarn run test
6565

6666
See [test-case-recorder.md](docs/test-case-recorder.md).
6767

68-
### Adding new programming languages / syntactic scopes
68+
### Adding a new programming language
69+
70+
See [docs](docs/adding-a-new-language.md).
71+
72+
### Adding syntactic scope types to an existing language
6973

7074
See [parse-tree-patterns.md](docs/parse-tree-patterns.md).
7175

docs/adding-a-new-language.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Adding a new programming language
2+
3+
So you want cursorless to support a new language? Great! Here's how to do it:
4+
5+
## 1. Add support to the [vscode-parse-tree](https://github.com/pokey/vscode-parse-tree) extension
6+
7+
Cursorless relies on the vscode-parse-tree extension to access the parse tree
8+
of a document. See the
9+
[docs](https://github.com/pokey/vscode-parse-tree/#adding-a-new-language) there
10+
for how to add support for a new parser
11+
12+
## 2. Define parse tree patterns in Cursorless
13+
14+
The parse trees exposed by tree-sitter are often pretty close to what we're
15+
looking for, but we often need to look for specific patterns within the parse
16+
tree to get the scopes that the user expects. Fortunately, we have a
17+
domain-specific language that makes these definitions fairly compact.
18+
19+
- Check out the [docs](parse-tree-patterns.md) for the syntax tree pattern
20+
matcher
21+
- You may also find it helpful to look at an existing language, such as
22+
[java](../src/languages/java.ts).
23+
- If you look in the debug console, you'll see debug output every time you move
24+
your cursor, which might be helpful.
25+
- 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 `grammar.js`, which might also be helpful to look at (eg [java](https://github.com/tree-sitter/tree-sitter-java/blob/master/grammar.js)).
26+
27+
## 3. Write tests
28+
29+
Test cases can be automatically recorded, which should speed things up a lot.
30+
See the [docs](test-case-recorder.md) for the test case recorder. It will also
31+
likely be helpful to look at the existing recorded test cases (eg
32+
[java](../src/test/suite/fixtures/recorded/languages/java)) to see how
33+
they
34+
should end up looking when they're recorded.

docs/test-case-recorder.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
# Test case recorder
22

3-
## Record new tests
4-
1. Add voice command
5-
- `cursorless record: user.vscode("cursorless.recordTestCase")`
6-
- We don't want to commit this so add it to your own repository.
3+
We use an automated test case recorder to generate test cases. To use it, you
4+
set up a file the way you'd like (usually a minimal file containing something
5+
like `hello world`), positioning your cursor where you want, tell cursorless to
6+
start recording, and then issue one or more cursorless commands. It works by
7+
recording the initial state of the file including cursor position(s), the
8+
command run, and the final state, all in the form of a yaml document. See
9+
[existing test cases](../src/test/suite/fixtures/recorded) for example outputs.
10+
11+
## Initial setup
12+
13+
1. Add a voice command for recording to your personal talon files:
14+
- `cursorless record: user.vscode("cursorless.recordTestCase")`
15+
- We don't want to commit this so add it to your own repository.
16+
17+
## Recording new tests
18+
719
1. Start debugging (F5)
8-
1. `"cursorless record"`
9-
- List of target directories is shown
20+
1. Create a minimal file to use for recording tests. And position your cursor
21+
where you'd like. Check out the `initialState.documentContents` field of
22+
[existing test cases](../src/test/suite/fixtures/recorded) for examples.
23+
1. Issue the `"cursorless record"` command
24+
- List of target directories is shown. All test cases will be put into the
25+
given subdirectory of `src/test/suite/fixtures/recorded`
1026
1. Select existing directory or create new one
11-
- Select `Create new folder`
12-
- Use `/` to create subdirectories.
27+
- Select `Create new folder`
28+
- If the new directory name contains any `/`, it will create nested
29+
subdirectories.
1330
1. `Recording test cases for following commands` is shown
1431
1. Issue any cursorless voice command
15-
- `"take air"`
32+
- `"take air"`
1633
1. `Cursorless test case saved` is shown
17-
- File created on disk using spoken words as file name
18-
1. Repeat as many voice commands as you want recorded
19-
1. `"cursorless record"`
20-
- `Stopped recording test cases` is shown
21-
- You can also just stop the debugger or close the debug window
34+
- File created on disk using spoken words as file name
35+
1. Repeat as many cursorless voice commands as you want recorded. Each command
36+
you
37+
issue will generate a test case in the form of a yaml file.
38+
1. Issue `"cursorless record"` command again to stop recording
39+
- `Stopped recording test cases` is shown
40+
- You can also just stop the debugger or close the debug window
2241

2342
## Run recorded tests
24-
Recorded tests are run with the normal test and can be run in vscode or via yarn in terminal.
43+
44+
Recorded tests will automatically be picked up and run with the normal tests,
45+
and can be run in vscode or via yarn in terminal.

0 commit comments

Comments
 (0)