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

Add syntax highlighting for Solidity #1853

Closed
slinlee opened this issue Mar 22, 2022 · 3 comments · Fixed by #1854
Closed

Add syntax highlighting for Solidity #1853

slinlee opened this issue Mar 22, 2022 · 3 comments · Fixed by #1854
Labels
A-tree-sitter Area: Tree-sitter C-enhancement Category: Improvements

Comments

@slinlee
Copy link
Contributor

slinlee commented Mar 22, 2022

This is the only result I've come across so far for tree-sitter support for Solidity https://github.com/JoranHonig/tree-sitter-solidity

I tried adding it in languages.toml, but I get the following errors:

[[grammar]]
name = "solidity"
source = { git = "https://github.com/JoranHonig/tree-sitter-solidity", rev = "5585e0739a248137d9561d835a915efb2db5ac3d" }
  Grammar 'iex' is already built.
  Grammar 'erlang' is already built.
  Grammar 'rescript' is already built.
  Grammar 'kotlin' is already built.
  Grammar 'org' is already built.
  Grammar 'hcl' is already built.

  --- stderr
  thread 'main' panicked at 'Failed to compile tree-sitter grammars: Failed to build some grammar(s)

  Caused by:
      0: Failed to compare source and binary timestamps
      1: No such file or directory (os error 2)', helix-term/build.rs:20:26
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
     1: core::panicking::panic_fmt
               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
     2: core::result::unwrap_failed
               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
     3: core::result::Result<T,E>::expect
     4: build_script_build::main
     5: core::ops::function::FnOnce::call_once
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `helix-term v0.6.0 (/home/slin/code/helix/helix-term)`, intermediate artifacts can be found at `/home/slin/code/helix/target`

Caused by:
  build failed


Is there anything obvious I'm doing incorrectly?

Related: I added LSP support in #1848

@slinlee slinlee added the C-enhancement Category: Improvements label Mar 22, 2022
@the-mikedavis
Copy link
Member

The problem is that the grammar .gitignores the src/ directory (see here). Helix's build process for grammars currently requires the generated src/ directory which is all the C/C++ files you need to compile the parser.

We've run into this with a few grammar repositories and the usual fix is to depend on a fork that checks src/ into git1. For example, tree-sitter-rescript depends on a fork. If you'd like to set one of these up, you'll need to install the tree-sitter-cli, remove that src line from the .gitignore, run tree-sitter generate, and check in all the files that creates.

Footnotes

  1. I have some thoughts on a way around this but it isn't very close to being in helix yet :)

@the-mikedavis the-mikedavis added the A-tree-sitter Area: Tree-sitter label Mar 22, 2022
@slinlee
Copy link
Contributor Author

slinlee commented Mar 22, 2022

Thanks, @the-mikedavis . I created a fork that includes the src/ dir with the generated files. Using that in languages.toml I was able to build and install hx but the syntax highlighting isn't showing up:

$ hx --health solidity
Configured language server: solc
Binary for language server: /snap/bin/solc
Configured debug adapter: None
Highlight queries: Not found
Textobject queries: Not found
Indent queries: Not found

Where can I look for more details for debugging?

@the-mikedavis
Copy link
Member

So now that you have the parser installed, you'll just need to add some tree-sitter queries (check out the docs here: https://github.com/helix-editor/helix/blob/master/book/src/guides/adding_languages.md#queries). You'll want to create a runtime/queries/solidity directory and copy over the queries/highlights.scm from the tree-sitter-solidity repository. Those queries look pretty good but some will need to be updated to follow the captures helix uses. For example @property should get translated into @variable.other.member. I think the @number capture is the only other one that needs to be replaced.

(Eventually I'd like to show whether the parser is available in the --health [LANG] read-out, I need to set myself a reminder for that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tree-sitter Area: Tree-sitter C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants