Repository navigation
Add support for solidity #1168
Description
Activity
- addedenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
on Apr 8, 2021 You can test it with https://github.com/nvim-treesitter/playground
Put this in your config
-- *Must* be *S*olidity not solidity require "nvim-treesitter.parsers".get_parser_configs().Solidity = { install_info = { url = "https://github.com/JoranHonig/tree-sitter-solidity", files = {"src/parser.c"}, requires_generate_from_grammar = true, }, filetype = 'solidity' }
Restart and run
:TSInstall Solidity. You need to have the tree-sitter-cli installed.tree-sittermust be executable.Seems to work fine. You must set the filetype
solidity.Reacted by N3wborn, Rohit Garg, Eliaz Bobadilla and Anawow, thanks for the quick support @theHamsta ! Didn't know that, will test ASAP.
How does it look? Good to merge? 🙃
Not really sure, I think this was more intended as a quick hack to enable the support of solidity.
No PR open regarding this if I remember well.Sorry guys, didn't have the time to check if this works correctly and/or create a PR and I'm not working on Solidity anymore. I think the issue could still be useful for people who want to add Solidity treesitter support for Neovim. Did you try it @weilbith ?
OK, I just tried it and it seems to be working properly after setting
set ft=solidity.
The current status seems to be that the parser is working correctly (as you can see in the screenshot below) but the highlights are still not implemented, that work is being done here: JoranHonig/tree-sitter-solidity#12Reacted by Thore Strassburg, vigoux, cds-amal and N3wbornHey everyone!
With the help of @p13nty there are now highlights on the tree-sitter-solidity impl 🚀.
Let me know if it works 🙌
Reacted by N3wborn, ibhagwan and Ricardo MadrizHey everyone!
With the help of @p13nty there are now highlights on the tree-sitter-solidity impl rocket.
Let me know if it works raised_hands
Tysm @JoranHonig!
I'm still not getting highlights though, it's very possible I'm doing something wrong as I just started using nvim 0.5 with TS, I followed the instructions in this thread, compiled the Solidity parser, I can see it's loaded in the TS modules but for some reason the highlight feature still appears as missing.
Output from
:TSModuleInfo:Additional output from
:checkhealth:EDIT 1: Installed
nvim-treesitter\playground, when used on a solidity file I get the below error:Error executing vim.schedule lua callback: Failed to load parser: uv_dlsym: /home/bhagwan/.local/share/nvim/site/pack/packer/start/nvim-treesitter/parser/Solidity.so: undefined symbol: tree_sitter_SolidityEDIT 2: I ran
nm -gD .../Solidity.soand discovered the exported symbol was actuallytree_sitter_solidity(hence the error above) so I changed the setup from:require "nvim-treesitter.parsers".get_parser_configs().Solidity = {...}
To:
require "nvim-treesitter.parsers".get_parser_configs().solidity = {...}`
The renaming of the grammer from
Soliditytosoliditywas commited about a week ago, invalidating the original instructions from @theHamstaIt seems to work now, however, still no syntax highlighting:
:checkhealthdoes not show highlight support as well:So I was able to make highlights work, the steps were as follows:
- Download queries\highlights.scm into
~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/solidity(assumingpackeras plugin manager):
curl -L https://raw.githubusercontent.com/JoranHonig/tree-sitter-solidity/master/queries/highlights.scm \ -o ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/solidity/highlights.scm- Edit the file and comment out lines 68-69, otherwise you'll get the error
treesitter/highlighter: Error executing lua: ...TDZW/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: error at position 1760when opening a.solfile
Aside from lines 68-69 raising an exception there's also an issue with block comment highlighting, here's how it looks:
Vs. how it should look (using
tomlion/vim-soliditysolidity syntax files:Reacted by svitax and AlbertReacted by Phuoc- Download queries\highlights.scm into
@JoranHonig, I was able to fix the block comment issue, copied the regex from tree-sitter-c and, created PR #14.
As you can see below, the comment block is accurately identified:
Reacted by Thore Strassburg, Sergio Márquez and N3wbornReacted by PhuocHi,
Any update on this? I'm still not able to get highlighting working with this.
If highlighting works for someone, would appreciate if you could share the config here.Reacted by N3wborn and Trent RandHi, for now solidity is not supported at all, we are waiting for someone to make a pull request adding solidity support (that is, adding it the the
parsers.luaand adding the queries toqueries) to make a move.We are not solidity experts, so we need your help 😉
Added to the tracking issue, so I'm closing this -- but feel free to use this issue for further discussion!
Language informations
Would love to have Solidity support, it's the language created to write Ethereum contracts.
The language is takes many syntactical ideas from JavaScript.
I found an attempt to support it's grammar here: https://github.com/JoranHonig/tree-sitter-solidity but don't know how to test it.
Here's more info on how the author wrote it: https://joranhonig.nl/incremental-parsing-of-solidity/
Thanks for your effort @JoranHonig !