extension.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Visual Studio Code Extension
  2. ============================
  3. Solang has
  4. a `language server <https://en.wikipedia.org/wiki/Language_Server_Protocol>`_ built
  5. into the executable, which can be used by the Visual Studio Code extension, or by
  6. any editor that can use a lsp language server. The Visual Studio Code
  7. extension provides the following:
  8. 1. Syntax highlighting.
  9. 2. Compiler warnings and errors displayed in the problems tab and marked
  10. with squiggly lines.
  11. 3. Additional information when hovering over variables, types, functions, etc.
  12. For example, this will give the struct fields when hovering over a variable
  13. which is a reference to a struct.
  14. .. image:: extension-screenshot.png
  15. Both the Visual Studio Code extension code and the language server were developed under a
  16. `Hyperledger Mentorship programme <https://wiki.hyperledger.org/display/INTERN/Create+a+new+Solidity+Language+Server+%28SLS%29+using+Solang+Compiler>`_.
  17. Solidity Language flavour
  18. -------------------------
  19. The Solidity language flavour depends on what target you are compiling for. For
  20. example:
  21. * Ethereum style address literals like ``0xE0f5206BBD039e7b0592d8918820024e2a7437b9`` are
  22. not supported on Substrate or Solana, but are supported for EVM.
  23. * On Substrate and Solana, base58 style encoded address literals like
  24. ``address"5GBWmgdFAMqm8ZgAHGobqDqX6tjLxJhv53ygjNtaaAn3sjeZ"`` are supported, but
  25. not with EVM.
  26. * On Solana, there is special builtin import file called ``'solana'`` available.
  27. * Different blockchains offer different builtins. See the :ref:`builtins documentation <builtins>`.
  28. * See :ref:`language-status` for compatiblity with Ethereum Solidity (solc)
  29. * There are many more differences, which are noted throughout the documentation.
  30. You can choose the between the following targets:
  31. solana
  32. Solidity for Solana
  33. substrate
  34. Solidity for Substrate (Polkadot)
  35. evm
  36. Solidity for any EVM based chain like Ethereum
  37. Note that the language server has support for EVM, but Hyperledger Solang does
  38. not support compiling for EVM (yet).
  39. Using the extension
  40. -------------------
  41. The extension can be found on the `Visual Studio Marketplace <https://marketplace.visualstudio.com/items?itemName=solang.solang>`_.
  42. When started for the first time, the extension will download the Solang binary. Once this is done, it should just automatically work.
  43. Updates are downloaded when made available. However, you should set the blockchain target in the extension settings.
  44. .. image:: extension-config.png
  45. Development
  46. -----------
  47. The code is spread over two parts. The first part the vscode extension client code,
  48. `written in TypeScript <https://github.com/hyperledger/solang/tree/main/vscode>`_.
  49. This part deals with syntax highlighting, and calling out to the Solang language server when
  50. needed. The client needs `npm and node installed <https://docs.npmjs.com/downloading-and-installing-node-js-and-npm>`_.
  51. The client implementation is present in
  52. `src/client <https://github.com/hyperledger/solang/tree/main/vscode/src/client>`_.
  53. The extension client code is in
  54. `src/client/extension.ts <https://github.com/hyperledger/solang/tree/main/vscode/src/client/extension.ts>`_.
  55. Secondly, there is the language server which is written in Rust.
  56. The Solang binary has a subcommand ``language-server``, which starts the
  57. `built-in language server <https://github.com/hyperledger/solang/blob/main/src/bin/languageserver/mod.rs>`_.
  58. Once you have node and npm installed, you can build the extension like so:
  59. .. code-block:: bash
  60. git clone https://github.com/hyperledger/solang
  61. cd solang/vscode
  62. npm install
  63. npm install -g vsce
  64. vsce package
  65. You should now have an extension file called solang-0.3.0.vsix which can be
  66. installed using ``code --install-extension solang-0.3.0.vsix``.
  67. Alternatively, the extension be run from vscode itself.
  68. 1. Inside a vscode instance, Ctrl+Shift+B to build the project
  69. 2. On the task bar at the bottom of the IDE select Launch Client
  70. 3. Open a Solidity file (.sol) to test the extension.
  71. To run the tests:
  72. 1. Inside a vscode instance, Ctrl+Shift+B to build the project
  73. 2. On the task bar at the bottom of the IDE select Extensions tests
  74. 3. The result should be displayed in the debug console of the host IDE instance.