/cadence-for-intellij-platform

Plugin for supporting Cadence Language in Intellij Platform IDEs

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Flow Logo

Flow - Cadence Support for Intellij Platform

Support for Cadence, the resource-oriented smart contract language of Flow, in Intellij Platform IDEs.
Get the plugin

Report a Problem / Request a Feature

Table of Contents
  1. About The Project
  2. Installation
  3. Getting Started
  4. Roadmap
  5. Contributing

About the Project

Usage Screenshot

Getting Started

Installation

  • You can download the plugin by searching the marketplace in your Intellij Platform IDE
  • Alternative you can get it from the Jetbrains Marketplace
  • For the semantic analysis through the language server to work, you need to:
    1. Ensure you have flow-cli installed. Running the command flow should works from any terminal (aka it is in your PATH).
    2. Ensure you have a file with the initial configuration, or generate one (named flow.json) by running flow init.
    3. Go to Settings -> Tools -> Cadence Settings and set the location of your flow.json.
    4. You can also edit the rest of the settings if you want
    5. Restart Intellij. (In a future release this will be improved so that this step is not needed)
  • ⚠️ If you get an error Can't start server due to Cannot run program "flow" ... No such file or directory, please go to Settings -> Tools -> Cadence Settings, set the absolute path to the flow executable, and restart the IDE

Usage

Syntax Highlighting

  • The plugin will be immediately associated with any .cdc files and provide syntax highlighting.
  • It will follow the different themes / color schemes you choose from your IDE
  • You can customize the colors by going to Settings -> Editor -> Color Scheme -> Cadence

Language Server Protocol Support

  • To utilize the LSP support, ensure you followed the installation instructions
  • If the Language Server is working correctly, you will see a green circle on the bottom toolbar (with information on hover)
  • You can configure the settings for the LSP under Settings -> Tools -> Cadence LSP settings
  • Note: After changing settings, a restart is required for them to take effect. This will be addressed in a future release

Compatibility

All Intellij Platform products, from version 2021.2 and up:

  • IntelliJ IDEA Ultimate
  • IntelliJ IDEA Community
  • IntelliJ IDEA Educational
  • PyCharm Professional
  • PyCharm Community
  • PyCharm Educational
  • GoLand
  • RubyMine
  • CLion
  • PhpStorm
  • WebStorm
  • Rider
  • Code With Me Guest
  • Android Studio
  • DataSpell
  • DataGrip
  • JetBrains Gateway
  • MPS
  • AppCode

Roadmap

  • Refine syntax highlighting
  • Improve support for Language Server Protocol

Contributing

  • Everyone is welcome to contribute, through issues reporting or pull requests
  • Feel free to open an issue before you start working on it, to avoid duplicate work

Building the project

  • Open project with Intellij
  • From project structure, set the project SDK to a JDK 11, and the language level to 11
  • From project structure -> modules -> main, click the edit on the "gen" folder under sources and check the checkbox to mark it as generated
  • Go to Cadence.bnf and from the context menu Generate Parser Code
  • Go to Cadence.flex and from the context menu Run JFlex Generator
  • Build the project (run the gradle build task)
  • Run the gradle task runide
  • On the new IDE that runs, if you open a .cdc file you should see the plugin working
  • If you make changes on the code, generate any sources needed, and run the runide again
  • If after changes you see "strange" results, it's a good idea to actually delete the gen folder and rerun the generations

Making changes to the language recognition

Cadence.bnf

  • Declares the high level Token types
  • All declared types will be available as return types at Cadence.flex
  • After changing you must generate parser code (control+shift+g)
  • It is good idea to also first delete the gen folder

Cadence.flex

  • Used to define the regexes that recognise the tokens
  • Generates the Lexer using JFlex
  • After changing you must Run JFlex generator (control+shift+g)
  • First rule that matches wins
  • You can have states, in which you declare the rules that apply only there

Making changes to the highlighting

Once a token is being recognised in the PSI structure, to add highlighting for it, you need to update:

  • CadenceSyntaxHighlighter for the actual highlighting
  • CadenceColorSettingsPage to add new tokens to the Color Scheme page of the IDE

Supporting Cadence Language Server Protocol

  • The Language Server Protocol server provided by Cadence is utilized
  • To provide the support the library lsp4intellij is used
  • Settings and functionality for logging input / output commands to LSP server for local debugging are available

Making a release (only for maintainers)

  • Ensure everything is ready
  • Make any required changes to build.gradle (version, changelog, release channel)
  • commit, and push
  • sign the plugin (for now using the sign-plugin.sh , will need to update the version)
  • tag version: git tag -a v1.4 -m "Version 1.4"
  • push tag git push 1.4
  • make a release in github. Add the generated signed zip found under /build/distribution
  • Go to plugins.jetbrains.com and upload new version
  • Wait for approval
  • Test that it works