Skip to content

Add support for solidity #1168

Description

@smarquez1

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 !

Activity

  1. theHamsta commented on Apr 8, 2021

    @theHamsta
    Member

    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-sitter must be executable.

    Seems to work fine. You must set the filetype solidity.

  2. smarquez1 commented on Apr 8, 2021

    @smarquez1
    Author

    wow, thanks for the quick support @theHamsta ! Didn't know that, will test ASAP.

  3. weilbith commented on Jun 7, 2021

    @weilbith

    How does it look? Good to merge? 🙃

  4. vigoux commented on Jun 7, 2021

    @vigoux
    Member

    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.

  5. smarquez1 commented on Jun 7, 2021

    @smarquez1
    Author

    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 ?

  6. smarquez1 commented on Jun 7, 2021

    @smarquez1
    Author

    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#12

    Captura de Pantalla 2021-06-07 a la(s) 19 00 08

  7. JoranHonig commented on Jun 18, 2021

    @JoranHonig
    Contributor

    Hey everyone!

    With the help of @p13nty there are now highlights on the tree-sitter-solidity impl 🚀.

    Let me know if it works 🙌

  8. ibhagwan commented on Jun 30, 2021

    @ibhagwan

    Hey 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:

    image

    Additional output from :checkhealth:

    image

    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_Solidity
    

    EDIT 2: I ran nm -gD .../Solidity.so and discovered the exported symbol was actually tree_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 Solidity to solidity was commited about a week ago, invalidating the original instructions from @theHamsta

    It seems to work now, however, still no syntax highlighting:

    image

    :checkhealth does not show highlight support as well:

    image

  9. ibhagwan commented on Jul 1, 2021

    @ibhagwan

    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 (assuming packer as 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 1760 when opening a .sol file

    Aside from lines 68-69 raising an exception there's also an issue with block comment highlighting, here's how it looks:

    image

    Vs. how it should look (using tomlion/vim-solidity solidity syntax files:

    image

  10. ibhagwan commented on Jul 1, 2021

    @ibhagwan

    @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:
    image

  11. shalzz commented on Aug 4, 2021

    @shalzz

    Hi,

    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.

  12. vigoux commented on Aug 6, 2021

    @vigoux
    Member

    Hi, 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.lua and adding the queries to queries) to make a move.

    We are not solidity experts, so we need your help 😉

  13. clason commented on Jan 17, 2022

    @clason
    Contributor

    Added to the tracking issue, so I'm closing this -- but feel free to use this issue for further discussion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions