Skip to content

Commit b2ae3f0

Browse files
authored
Merge pull request #15 from heyAyushh/rc-v0.2.4
Release Candidate v0.2.4
2 parents 206ae9f + 1ebadfe commit b2ae3f0

15 files changed

+252
-92
lines changed

CHANGELOG.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
# Change Log
22

33
All notable changes to the 'vscode-anchor' extension will be documented in this file.
4+
5+
## Version 0.2.4 [current]
6+
### Added
7+
- Support for Anchor Version Manager (avm)
8+
- Scaffolding projects Improvements #12
9+
- Test against local validator
10+
11+
### Changed
12+
- Install command now uses avm to install Anchor and Other versions.
13+
- Edit buttons on views for programs and tests are now replaced with default name click to open file.
414

5-
## Version 0.2.3 [current]
15+
### Fixed
16+
- Anchor tests were not visible in pane #13
17+
18+
---
19+
## Version 0.2.3
620
### Added
721
- Added Help Commands to your favourite docs site.
822
- Analyze your code with Soteria, Cargo Audit, and clippy.

assets/dark/local_validator.svg

+6
Loading

assets/light/local_validator.svg

+6
Loading

package.json

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Anchor",
44
"publisher": "Ayushh",
55
"description": "vscode extension for Anchor (Solana's Sealevel runtime Framework)",
6-
"version": "0.2.3",
6+
"version": "0.2.4",
77
"icon": "assets/marketplace-logo.png",
88
"homepage": "https://github.com/microsoft/vscode-anchor/blob/main/README.md",
99
"galleryBanner": {
@@ -99,6 +99,10 @@
9999
"command": "vscode-anchor.test",
100100
"title": "Anchor: Test"
101101
},
102+
{
103+
"command": "vscode-anchor.testAgainstLocalValidator",
104+
"title": "Anchor: Test against local validator"
105+
},
102106
{
103107
"command": "vscode-anchor.upgrade",
104108
"title": "Anchor: Upgrade (use Solana's upgradeable BPF loader to upgrade the onchain program code)"
@@ -178,6 +182,14 @@
178182
"light": "assets/light/edit.svg",
179183
"dark": "assets/dark/edit.svg"
180184
}
185+
},
186+
{
187+
"command": "vscode-anchor-view-tests.skipLocalValidator",
188+
"title": "Start test with local-validator",
189+
"icon": {
190+
"light": "assets/light/local_validator.svg",
191+
"dark": "assets/dark/local_validator.svg"
192+
}
181193
}
182194
],
183195
"menus": {
@@ -206,13 +218,17 @@
206218
"command": "vscode-anchor-view-tests.test",
207219
"when": "view == vscode-anchor-view-tests",
208220
"group": "navigation"
221+
},
222+
{
223+
"command": "vscode-anchor-view-tests.skipLocalValidator",
224+
"when": "view == vscode-anchor-view-tests",
225+
"group": "navigation"
209226
}
210227
],
211228
"view/item/context": [
212229
{
213230
"command": "vscode-anchor-view-programs.editEntry",
214-
"when": "view == vscode-anchor-view-programs && viewItem == program",
215-
"group": "inline"
231+
"when": "view == vscode-anchor-view-programs && viewItem == program"
216232
},
217233
{
218234
"command": "vscode-anchor-view-programs.buildVerifiableItem",
@@ -221,8 +237,7 @@
221237
},
222238
{
223239
"command": "vscode-anchor-view-tests.editEntry",
224-
"when": "view == vscode-anchor-view-tests && viewItem == test",
225-
"group": "inline"
240+
"when": "view == vscode-anchor-view-tests && viewItem == test"
226241
}
227242
]
228243
},

src/commands/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { anchorBuild, anchorBuildVerifiable, anchorRemoveDockerImage } from "./build";
2-
import { anchorTest } from "./test";
2+
import { anchorTest, anchorTestLocalValidator } from "./test";
33
import { anchorVerify } from "./verify";
44
import { anchorInit } from "./scaffold";
55
import { anchorNew } from "./new";
@@ -20,6 +20,7 @@ const commands = [
2020
anchorNew(),
2121
anchorRemoveDockerImage(),
2222
anchorTest(),
23+
anchorTestLocalValidator(),
2324
anchorUpgrade(),
2425
anchorVerify(),
2526
];

src/commands/install.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import * as vscode from 'vscode';
22
import { EXT_NAME } from "../config";
3-
import checkInstallAnchor from "../helpers/install";
43
import chan from "../helpers/outputChannel";
4+
import { checkAvm, installAnchorUsingAvm, installAvm } from "../helpers/avm";
55

66
export const anchorInstall = () => vscode.commands.registerCommand(
77
`${EXT_NAME}.install`,
88
async () => {
99
try{
10-
// check and install anchor
11-
checkInstallAnchor();
10+
try {
11+
await checkAvm();
12+
} catch (err) {
13+
await installAvm();
14+
} finally {
15+
await installAnchorUsingAvm();
16+
}
1217
} catch(err) {
1318
if(err instanceof Error) {
1419
chan.appendLine(err.message);

src/commands/scaffold.ts

+53-22
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,75 @@
11
import { spawnChan } from "../helpers/spawnExec";
22
import * as vscode from 'vscode';
33
import { EXT_NAME } from "../config";
4-
import chan from "../helpers/outputChannel";
4+
import chan, { appendChan } from "../helpers/outputChannel";
5+
import path = require("path");
56

67
const anchorInit = () => vscode.commands.registerCommand(
78
`${EXT_NAME}.scaffold`,
89
async () => {
9-
const item = await vscode
10-
.window
11-
.showQuickPick(['init (default)', 'Synthetify/solana-template'], {
12-
placeHolder: 'init or synthetify template',
13-
});
14-
if (!item) {
15-
return;
16-
}
10+
try {
11+
const item = await vscode
12+
.window
13+
.showQuickPick(['init (default)', 'Synthetify/solana-template'], {
14+
placeHolder: 'init or synthetify template',
15+
});
16+
if (!item) {
17+
return;
18+
}
1719

18-
const name = await vscode
19-
.window
20-
.showInputBox({
21-
placeHolder: 'Enter Project name: <uwu defi>',
22-
});
23-
if (!name) {
24-
return;
25-
}
20+
const name = await vscode
21+
.window
22+
.showInputBox({
23+
placeHolder: 'Enter Project name: <uwu defi>',
24+
});
25+
if (!name) {
26+
return;
27+
}
28+
29+
const options: vscode.OpenDialogOptions = {
30+
canSelectMany: false,
31+
openLabel: 'Select root of scaffold project',
32+
canSelectFiles: false,
33+
canSelectFolders: true
34+
};
35+
const cwd = await vscode
36+
.window
37+
.showOpenDialog(options);
38+
if (!cwd || !cwd[0]) {
39+
return;
40+
}
2641

27-
if (item && name) {
2842
if (item === 'init (default)') {
29-
spawnChan(`anchor`, ['init', name], 'Scaffolding Anchor Project');
43+
await spawnChan(`anchor`, ['init', name], 'Scaffolding Anchor Project', cwd[0].fsPath);
3044
} else if (item === 'Synthetify/solana-template') {
3145
try {
32-
spawnChan(`npx`, ['degit', `https://github.com/${item}`, name], 'Scaffolding Anchor Project');
33-
vscode.window.showInformationMessage(`Anchor ⚓: init Synthetify template completed!`);
46+
await spawnChan(`npx`, ['degit', `https://github.com/${item}`, name], 'Scaffolding Anchor Project', cwd[0].fsPath);
3447
} catch (err) {
35-
vscode.window.showErrorMessage(`Anchor ⚓: init Synthetify template faled!`);
48+
vscode.window.showErrorMessage(`Anchor ⚓: init Synthetify template failed!`);
3649
if (err instanceof Error) {
3750
chan.append(err?.message);
3851
chan.show(true);
3952
}
4053
}
4154
}
55+
56+
const openInWorkspace = await vscode
57+
.window
58+
.showWarningMessage('Jump into the Anchor project?', 'yesss lfg', 'later maybe');
59+
60+
if (openInWorkspace === 'yesss lfg') {
61+
const uri = vscode.Uri.file(path.join(`${cwd[0].fsPath}`,`${name}`));
62+
await vscode.commands.executeCommand('vscode.openFolder', uri);
63+
await vscode.window.showInformationMessage(`Anchor ⚓: Jumping to your ${name} anchor project!`);
64+
}
65+
66+
return true;
67+
} catch (err) {
68+
if (err instanceof Error) {
69+
chan.show(true);
70+
appendChan('ERROR', err?.message);
71+
};
72+
return false;
4273
}
4374
}
4475
);

src/commands/test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ const anchorTest = () => vscode.commands.registerCommand(
1515
}
1616
);
1717

18+
const anchorTestLocalValidator = () => vscode.commands.registerCommand(
19+
`${EXT_NAME}.testAgainstLocalValidator`,
20+
async () => {
21+
vscode.window.withProgress({
22+
location: vscode.ProgressLocation.Notification,
23+
title: "Anchor ⚓: Starting Tests against local validator...",
24+
cancellable: false
25+
}, async (progress, token) => {
26+
await spawnChan('anchor',['test', '--skip-local-validator'], 'test');
27+
});
28+
}
29+
);
30+
1831
export {
1932
anchorTest,
33+
anchorTestLocalValidator
2034
};

src/extension.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import * as vscode from "vscode";
1+
import { ExtensionContext } from "vscode";
22
import commands from "./commands";
33
import checkInstallAnchor from "./helpers/install";
44
import { registerViews } from "./views";
5-
import { TestItem, TestsProvider } from "./views/tests";
65

7-
export async function activate(context: vscode.ExtensionContext) {
8-
6+
export async function activate(context: ExtensionContext) {
97
// check and install anchor
108
checkInstallAnchor();
119
registerViews();

src/helpers/avm.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as vscode from 'vscode';
2+
import chan, { appendChan } from "./outputChannel";
3+
import { spawnChan } from "./spawnExec";
4+
5+
export const avmList = async () => spawnChan('avm', ['list'], 'avm list', '', true);
6+
export const checkAvm = async () => spawnChan('avm', ['--version'], 'avm version', '', true);
7+
export const installAvm = async () => vscode.window.withProgress({
8+
location: vscode.ProgressLocation.Notification,
9+
title: `Installing Anchor Version Manager ⚓ ...`,
10+
cancellable: false
11+
}, async (progress, token) => {
12+
try {
13+
const isInstalled = await spawnChan(`cargo`,
14+
['install', '--git', 'https://github.com/project-serum/anchor', 'avm', '--locked', '--force'],
15+
'Install Anchor cli', '', true
16+
);
17+
return Promise.resolve(isInstalled);
18+
} catch (err) {
19+
if (err instanceof Error) {
20+
chan.appendLine(err.message);
21+
chan.show(true);
22+
}
23+
return Promise.reject(err);
24+
}
25+
});
26+
27+
28+
export const installAnchorUsingAvm = async () => {
29+
try {
30+
const listBuffer = (await avmList())?.stdout;
31+
const list = listBuffer?.toString().split('\n').reverse().filter(Boolean);
32+
if (!list || !list.length) {
33+
appendChan('ERROR', `avm list ERROR`);
34+
chan.show(true);
35+
return;
36+
}
37+
38+
const quickPick = await vscode.window.showQuickPick(list, {
39+
placeHolder: 'Select a version of Anchor to use',
40+
});
41+
if (!quickPick) {
42+
return;
43+
}
44+
const version = quickPick.split('\t')[0];
45+
46+
vscode.window.withProgress({
47+
location: vscode.ProgressLocation.Notification,
48+
title: `Installing Anchor ⚓ CLI ${version}...`,
49+
cancellable: false
50+
}, async (progress, token) => {
51+
const isInstalled = await spawnChan('avm', ['install', version], `avm install ${version}`);
52+
return Promise.resolve(isInstalled);
53+
});
54+
} catch (err) {
55+
if (err instanceof Error) {
56+
chan.appendLine(err.message);
57+
chan.show(true);
58+
}
59+
return Promise.reject(err);
60+
}
61+
};

src/helpers/install.ts

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import * as vscode from "vscode";
2-
import chan from "./outputChannel";
3-
import { execShell, spawnChan } from "./spawnExec";
4-
import * as os from 'os';
5-
6-
export const installAnchor = async () => {
7-
vscode.window.withProgress({
8-
location: vscode.ProgressLocation.Notification,
9-
title: "Installing Anchor ⚓ CLI...",
10-
cancellable: false
11-
}, async (progress, token) => {
12-
if (os.arch() === 'x64' && os.type() === 'Linux') {
13-
spawnChan('npm',['i', '-g', '@project-serum/anchor-cli'], 'install');
14-
} else {
15-
spawnChan('cargo', ['install', '--git', 'https://github.com/project-serum/anchor', '--tag', 'v0.20.1', 'anchor-cli', '--locked'],
16-
'build anchor cli from source');
17-
}
18-
});
19-
};
2+
import chan, { appendChan } from "./outputChannel";
3+
import { spawnChan } from "./spawnExec";
4+
import { checkAvm, installAnchorUsingAvm, installAvm } from "./avm";
205

216
export default async function checkInstallAnchor() {
227
try {
23-
await execShell('anchor --version');
8+
await spawnChan('anchor', ['--version'], 'anchor version', '', true);
249
} catch (err) {
2510
// if anchor is not installed
2611
if (err instanceof Error && err?.message?.includes("not found")) {
@@ -34,7 +19,20 @@ export default async function checkInstallAnchor() {
3419
);
3520

3621
if (selection === "Install it") {
37-
installAnchor();
22+
try {
23+
try {
24+
await checkAvm();
25+
} catch (err) {
26+
appendChan('INFO', `Installing Anchor version manager...`);
27+
await installAvm();
28+
}
29+
await installAnchorUsingAvm();
30+
} catch (err) {
31+
if (err instanceof Error) {
32+
chan.appendLine(err.message);
33+
chan.show(true);
34+
};
35+
}
3836
} else {
3937
chan.appendLine("Anchor CLI was not found and not Installed! ngmi");
4038
chan.show(true);

0 commit comments

Comments
 (0)