onflow/cadence-tools

[LS] Use the state for account storage

Closed this issue · 3 comments

Problem
The language server should use flow.json configuration for accounts and expose more functionality such as deploying project contracts, etc.
Currently, when a user starts the LS client we create some accounts for the user, but those accounts are logically separate from those in flow.json which makes the whole thing quite confusing and it doesn't leverage the flowkit capability of using those generated accounts for sending transactions (we need to build and send those manually) but more importantly it doesn't provide more functionality of deploying contracts defined in flow.json.

Solution
Refactor the code so it adds the newly created accounts on top of the existing ones using the flowkit state API. We should also create the accounts defined in flow.json for the user during the setup.
The client can then detect if the flow.json is present and if so, allows the user to automatically deploy all the contracts configured. Down the line another feature could come where it would even migrate to a state.

I believe this why I am getting this LSP error in my flow project:

cannot find declaration 'PetStore' in 'f8d6e0586b0a20c7.PetStore'. available exported declarations are:

^ I didn't forget to add exported declarations. This is the entire LSP error message.

This is the import:

import PetStore from 0xf8d6e0586b0a20c7

My project has a single contract called PetStore. And here is my flow.json

{
  "networks": {
    "emulator": "127.0.0.1:3569",
    "mainnet": "access.mainnet.nodes.onflow.org:9000",
    "testnet": "access.devnet.nodes.onflow.org:9000"
  },
  "accounts": {
    "emulator-account": {
      "address": "f8d6e0586b0a20c7",
      "key": "615ba59f794b991829b017c93bf560c6d0829b8e67f5fea3a1b4348aef9df3db"
    }
  },
  "contracts": {
    "PetStore": "./src/flow/contracts/PetStore.cdc"
  },
  "deployments": {
    "emulator": {
      "emulator-account": ["PetStore"]
    }
  }
}

I realized separate accounts are being used when looking up the accounts list in VSCode (Alice, Bob, Charlie). emulator-account is not on that list. And if LSP doesn't load accounts defined in flow.json it will not detect imports correctly.

We will be fixing this soon, it's a known issue. If you have any more feedback or ideas on this let us know! Sorry for the inconvenience. We are also happy if you want to contribute and help us with this.

This is now implemented #48