Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Example in README #4

Open
albfan opened this issue Nov 9, 2018 · 11 comments
Open

Example in README #4

albfan opened this issue Nov 9, 2018 · 11 comments

Comments

@albfan
Copy link

albfan commented Nov 9, 2018

if I try the example in README

document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_arithmetic')

creates a nilClass, so I cannot modify later to tree_sitter_python

Using tree_sitter_python directly it works

@kwerle
Copy link

kwerle commented Nov 11, 2018

Guh. Did I not just leave a comment? This worked even less for me:

➜  ~ docker run -it ruby bash
root@6a1c331bcfaf:/# export TREE_SITTER_PARSER_DIR=/tree-sitter
root@6a1c331bcfaf:/# mkdir /tree-sitter
root@6a1c331bcfaf:/# gem install tree-sitter
Fetching: tree-sitter-0.1.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed tree-sitter-0.1.0
1 gem installed

root@6a1c331bcfaf:/# irb 
irb(main):001:0> require 'tree-sitter'
=> true
irb(main):002:0> document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_arithmetic')
Traceback (most recent call last):
        4: from /usr/local/bin/irb:11:in `<main>'
        3: from (irb):2
        2: from (irb):2:in `new'
        1: from (irb):2:in `initialize'
TreeSitter::DocumentError (/usr/local/bundle/gems/tree-sitter-0.1.0/lib/tree-sitter/treesitter.so: undefined symbol: tree_sitter_arithmetic)

irb(main):003:0> document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_pyton')
Traceback (most recent call last):
        4: from /usr/local/bin/irb:11:in `<main>'
        3: from (irb):3
        2: from (irb):3:in `new'
        1: from (irb):3:in `initialize'
TreeSitter::DocumentError (/usr/local/bundle/gems/tree-sitter-0.1.0/lib/tree-sitter/treesitter.so: undefined symbol: tree_sitter_pyton)

@albfan
Copy link
Author

albfan commented Nov 11, 2018

@kwerle, you miss an h in tree_sitter_pyton, it is tree_sitter_python

@kwerle
Copy link

kwerle commented Nov 11, 2018

Doh! Still - same result:

irb(main):005:0> document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_python')
Traceback (most recent call last):
        4: from /usr/local/bin/irb:11:in `<main>'
        3: from (irb):5
        2: from (irb):5:in `new'
        1: from (irb):5:in `initialize'
TreeSitter::DocumentError (/usr/local/bundle/gems/tree-sitter-0.1.0/lib/tree-sitter/treesitter.so: undefined symbol: tree_sitter_python)

@albfan
Copy link
Author

albfan commented Nov 11, 2018

@kwerle, I guess you're not building correctly ruby-tree-sitter. The bootstrap step takes some iterations for me but:

export TREE_SITTER_PARSER_DIR=test/tree-sitter/fixtures/parsers 
bundler update
bundle update
script/bootstrap 
bundler update
script/bootstrap 
script/test 
script/console 
===> Bundling...
==> Initing Git submodules
==> Installing gem dependencies…
===> Launching...
[1] pry(main)> document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_python')
=> #<TreeSitter::Document:0x00005647d293a218>
[2] pry(main)> print document.root_node
(module (expression_statement (binary_operator (identifier) (binary_operator (identifier) (integer)))))=> nil

just works

@gjtorikian about this issue:

$ script/console 
===> Bundling...
==> Initing Git submodules
==> Installing gem dependencies…
===> Launching...
[1] pry(main)> document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_foo')
TreeSitter::DocumentError: /home/alberto/projects/tree-sitter/ruby-tree-sitter/lib/tree-sitter/treesitter.so: undefined symbol: tree_sitter_foo
from (pry):1:in `initialize'
[2] pry(main)> document.language = "tree_sitter_python"
NoMethodError: undefined method `language=' for nil:NilClass
from (pry):2:in `<main>'
[3] pry(main)> 

NoMethodError: undefined method `language=' for nil:NilClass

@kwerle
Copy link

kwerle commented Nov 11, 2018

When I use a gem I expect it to 'just work'. The following trivial project doesn't work, and it seems like it should:

https://github.com/kwerle/tree-sitter-project

@maxbrunsfeld
Copy link

👋 This gem is still somewhat experimental, and it’s using an older version of Tree-sitter. I personally maintain the node and rust bindings, but not this one.

@albfan
Copy link
Author

albfan commented Nov 11, 2018

@maxbrunsfeld fair enough for me. Basic example works, so this is a matter of maintainer updating this repo

@gjtorikian
Copy link
Contributor

@albfan Sorry this didn't work for you! I will look into it within the week. I'm re-opening the issue because I want to track it for updating the dependencies.

When I use a gem I expect it to 'just work'. The following trivial project doesn't work, and it seems like it should:

@kwerle I am sorry your expectations were unfulfilled. Most open source is volunteer work. If there's some unexpected behavior, you can log it and move on.

@gjtorikian gjtorikian reopened this Nov 12, 2018
@kwerle
Copy link

kwerle commented Nov 12, 2018

Hey - I totally get it! In fact, this is a blocker for
kwerle/ide-ruby#16

And it's not blocking ide-ruby at all - this is just an alternative to the native stuff I have working. Sounded interesting so I figured I'd take a shot!

Thank you for your work!

@albfan
Copy link
Author

albfan commented Nov 12, 2018

@gjtorikian, count on me to do new tries on this. It was just I prefer you to rule the issue, so let's fix this.

Get a nilClass for me is correct, so among correct the example there's no much to fix here.

Update the codebase to support existing parsers would be the core thing for me

@gjtorikian
Copy link
Contributor

Yeah, in looking at the code, I'm actually pretty unhappy with the requirement of TREE_SITTER_PARSER_DIR overall. In assumes that you will not be adding more parser in the future, which doesn't make sense (ie. you need to install/build the gem with a specific set of existing parsers in a directory, and can't add more at runtime). I'm rewriting a lot of the internals to just support that use case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants