Development

Running the latest version of the Language Server in the Visual Studio Code Extension

  • Ensure that a replace statement exists in languageserver/go.mod, so that the language server compiles with the local changes to Cadence.

  • Find the Visual Studio Code preference named "Cadence: Flow Command" and change it to:

    1
    /path/to/cadence/languageserver/run.sh
  • Restart Visual Studio Code

This will automatically recompile the language server every time it is started.

Debugging the Language Server

  • Follow the instructions above (see "Running the latest version of the Language Server in the Visual Studio Code Extension")

  • Attach to the process of the language server started by Visual Studio Code.

    For example, in Goland, choose Run -> Attach to Process.

    This requires gops to be installed, which can be done using go get github.com/google/gops.

Tools

The runtime/cmd directory contains command-line tools that are useful when working on the implementation for Cadence, or with Cadence code:

  • The parse tool can be used to parse (syntactically analyze) Cadence code. By default, it reports syntactical errors in the given Cadence program, if any, in a human-readable format. By providing the -json it returns the AST of the program in JSON format if the given program is syntactically valid, or syntactical errors in JSON format (including position information).

    1
    $ echo "X" | go run ./runtime/cmd/parse
    2
    error: unexpected token: identifier
    3
    --> :1:0
    4
    |
    5
    1 | X
    6
    | ^
    1
    $ echo "let x = 1" | go run ./runtime/cmd/parse -json
    2
    [
    3
    {
    4
    "program": {
    5
    "Type": "Program",
    6
    "Declarations": [
    7
    {
    8
    "Type": "VariableDeclaration",
    9
    "StartPos": {
    10
    "Offset": 0,
    11
    "Line": 1,
    12
    "Column": 0
    13
    },
    14
    "EndPos": {
    15
    "Offset": 8,
    16
    "Line": 1,
    17
    "Column": 8
    18
    },
    19
    [...]
  • The check tool can be used to check (semantically analyze) Cadence code. By default, it reports semantic errors in the given Cadence program, if any, in a human-readable format. By providing the -json it returns the AST in JSON format, or semantic errors in JSON format (including position information).

    1
    $ echo "let x = 1" | go run ./runtime/cmd/check 1 ↵
    2
    error: error: missing access modifier for constant
    3
    --> :1:0
    4
    |
    5
    1 | let x = 1
    6
    | ^
  • The main tools can be used to execute Cadence programs. If a no argument is provided, the REPL (Read-Eval-Print-Loop) is started. If an argument is provided, the Cadence program at the given path is executed. The program must have a function named main which has no parameters and no return type.

    1
    $ go run ./runtime/cmd/main 130 ↵
    2
    Welcome to Cadence v0.12.3!
    3
    Type '.help' for assistance.
    4
    5
    1> let x = 2
    6
    2> x + 3
    7
    5
    1
    $ echo 'pub fun main () { log("Hello, world!") }' > hello.cdc
    2
    $ go run ./runtime/cmd/main hello.cdc
    3
    "Hello, world!"

How is it possible to detect non-determinism and data races in the checker?

Run the checker tests with the cadence.checkConcurrently flag, e.g.

1
go test -race -v ./runtime/tests/checker -cadence.checkConcurrently=10

This runs each check of a checker test 10 times, concurrently, and asserts that the checker errors of all checks are equal.