alex-pinkus / tree-sitter-swift

A tree-sitter grammar for the Swift programming language.
MIT License
142 stars 37 forks source link

Integration with tree-sitter: ast-grep installation fails seemingly due to tree-sitter-swift's dependency definition #386

Closed grembo closed 7 months ago

grembo commented 7 months ago

Hi,

This issue could also be left at tree-sitter or ast-grep, but it feels like this is the best place to start.

When building some versions of ast-grep (including the latest 0.19.4 - e.g. cargo install ast-grep), the build fails with:

error[E0277]: the trait bound `TSLanguage: From<tree_sitter::Language>` is not satisfied
  --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ast-grep-language-0.19.4/src/parsers.rs:69:35
   |
69 |     tree_sitter_swift::language().into()
   |                                   ^^^^ the trait `From<tree_sitter::Language>` is not implemented for `TSLanguage`
   |
   = help: the trait `From<tree_sitter::Language>` is implemented for `TSLanguage`
   = note: required for `tree_sitter::Language` to implement `Into<TSLanguage>`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `ast-grep-language` (lib) due to previous error
error: failed to compile `ast-grep v0.19.4`, intermediate artifacts can be found at `/tmp/cargo-install43pB9W`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

Without digging too deep, it seems like to be caused by a combination of a new release of tree-sitter and this dependency in Cargo.toml:

[dependencies]
tree-sitter = ">=0.20.4, <0.23.0"

Changing it to

tree-sitter = ">= 0.20, < 0.21"

or

tree-sitter = "=0.20.4"

fixes the build.

alex-pinkus commented 7 months ago

Hmm, ok. I did that in the hopes of avoiding a lockstep-bump of major version (i.e. having to release 0.5.0 to match tree-sitter’s 0.23.1) but it looks like Cargo’s dependency resolver ends up just bundling both versions.

I can check, but it sounds like ast-grep is still on 0.20.x, is that right? So I should just go back to matching that?

grembo commented 7 months ago

I can check, but it sounds like ast-grep is still on 0.20.x, is that right? So I should just go back to matching that?

Yes, it seems like it, so I think this would be the way to go. Once you tag a release, I can open a PR at ast-grep (or you can do that, if you prefer)


tree-sitter-lua-0.0.19/Cargo.toml.orig:tree-sitter = "0.20"
tree-sitter-css-0.20.0/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-elixir-0.1.1/Cargo.toml.orig:tree-sitter = ">= 0.19, < 0.21"
tree-sitter-kotlin-0.3.5/Cargo.toml.orig:tree-sitter = "0.20"
tree-sitter-javascript-0.20.4/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-scala-0.20.3/Cargo.toml.orig:tree-sitter = "0.20.7"
tree-sitter-json-0.20.2/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-rust-0.20.4/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-swift-0.4.2/Cargo.toml.orig:tree-sitter = ">=0.20.4, <0.23.0"
tree-sitter-swift-0.4.2/Cargo.toml.orig:tree-sitter = "0.20.4"
tree-sitter-php-0.22.2/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-cpp-0.20.5/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-facade-sg-0.9.2/Cargo.toml.orig:tree-sitter = "0.20"
ast-grep-tree-sitter-c-sharp-0.20.0/Cargo.toml.orig:tree-sitter = "0.20"
tree-sitter-bash-0.20.5/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-typescript-0.20.5/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-ruby-0.20.1/Cargo.toml.orig:tree-sitter = "0.20.10"
tree-sitter-python-0.20.4/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-c-0.20.8/Cargo.toml.orig:tree-sitter = "~0.20.10"
tree-sitter-go-0.20.0/Cargo.toml.orig:tree-sitter = ">= 0.20, < 0.21"
tree-sitter-dart-0.0.3/Cargo.toml.orig:tree-sitter = "0.20.8"
tree-sitter-java-0.20.2/Cargo.toml.orig:tree-sitter = ">= 0.19, < 0.21"
tree-sitter-html-dvdb-0.20.0/Cargo.toml.orig:tree-sitter = "~0.20.10"
alex-pinkus commented 7 months ago

OK, published 0.4.3 that goes back to exclusively supporting 0.20.x: https://crates.io/crates/tree-sitter-swift/0.4.3

I admit, I am a bit skeptical of how the tree-sitter ecosystem plans to migrate to 0.23 -- it seems like all the grammars are just holding back. If individual grammar repos can't do cross-MV support like this, it's going to take a long time to shore up.

grembo commented 7 months ago

I admit, I am a bit skeptical of how the tree-sitter ecosystem plans to migrate to 0.23 -- it seems like all the grammars are just holding back. If individual grammar repos can't do cross-MV support like this, it's going to take a long time to shore up.

I don’t know much about the tree-sitter ecosystem (I’m basically just a user whose CI process broke), but from what I’ve seen I would agree to your assertion.

Thank you for the ultra-quick response! 🙏

HerringtonDarkholme commented 7 months ago

tree-sitter's new release is pretty hard to upgrade. All grammars need to be updated for a multi-language tool to be upgraded :/

https://github.com/ast-grep/ast-grep