Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO MERGE] Extension Development Improvements #162

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tools/vscode-extension/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "extensionHost",
"request": "launch",
"name": "Launch Extension",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"]
}
]
}
23 changes: 16 additions & 7 deletions tools/vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ and have configured the [`code` command line interface](https://code.visualstudi

### Using the Flow CLI

The recommended way to install the latest released version is to use the Flow CLI.
The recommended way to install the latest released version is to use the Flow CLI.

```shell script
brew tap dapperlabs/homebrew && brew install flow-cli
```

Check that it's been installed correctly.

```shell script
flow version
```

Next, use the CLI to install the VS Code extension.

```shell script
flow cadence install-vscode-extension
```
Expand All @@ -33,49 +36,55 @@ Restart VS Code and the extension should be installed!

### Building

If you are building the extension from source, you need to build both the
If you are building the extension from source, you need to build both the
extension itself and the Flow CLI (if you don't already have a version installed).
Unless you're developing the extension or need access to unreleased features,
Unless you're developing the extension or need access to unreleased features,
you should use the Flow CLI option. It's much easier!

#### VS Code Extension
Make sure you are in this `vscode-extension` directory.

Make sure you are in this `vscode-extension` directory.

If you haven't already, install dependencies.

```shell script
npm install
```

Next, build and package the extension.

```shell script
npm run package
```

This will result in a `.vsix` file containing the packaged extension.
This will result in a `.vsix` file containing the packaged extension.

Install the packaged extension.

```shell script
code --install-extension cadence-*.vsix
```

Restart VS Code and the extension should be installed!

#### FLow CLI
#### Flow CLI

Make sure you are in the root directory.

Build the Flow CLI.

```shell script
make cmd/flow/flow
```

Move the resulting binary (`cmd/flow/flow`) into your `$PATH`. For example:

```shell script
mv ./cmd/flow/flow /usr/local/bin/
```

Restart your terminal and check to ensure it was installed correctly.

```shell script
flow version
```

12 changes: 12 additions & 0 deletions tools/vscode-extension/images/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions tools/vscode-extension/images/flow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 0 additions & 21 deletions tools/vscode-extension/out/test/extension.test.js

This file was deleted.

1 change: 0 additions & 1 deletion tools/vscode-extension/out/test/extension.test.js.map

This file was deleted.

23 changes: 0 additions & 23 deletions tools/vscode-extension/out/test/index.js

This file was deleted.

1 change: 0 additions & 1 deletion tools/vscode-extension/out/test/index.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion tools/vscode-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions tools/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@
],
"main": "./out/extension.js",
"contributes": {
"viewsContainers": {
"activitybar": [
{
"id": "flow-explorer",
"title": "Flow Explorer",
"icon": "images/flow.svg"
}
]
},
"views": {
"flow-explorer": [
{
"id": "flowAccounts",
"name": "Flow Accounts"
},
{
"id": "flowContracts",
"name": "Deployed Contract"
}
]
},
"commands": [
{
"command": "cadence.restartServer",
Expand Down Expand Up @@ -47,6 +68,14 @@
"title": "Switch account"
}
],
"menus": {
"view/title": [
{
"command": "cadence.createAccount",
"when": "view == flowAccounts"
}
]
},
"configuration": {
"title": "Cadence",
"properties": {
Expand Down
78 changes: 78 additions & 0 deletions tools/vscode-extension/src/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { addAddressPrefix } from "./address";
import { Extension } from "./extension";
export const SERVICE_ADDR: string = "f8d6e0586b0a20c7";

export class AccountsService {
numAccounts: number;
// Set of created accounts for which we can submit transactions.
// Mapping from account address to account object.
list: Array<Account>;
// Index of the currently active account.
activeAccount: number;

ext: Extension | undefined;

constructor(numAccounts: number) {
this.numAccounts = numAccounts;
this.list = [new Account(0, SERVICE_ADDR)];
this.activeAccount = 0;
this.ext = undefined;
}

init(ext: Extension) {
this.ext = ext;
}

addAccount(address: string) {
const index = this.list.length;
const account = new Account(index, address);
this.list.push(account);
this.ext &&
this.ext.accountsTreeView.accountsTreeViewDataProvider.refresh();
}

setActiveAccount(index: number) {
this.activeAccount = index;
}

getActiveAccount(): Account {
return this.list[this.activeAccount];
}

getAccount(index: number): Account | null {
if (index < 0 || index >= this.list.length) {
return null;
}

return this.list[index];
}

// Resets account state
resetAccounts() {
this.list = [new Account(0, SERVICE_ADDR)];
this.activeAccount = 0;
}
}

export class Account {
index: number;
address: string;

constructor(index: number, address: string) {
this.index = index;
this.address = address;
}

name(): string {
return this.index === 0 ? "Service Account" : `Account ${this.index}`;
}

fullName(): string {
return `${this.name()} (${addAddressPrefix(this.address)})`;
}
}

export function createAccountsService(numAccounts: number) {
const accountsService = new AccountsService(numAccounts);
return accountsService;
}
Loading