First things first, you need to install the cairo-lang package, preferably in a virtual env you can later use and upgrade. Currently only python 3.7 and 3.8 is supported
python3 -m venv ~/cairo_venv
source ~/cairo_venv/bin/activate
You can also add an alias in .bashrc
to quickly source the cairo env file in the future
alias source_cairo='source /home/$USER/cairo_venv/bin/activate'
It is also recommended to install starknet-devnet for local testing
pip install starknet-devent
For further info checkout the cairo-lang quick-start
To easily get auto-complete functionality as well as some just-to-definition functionality, you can use the cairo language server cairo-ls
Installation instructions for vim functionality:
-
Install Coc
-
In an empty directory, run
npm install cairo-ls
. This can also be installed as a global dir, then your DIR in step 3 is~/
or a direct path to the user home dir -
Run Vim, then use
:CocConfig
command to editcoc-settings.json
with the following:
{
"languageserver": {
"cairo": {
"module": "YOUR_DIRECTORY_FROM_STEP_2/node_modules/cairo-ls/out/server.js",
"args": ["--node-ipc"],
"filetypes": ["cairo"],
"rootPatterns": [".git/"]
}
}
}
- Add the following to
~/.vimrc
au BufReadPost *.cairo set filetype=cairo
au Filetype cairo set syntax=cairo
- Optionally you can add the Coc's example Vim configuration to
~/.vimrc
For syntax highlighting, download https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/lang/ide/vim/syntax/cairo.vim to ~/.vim/syntax/
The cairo virtual env comes with the executable cairo-format
that formats the cairo code with pre-defined conventions.
The executable receives the -i
tag to modify and save the file in place
To Run the auto-format code on-save when using vim, add this to your vimrc:
:autocmd BufWritePost *.cairo silent ! cairo-format % -i 2> /dev/null
This will format the current buffer in place. The command will do nothing if cairo_venv
is not activated