extension.rst 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, see :ref:`language-status` for a brief overview.
  20. You can choose between the following targets:
  21. solana
  22. Solidity for Solana
  23. polkadot
  24. Solidity for Polkadot (Substrate contracts pallet)
  25. evm
  26. Solidity for any EVM based chain like Ethereum
  27. Note that the language server has support for EVM, but Hyperledger Solang does
  28. not support compiling for EVM.
  29. Using the extension
  30. -------------------
  31. The extension can be found on the `Visual Studio Marketplace <https://marketplace.visualstudio.com/items?itemName=solang.solang>`_.
  32. When started for the first time, the extension will download the Solang binary. Once this is done, it should just automatically work.
  33. Updates are downloaded when made available. However, you should set the blockchain target in the extension settings.
  34. .. image:: extension-config.png
  35. Development
  36. -----------
  37. The code is spread over two parts. The first part the vscode extension client code,
  38. `written in TypeScript <https://github.com/hyperledger-solang/solang/tree/main/vscode>`_.
  39. This part deals with syntax highlighting, and calling out to the Solang language server when
  40. needed. The client needs `npm and node installed <https://docs.npmjs.com/downloading-and-installing-node-js-and-npm>`_.
  41. The client implementation is present in
  42. `src/client <https://github.com/hyperledger-solang/solang/tree/main/vscode/src/client>`_.
  43. The extension client code is in
  44. `src/client/extension.ts <https://github.com/hyperledger-solang/solang/tree/main/vscode/src/client/extension.ts>`_.
  45. Secondly, there is the language server which is written in Rust.
  46. The Solang binary has a subcommand ``language-server``, which starts the
  47. `built-in language server <https://github.com/hyperledger-solang/solang/blob/main/src/bin/languageserver/mod.rs>`_.
  48. Once you have node and npm installed, you can build the extension like so:
  49. .. code-block:: bash
  50. git clone https://github.com/hyperledger-solang/solang
  51. cd solang/vscode
  52. npm install
  53. npm install -g vsce
  54. vsce package
  55. You should now have an extension file called ``solang-0.3.4.vsix`` which can be
  56. installed using ``code --install-extension solang-0.3.4.vsix``.
  57. Alternatively, the extension is run from vscode itself.
  58. 1. Inside a vscode instance, Ctrl+Shift+B to build the project
  59. 2. On the task bar at the bottom of the IDE select Launch Client
  60. 3. Open a Solidity file (.sol) to test the extension.
  61. To run the tests:
  62. 1. Inside a vscode instance, Ctrl+Shift+B to build the project
  63. 2. On the task bar at the bottom of the IDE select Extensions tests
  64. 3. The result should be displayed in the debug console of the host IDE instance.