Skip to content

Commit f2c9413

Browse files
authored
Merge pull request #149 from ckipp01/contribute
docs: add some basic contributing docs
2 parents b49a1fc + 3e2382c commit f2c9413

File tree

2 files changed

+120
-23
lines changed

2 files changed

+120
-23
lines changed

CONTRIBUTING.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Contributing to tree-sitter-scala
2+
3+
First off, thanks for being willing to contribute to making syntax highlighting
4+
in Scala better! This document will hopefully help you get set up, understand
5+
how to work on the codebase, or link to places to help you understand
6+
tree-sitter.
7+
8+
## Requirements
9+
10+
- Node.js version 18.0 or greater
11+
- C Compiler
12+
13+
Refer to the [tree-sitter
14+
documentation](https://tree-sitter.github.io/tree-sitter/creating-parsers#dependencies)
15+
for more details and specifics.
16+
17+
If you use nix you can enter a nix-shell (`nix-shell .`) which will install them
18+
for you.
19+
20+
## Getting Started
21+
22+
To get started with contributing to the grammar you'll first need to install the
23+
project's dependencies:
24+
25+
```sh
26+
npm install
27+
```
28+
29+
The general flow will often start with adding a test case to `./corpus`. You can
30+
find details on how testing works with tree-sitter
31+
[here](https://tree-sitter.github.io/tree-sitter/creating-parsers#command-test).
32+
33+
Once you've added your test case you'll want to then make the required changes
34+
to `grammar.js`, regenerate and recompile the parser, and run the tests:
35+
36+
```sh
37+
npm run build
38+
npm test
39+
```
40+
41+
Then adjust as necessary. Note that depending on your change you may also have
42+
to touch the `/src/scanner.c` file if you need more advanced features like
43+
look-ahead.
44+
45+
## Syntax highlighting
46+
47+
Right now the most common use-case for syntax highlight using tree-sitter is
48+
[nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter), which
49+
means much of our testing is in relation to it. You can find the syntax
50+
highlighting tests in `test/highlight/*.scala`. You can read more about this
51+
type of testing
52+
[here](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#unit-testing). These test will be automatically ran with `npm run test`.
53+
54+
### tree-sitter highlight
55+
56+
Another way to test your syntax highlighting locally is to use the `tree-sitter
57+
highlight` command. Note that you'll need to have `tree-sitter` installed
58+
globally for this to work. Once you have it installed you'll want to follow the
59+
instructions [here](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#per-user-configuration) to setup a local config that points towards this repo to be used as a parser. Once done you can then do the following:
60+
61+
```sh
62+
tree-sitter highlight some/scala/file.scala
63+
```
64+
65+
And see the syntax highlighting spit out. This is also the format used for
66+
testing, so it provides an easy way to get the output we use for testing.
67+
68+
## Generation
69+
70+
In order to help not cause conflicts with multiple prs being open at the same
71+
time, we don't check in the parser on each pr. Instead, just check in the
72+
changes to the `grammar.js` and the CI will take care of the rest. Each night if
73+
changes are detected it will automatically be generated.
74+
75+
## Smoke testing
76+
77+
You'll noticed that there is a part of CI that checks parsing against the Scala
78+
2 and Scala 3 repositories to ensure we don't introduce unexpected regressions.
79+
The script for this is in `script/smoke_test.sh`. If you're change is increasing
80+
the coverage in either the library or compiler, please do update the expected
81+
percentages at the top of the file.
82+
83+
## Obtaining an error reproduction
84+
85+
_With Neovim_
86+
87+
When creating an issue you'll want to ensure to include the `ERROR` node in it's
88+
context. There's a couple ways to do this. If you're using Neovim and utilizing
89+
treesitter, you can see the tree with `:lua vim.treesitter.show_tree()`. You can
90+
copy it directly from the open panel.
91+
92+
_Manually_
93+
94+
A manual way to get this would be to ensure that when you're in the repo you
95+
have the latest parser with
96+
97+
```sh
98+
npm run build
99+
```
100+
101+
Then you can copy your Scala code in a file and pass that file into `npm run
102+
parse`:
103+
104+
```
105+
npm run parse <path/to/your/file.scala>
106+
```
107+
108+
Then the tree will be printed out for you to copy.
109+

README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,20 @@
22

33
[![Test the grammar](https://github.com/tree-sitter/tree-sitter-scala/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-scala/actions/workflows/ci.yml)
44

5-
Scala grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
5+
Scala grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
6+
covering both Scala 2 and 3.
67

7-
References
8+
## References
89

9-
- [The Scala Language Specification](https://www.scala-lang.org/files/archive/spec/2.13/)
10-
- [Scala Syntax Summary](https://www.scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html)
10+
_Scala 2_
11+
- [The Scala 2 Language Specification](https://www.scala-lang.org/files/archive/spec/2.13/)
12+
- [Scala 2 Syntax Summary](https://www.scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html)
1113

12-
## Development
14+
_Scala 3_
1315

14-
Requirements:
16+
- [Scala 3 Syntax Summary](https://docs.scala-lang.org/scala3/reference/syntax.html)
1517

16-
- Node.js version 6.0 or greater
17-
- C Compiler
18+
## Development and Contributing
1819

19-
Refer to the [tree-sitter documentation](https://tree-sitter.github.io/tree-sitter/creating-parsers#dependencies) for more details. If you use nix you can enter a nix-shell (`nix-shell .`) which will install them for you.
20-
21-
Then, install the project's dependencies:
22-
23-
```sh
24-
npm install
25-
```
26-
27-
Add a test case to `./corpus`, make the required changes to `grammar.js`,
28-
regenerate and recompile the parser, and run the tests:
29-
30-
```sh
31-
npm run build
32-
npm test
33-
```
20+
Please refer to the [CONTRIBUTING.md](./CONTRIBUTING.md) for instructions on
21+
getting set up.

0 commit comments

Comments
 (0)