Skip to content

Commit

Permalink
Improve install behavior on Windows
Browse files Browse the repository at this point in the history
Installing the grammar from `build/grammar.js` works for normal install
commands but leaves the user unable to run `tree-sitter` commands from
the current directory. That's because specifying a `grammar.js` path
causes the CLI to skip writing a `grammar.json` (which is debatably a
bug in the CLI). Other scripts currently work around this by running
`tree-sitter generate` themselves, relying on a symlink into the build
directory. That doesn't work on Windows, though.

This changes the install script so that it copies the `grammar.js` into
the current directory and then uses the copied one. With this change, we
get our `grammar.json` simply by running `npm install`!
  • Loading branch information
alex-pinkus committed Jan 16, 2022
1 parent 7e359f4 commit 05e21aa
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- run: npm install
- run: npm run ci
- run: npm run test-ci
- run: cargo test
- run: cd ./test-npm-package && npm test; cd ..
- name: Publish parser source
uses: actions/upload-artifact@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
/test
Cargo.lock
/target/*
/grammar.js
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-swift"
description = "swift grammar for the tree-sitter parsing library"
version = "0.1.0"
version = "0.1.1"
keywords = ["incremental", "parsing", "swift"]
categories = ["parsing", "text-editors"]
repository = "https:/alex-pinkus/tree-sitter-swift"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use this parser to parse Swift code, you'll want to depend on either the Rust
To use the Rust crate, you'll add this to your `Cargo.toml`:
```
tree-sitter = "0.20.0"
tree-sitter-swift = "=0.1.0"
tree-sitter-swift = "=0.1.1"
```

Then you can use a `tree-sitter` parser with the language declared here:
Expand All @@ -35,7 +35,7 @@ let tree = parser.parse(&my_source_code, None)
To use this from NPM, you'll add similar dependencies to `package.json`:
```
"dependencies: {
"tree-sitter-swift": "0.1.0",
"tree-sitter-swift": "0.1.1",
"tree-sitter": "^0.20.0"
}
```
Expand Down
1 change: 0 additions & 1 deletion grammar.js

This file was deleted.

5 changes: 5 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file exists to flag to the `tree-sitter` CLI that we are a proper grammar directory, to work
// around some inflexibility in the CLI. However, it will get replaced at install-time with totally
// different contents. Do not check in these changes!

// You can ignore this file's changes using `git update-index --skip-worktree grammar.js`.
Loading

0 comments on commit 05e21aa

Please sign in to comment.