Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Feature/command provider poc #204

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
001c69d
feat: command provider poc
michaeljohnbennett Jul 20, 2022
0ed7d89
fix: adding in tests and typings to make chai/mocha work
michaeljohnbennett Jul 26, 2022
dabb72a
Merge remote-tracking branch 'origin/develop' into feature/command-pr…
michaeljohnbennett Aug 1, 2022
af4eaaa
fix: adjusting provider
michaeljohnbennett Aug 1, 2022
e8c58b6
fix: adjusting provider
michaeljohnbennett Aug 5, 2022
8126c63
Merge remote-tracking branch 'origin/develop' into feature/command-pr…
michaeljohnbennett Aug 11, 2022
2e804e2
fix: rework again after merging
michaeljohnbennett Aug 11, 2022
27f20a7
fix: added logging wrapper
michaeljohnbennett Aug 15, 2022
b13ae39
Merge remote-tracking branch 'origin/develop' into feature/command-pr…
michaeljohnbennett Aug 15, 2022
b8904b6
fix: added in compiler
michaeljohnbennett Aug 15, 2022
18b9882
fix: cleanup comments
michaeljohnbennett Aug 24, 2022
5d84c97
fix: merging in changes from develop
michaeljohnbennett Nov 1, 2022
ecd92be
fix: logging fixed
michaeljohnbennett Nov 1, 2022
e002cb6
fix: project based compilation working
michaeljohnbennett Nov 1, 2022
b8f3da9
fix: cleaning up code
michaeljohnbennett Nov 7, 2022
9ae11c7
fix: lots of refactoring
michaeljohnbennett Nov 9, 2022
2c0f847
fix: lots of refactoring
michaeljohnbennett Nov 14, 2022
3c01bfe
fix: tests
michaeljohnbennett Nov 16, 2022
90a7f12
Merge branch 'develop' into feature/command-provider-poc
michaeljohnbennett Nov 16, 2022
7bfb7fe
chore: removing copyright cleanup
michaeljohnbennett Nov 17, 2022
75e4935
chore: post merge refactor/cleanup
michaeljohnbennett Nov 18, 2022
19a3be6
fix: broken integration tests
michaeljohnbennett Nov 21, 2022
5ed78f4
fix: windows paths on CICD
michaeljohnbennett Nov 21, 2022
3addbe8
Merge branch 'develop' into feature/command-provider-poc
michaeljohnbennett Nov 29, 2022
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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
"default": false,
"description": "Disable notification on long running tasks."
},
"truffle-vscode.storageAccount.name": {
"type": "string",
"scope": "Storage Account name"
},
"truffle-vscode.coreSDK": {
"type": "string",
"scope": "Core SDK for extensions backend",
Expand Down Expand Up @@ -764,6 +760,8 @@
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@types/big.js": "^6.1.2",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/copy-webpack-plugin": "^8.0.1",
"@types/download": "^6.2.4",
"@types/estree": "^0.0.52",
Expand All @@ -780,7 +778,7 @@
"@types/rewire": "^2.5.28",
"@types/rimraf": "^3.0.2",
"@types/semver": "^6.0.0",
"@types/sinon": "^7.0.11",
"@types/sinon": "^10.0.13",
"@types/source-map": "^0.5.2",
"@types/uuid": "^3.4.4",
"@types/vscode": "1.66.0",
Expand All @@ -789,6 +787,8 @@
"@vscode/debugadapter": "^1.55.1",
"@vscode/debugprotocol": "^1.55.1",
"@vscode/test-electron": "^2.1.3",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"copy-webpack-plugin": "^10.0.0",
"copyfiles": "^2.4.1",
"decache": "^4.5.1",
Expand All @@ -797,13 +797,13 @@
"husky": "^8.0.1",
"istanbul": "^0.4.5",
"lint-staged": "^8.2.0",
"mocha": "^6.2.3",
"mocha": "^10.0.0",
"mockery": "^2.1.0",
"prettier": "2.7.1",
"pretty-quick": "^3.1.3",
"remap-istanbul": "^0.13.0",
"rewire": "^4.0.1",
"sinon": "^7.3.2",
"sinon": "^14.0.2",
"truffle": "^5.5.30",
"ts-loader": "9.3.1",
"ts-node": "^10.8.1",
Expand Down
2 changes: 1 addition & 1 deletion resources/ganache/assets/icons/contract.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/ganache/assets/icons/events.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: 12 additions & 1 deletion src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export enum RequiredApps {
dashboard = 'dashboard',
}

export enum OptionalApps {
hardhat = 'hardhat',
}
export type AppTypes = RequiredApps | OptionalApps;

export enum NotificationOptions {
error = 'error',
info = 'info',
Expand Down Expand Up @@ -119,6 +124,10 @@ export class Constants {
max: '',
min: '5.5.0',
},
[OptionalApps.hardhat]: {
max: '',
min: '2.9.0',
},
};

public static telemetryEvents = {
Expand Down Expand Up @@ -607,6 +616,8 @@ export class Constants {
FetchingBoxesHasFailed: 'An error occurred while fetching boxes',
ContractFolderNotExists: 'There is no contract directory in this workspace',
UriHandlerError: 'Badly formatted. Ensure that the command and arguments are described correctly',
HHNoDefaultDeploy:
'Hardhat has no default deploy command. Consider using the HardHat Deploy Plugin: [hardhat-deploy](https://github.com/wighawag/hardhat-deploy)',
};

public static informationMessage = {
Expand Down Expand Up @@ -678,11 +689,11 @@ export class Constants {
};
public static userSettings = {
coreSdkSettingsKey: 'truffle-vscode.coreSDK',
storageAccountUserSettingsKey: 'truffle-vscode.storageAccount.name',
};

public static coreSdk = {
truffle: 'Truffle',
hardhat: 'Hardhat',
};

public static initialize(context: ExtensionContext) {
Expand Down
2 changes: 2 additions & 0 deletions src/Output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export enum OutputLabel {
requirements = 'Truffle: Requirements',
telemetryClient = 'Truffle: Telemetry Client',
treeManager = 'Truffle: Service Tree Manager',
sdkCoreCommands = 'Truffle: SDK Commands',
hardhatCommands = 'Truffle: Hardhat Commands',
}

export class Output {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/DebuggerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {DEBUG_TYPE} from '@/debugAdapter/constants/debugAdapter';
import {DebugNetwork} from '@/debugAdapter/debugNetwork';
import {TransactionProvider} from '@/debugAdapter/transaction/transactionProvider';
import {Web3Wrapper} from '@/debugAdapter/web3Wrapper';
import {getTruffleWorkspace, getPathByPlatform} from '@/helpers/workspace';
import {getWorkspaceForUri} from '@/helpers/AbstractWorkspace';
import {showInputBox, showQuickPick} from '@/helpers/userInteraction';
import {getPathByPlatform} from '@/helpers/WorkspaceHelpers';
import {Telemetry} from '@/TelemetryClient';
import {DebuggerTypes} from '@/debugAdapter/models/debuggerTypes';

Expand All @@ -19,7 +20,7 @@ export namespace DebuggerCommands {
export async function startSolidityDebugger() {
Telemetry.sendEvent('DebuggerCommands.startSolidityDebugger.commandStarted');

const workspaceUri = (await getTruffleWorkspace()).workspace;
const workspaceUri = (await getWorkspaceForUri()).workspace;
const workingDirectory = getPathByPlatform(workspaceUri);
const debugNetwork = new DebugNetwork(workingDirectory);
await debugNetwork.load();
Expand Down Expand Up @@ -95,7 +96,7 @@ async function getQuickPickItems(txProvider: TransactionProvider) {

/**
* Responsible for starting the Solidity debugger with the given arguments.
*
*
@param args The `DebugArgs` to initialize the `DebugSession`.
*/
export async function startDebugging(args: DebuggerTypes.DebugArgs): Promise<void> {
Expand Down
44 changes: 44 additions & 0 deletions src/commands/HardhatCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2022. Consensys Software Inc. All rights reserved.
// Licensed under the MIT license.

import {Constants, NotificationOptions, OptionalApps} from '@/Constants';

import {outputCommandHelper} from '@/helpers';
import {required} from '@/helpers/required';
import {showIgnorableNotification, showNotification} from '@/helpers/userInteraction';
import {AbstractWorkspace} from '@/helpers/AbstractWorkspace';
import {Output, OutputLabel} from '@/Output';
import {Telemetry} from '@/TelemetryClient';
import {commands, Uri} from 'vscode';

export async function buildContracts(ws: AbstractWorkspace, uri?: Uri): Promise<void> {
Telemetry.sendEvent('HardhatCommands.buildContracts.commandStarted');
if (!(await required.checkAppsSilentForUri(ws.workspace, OptionalApps.hardhat))) {
Telemetry.sendEvent('HardhatCommands.buildContracts.hardhatInstallationMissing');
await showNotification({
message: 'Hardhat is not installed, please install to continue...',
type: NotificationOptions.error,
});
// await required.installHardhat(required.Scope.locally);
return;
}

const workspaceDir = ws.workspace.fsPath;

Output.outputLine(OutputLabel.hardhatCommands, `compiling: ${JSON.stringify(uri)} : ${workspaceDir}`);
const args: string[] = [OptionalApps.hardhat, 'compile'];

// hardhat will compile all contracts, not one specifically.
Output.outputLine(
OutputLabel.hardhatCommands,
`Building: ${args} DIR: ${workspaceDir} Workspace: ${JSON.stringify(ws)} `
);

await showIgnorableNotification(Constants.statusBarMessages.buildingContracts, async () => {
Output.show();
await outputCommandHelper.executeCommand(workspaceDir, 'npx', args.join(' '));
commands.executeCommand('truffle-vscode.views.deployments.refresh');

Telemetry.sendEvent('HardhatCommands.buildContracts.commandFinished');
});
}
65 changes: 45 additions & 20 deletions src/commands/SdkCoreCommands.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
// Copyright (c) Consensys Software Inc. All rights reserved.
// Licensed under the MIT license.

import {Memento, window, Uri} from 'vscode';
import {Constants} from '@/Constants';
import {userSettings} from '../helpers';
import {IExtensionAdapter, TruffleExtensionAdapter} from '@/services/extensionAdapter';
import {getWorkspaceForUri, WorkspaceType} from '@/helpers/AbstractWorkspace';
import {Output, OutputLabel} from '@/Output';

import {
HardHatExtensionAdapter,
IExtensionAdapter,
TruffleExtensionAdapter,
UnknownExtensionAdapter,
} from '@/services/extensionAdapter';
import {Uri, window} from 'vscode';

class SdkCoreCommands {
private extensionAdapter!: IExtensionAdapter;

public async initialize(_globalState: Memento): Promise<void> {
const sdk = await this.getCoreSdk();
this.extensionAdapter = this.getExtensionAdapter(sdk.userValue ? sdk.userValue : sdk.defaultValue);
this.extensionAdapter.validateExtension().catch((error) => {
window.showErrorMessage(error.message);
});
private extensionAdapters = new Map<string, IExtensionAdapter>();

public getExtensionAdapter(sdkVal: WorkspaceType): IExtensionAdapter | undefined {
if (this.extensionAdapters.has(sdkVal)) {
return this.extensionAdapters.get(sdkVal);
}
// let's initialise it otherwise
const adapter = this.initExtensionAdapter(sdkVal);
adapter.validateExtension().then(
(_) => {
Output.outputLine(
OutputLabel.sdkCoreCommands,
`Configuration Initialized. SdkCoreProvider: ${adapter.constructor.name}`
);
},
(error) => {
window.showErrorMessage(error.message);
}
);
this.extensionAdapters.set(sdkVal, adapter);
return adapter;
}

/**
Expand All @@ -23,7 +42,10 @@ class SdkCoreCommands {
* @param contractUri if provided, it is the `Uri` of the smart contract to be compiled.
*/
public async build(contractUri?: Uri): Promise<void> {
return this.extensionAdapter.build(contractUri);
const ws = await getWorkspaceForUri(contractUri);
const buildUri = contractUri ? contractUri : ws.workspace;
const adapter = this.getExtensionAdapter(ws.workspaceType);
return adapter!.build(ws, buildUri);
}

/**
Expand All @@ -32,17 +54,20 @@ class SdkCoreCommands {
* @param contractUri FIXME: Is this used?
*/
public async deploy(contractUri?: Uri): Promise<void> {
return this.extensionAdapter.deploy(contractUri);
const ws = await getWorkspaceForUri(contractUri);
const deployUri = contractUri ? contractUri : ws.workspace;
const adapter = this.getExtensionAdapter(ws.workspaceType);
return adapter!.deploy(ws, deployUri);
}

private async getCoreSdk() {
return userSettings.getConfigurationAsync(Constants.userSettings.coreSdkSettingsKey);
}

private getExtensionAdapter(sdk: string): IExtensionAdapter {
private initExtensionAdapter(sdk: WorkspaceType): IExtensionAdapter {
switch (sdk) {
default:
case WorkspaceType.HARDHAT:
return new HardHatExtensionAdapter();
case WorkspaceType.TRUFFLE:
return new TruffleExtensionAdapter();
default:
return new UnknownExtensionAdapter();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/TruffleCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {getTruffleWorkspace} from '@/helpers/workspace';
import {required} from '@/helpers/required';

import {showQuickPick, showConfirmPaidOperationDialog, showIgnorableNotification} from '@/helpers/userInteraction';
import {getPathByPlatform} from '@/helpers/workspace';
import {getPathByPlatform} from '@/helpers/WorkspaceHelpers';

import {IDeployDestination, ItemType} from '@/Models';
import {NetworkForContractItem} from '@/Models/QuickPickItems';
Expand Down Expand Up @@ -573,7 +573,7 @@ async function readCompiledContract(uri: Uri): Promise<any> {
return JSON.parse(data.toString());
}

function ensureFileIsContractJson(filePath: string) {
function ensureFileIsContractJson(filePath: string): void {
if (path.extname(filePath) !== Constants.contract.configuration.extension.json) {
const error = new Error(Constants.errorMessageStrings.InvalidContract);
Telemetry.sendException(error);
Expand Down
15 changes: 7 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {registerHelpView} from './views/HelpView';
import {OpenUrlTreeItem} from './views/lib/OpenUrlTreeItem';
import {registerGanacheDetails} from './pages/GanacheDetails';
import {registerLogView} from './views/LogView';
import {saveTextDocument} from './helpers/workspace';
import {saveTextDocument} from './helpers/WorkspaceHelpers';
import {StatusBarItems} from './Models/StatusBarItems/Contract';
import {UriHandlerController} from './helpers/uriHandlerController';
import {Output} from './Output';
Expand Down Expand Up @@ -78,7 +78,6 @@ export async function activate(context: ExtensionContext) {
MnemonicRepository.initialize(context.globalState);
TreeManager.initialize(context.globalState);
TreeService.initialize('truffle-vscode.truffle');
await sdkCoreCommands.initialize(context.globalState);

// Starts the status bar item for automatic deploy
const contractStatusBarItem = new StatusBarItems.Contract(context.globalState);
Expand Down Expand Up @@ -231,11 +230,12 @@ export async function activate(context: ExtensionContext) {
//#endregion

//#region workspace subscriptions
const changeCoreSdkConfigurationListener = workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration(Constants.userSettings.coreSdkSettingsKey)) {
await sdkCoreCommands.initialize(context.globalState);
}
});
// I think this isn't needed anymore.
// const changeCoreSdkConfigurationListener = workspace.onDidChangeConfiguration(async (event) => {
// if (event.affectsConfiguration(Constants.userSettings.coreSdkSettingsKey)) {
// await sdkCoreCommands.initialize(context.globalState);
// }
// });
const didSaveTextDocumentListener = workspace.onDidSaveTextDocument(async (event) => {
// Calls the action that listens for the save files event
await saveTextDocument(context.globalState, event);
Expand Down Expand Up @@ -274,7 +274,6 @@ export async function activate(context: ExtensionContext) {
signInToInfuraAccount,
signOutOfInfuraAccount,
showProjectsFromInfuraAccount,
changeCoreSdkConfigurationListener,
didSaveTextDocumentListener,
// new view - main views
fileExplorerView,
Expand Down
Loading