Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How did you make the extension that depends on tree-sitter work cross-platform? #40

Closed
Symbolk opened this issue Aug 4, 2021 · 8 comments

Comments

@Symbolk
Copy link

Symbolk commented Aug 4, 2021

Hi, I am very excited to find this project! I am also developing a VSCode extension based on LSP and tree-sitter, which is used to help developers to resolve merge conflicts: https://github.com/Symbolk/somanyconflicts/

However, now I am in front of a severe issue: I am developing on mac, and I built and published it in the VSCode market, but according to my users, this version cannot be run on windows, for the error: "tree-sitter-runtime is not a valid Win32 Application". Therefore, I tried to rebuild the module and extension on windows, now it runs but the query will report error that do not exist on mac: 'Query error of type TSQueryErrorSyntax at position 1'

I saw yours depends on web-tree-sitter and somehow uses the WASM, but I failed to figure whether and how can this solve the cross-platform issue, can you help me? Ideally I do not want to have two versions for different OSs.

@sogaiu
Copy link

sogaiu commented Aug 4, 2021

I learned a bit more detail about this here.

IIUC, the reason the cross-platform issue is addressed is because the WASM bits are platform-independent.

@Symbolk
Copy link
Author

Symbolk commented Aug 4, 2021

I learned a bit more detail about this here.

IIUC, the reason the cross-platform issue is addressed is because the WASM bits are platform-independent.

Thanks! I will check it out.

@sogaiu
Copy link

sogaiu commented Aug 4, 2021

@Symbolk jeff-hykin mentioned here about another VSCode extension that uses tree-sitter and WASM.

I think it's this one: https://github.com/EvgeniyPeshkov/syntax-highlighter

If you haven't had a look, may be it would be of interest to you -- it seems like it might be better maintained at this point in time.

@jeff-hykin
Copy link

jeff-hykin commented Aug 4, 2021

@Symbolk here's the commit for when this extension switched to using wasm, which made it work cross platform with no extra effort.

Commit: 7ef1ce9
createParser is the function you'll probably want to talk a look at

@Symbolk
Copy link
Author

Symbolk commented Aug 16, 2021

@jeff-hykin @sogaiu Hi, I managed to switch to web-tree-sitter in this way:

Symbolk/somanyconflicts@47a94de
Symbolk/somanyconflicts@3412c8e
Symbolk/somanyconflicts@3e19b56

I am not sure whether I am doing it correctly, though the debugging and running under macOS&Win10 seem basically good!

However, there are some remaining issues that I need your help:

  1. In my old version which depends on the node binding, I need to init a Query object with 2 arguments (https://github.com/Symbolk/somanyconflicts/blob/0834d4e9c903b4d3512d34c8f1cfde5e81b219aa/src/SoManyConflicts.ts#L91). However, the web-tree-sitter the TreeSitter.Query() expects 0 arguments, so I have to temporarily remove arguments to build:
-      const treeQuery = new TreeSitter.Query(specification, queryString)
+      const treeQuery = new TreeSitter.Query()

But the query is necessary for my extension, is there anyway to use Query with query string?

  1. I am not sure whether the parser is loaded correctly, but the TreeSitter.parse() seems to return nothing, I tried to print the parsed tree, but no results printed in any cases:

https://github.com/Symbolk/somanyconflicts/blob/3e19b56c77d67e1dcd2059ae221590e6030c66b5/src/SoManyConflicts.ts#L100

Any hint is a great help!

@sogaiu
Copy link

sogaiu commented Aug 16, 2021

@Symbolk It's been quite a while since I've looked at these details so I'm not sure how much help I can be.

There are a few things that occur to me though.

For 1., IIUC, the web-tree-sitter tests seem to indicate that querying can be handed a string: https://github.com/tree-sitter/tree-sitter/blob/master/lib/binding_web/test/query-test.js#L57-L60 -- may be studying how that's done in that file could be helpful?

For 2., IIUC, the elm folks use web-tree-sitter in their language server which is written in TypeScript: https://github.com/elm-tooling/elm-language-server/blob/main/package.json#L31 -- may be you can get some hints from looking in their source?

One more thing is that the tree-sitter repository has a discussions area: https://github.com/tree-sitter/tree-sitter/discussions -- it might be that there are folks who can help you better there.

Good luck!

Sorry I don't have good answers for you.

@Symbolk
Copy link
Author

Symbolk commented Aug 16, 2021

@sogaiu No, your answer is amazing! I think it solves the both problems!

@Symbolk
Copy link
Author

Symbolk commented Aug 19, 2021

Thanks for the nice answers from you, loving Github!

@Symbolk Symbolk closed this as completed Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants