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

Conversation

michaeljohnbennett
Copy link
Contributor

This is the intial POC for the concept of alternative providers for the main commands on a project.

I spent a bit of time to and fro on how best to achieve or abstract out the concept of a workspace and a provider and this is the initial version where we have providers that can interrogate the workspaces and decide what provider is where in a monorepo for ones we support.

Still early days but I think it could be adapted to give us some flexibility in supporting other frameworks easily in the future.

Going to mark this draft right now as I'd like to get your thoughts on the thinking behind it and how we might be able to do it better/enhance it.

Things we could improve:

  1. having config and commands driven by the folder or parent folder config.
  2. understanding what can and cannot be done in each project and how things like package.json commands/sdk commands may interoperate or conflict.

Add in POC to test other providers under the hood.
Lot of fuffing around to figure out what to mock when doing a test.
Removing unused config elements also.
More refactoring and adding HH component finder.
This is the 3rd attempt.
Output channel has a wrapper to make logging easier.
Fixed the NPM and code which found/resolved the paths for projects into
an abstract resolver.

Hasn't been merged over the truffle code write now but put into a
seperate namespace to keep it isolated and for comment.
@michaeljohnbennett michaeljohnbennett added the enhancement New feature or request label Aug 15, 2022
@michaeljohnbennett michaeljohnbennett self-assigned this Aug 15, 2022
Copy link
Contributor

@acuarica acuarica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @michaeljohnbennett for working on this. This would be a cool addition. Totally agree, with your points.

src/Constants.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/helpers/required.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
typings/global/index.d.ts Outdated Show resolved Hide resolved
@@ -185,3 +189,120 @@ async function selectTruffleConfigFromQuickPick(workspaces: TruffleWorkspace[]):

return result.truffleWorkspace;
}

export namespace AbstractWorkspaceManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I would put all HH related stuff under a module HH. Or even as part of the extension adapter. Otherwise I won't be maintainable, say if we add more SDK providers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is abstract.

It is provider agnostic hence the name. There are multiple resolvers inside it so in theory it would remove all the other code above in time and make the resolving of config and uri locations agnostic. so if we find a truffle config in folder A, then folder A is a truffle based SDK command driven workspace/folder. Folder B could hh or something else?

Does that make sense?

Namespace was here to just encapsulate it in this file v's making another workspace file.

Copy link
Contributor

@xhulz xhulz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @michaeljohnbennett,

It looks awesome :)

I agree with @acuarica comments. I'd like to point that we can keep the output wrapper, but I think might be a good idea, raise another issue to change the other output callings on the code, just to keep the pattern

Thank you for that :)

import {NotificationOptions} from '@/Constants';
import {showNotification} from '@/helpers/userInteraction';
import {IExtensionAdapter} from '@/services/extensionAdapter/IExtensionAdapter';
import {Constants} from '@/constants';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should use the same casing, i.e., @/Constants. Otherwise, webpack gives a warning

There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.

removed some dead imports and lowered the hardhat min version.
Added in methods to make folder based ExtensionMapping work.

Still an odd issue that the picker per project is happening twice but
will be easy enough to figure out whats going on.
@michaeljohnbennett
Copy link
Contributor Author

@acuarica @xhulz I have made more fixes and now the actual resolving of providers is dynamic based on the folders it finds and configs inside them.

Still a bit to fix but overall its working for compilation. But we need to figure out the display in the contracts folders.

@acuarica
Copy link
Contributor

acuarica commented Nov 1, 2022

Hi @michaeljohnbennett, maybe we could use the approach I've used for deployments. Whenever more than one Truffle is found, the Deployments view uses the folder name+Truffle config name as a way to identify each project, for example

image

This was implemented in #179.

@michaeljohnbennett
Copy link
Contributor Author

Hi @michaeljohnbennett, maybe we could use the approach I've used for deployments. Whenever more than one Truffle is found, the Deployments view uses the folder name+Truffle config name as a way to identify each project, for example

image

This was implemented in #179.

I was trying to figure out a easy way to do this with the current treeview for file we use in that contract window, I'll have a look at the deployments view code again and see if I can adapt it. I was thinking even a logo against the folders or something would be good. 👍🏻

moving the code to be more workspace aware.

adding code to handle workspaces that have no/unknown frameworks
installed so they fail gracefully.

TODO: somehow add in a notification on UnknownExtensionAdapter.ts to
warn user their commands are benign.
update to latest sinon (was very old)

refactored out the old TruffleWorkspace code and move everything to
AbstractWorkspace aware.

workspace.ts removed and refactored to a Helper class WorkspaceHelpers
.ts which now has all the base workspace helpers that are more VSCode
specific.

Core commands and TruffleCommands.ts are all AbstractWorkspace aware now
 as well.

 Tests cleaned up. A few placeholders added to wire out tomorrow.
* The [glob](https://github.com/isaacs/node-glob#glob-primer) pattern to match Truffle/Other config file names.
*/
export const TRUFFLE_CONFIG_GLOB = 'truffle-config{,.*}.js';
export const HARDHAT_CONFIG_GLOB = 'hardhat.config{,.*}.ts';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need to include Hardhat js config files, i.e., we can use the following glob hardhat.config{,.*}.{js,ts}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll make that change I just think the majority of HH projects are TS based. I don't think they even give you a choice when bootstrapping a project to use JS anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of HardHat v2.12.2 they do

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change the glob. thanks! 👍🏻

@acuarica
Copy link
Contributor

Hey @michaeljohnbennett, doing some early testing as discussed earlier.

The Contract Explorer now displays the whole workspace, instead of displaying the contracts folder only. This happens for both Truffle and Hardhat projects.

image

image

Comment on lines 1 to 3
// Copyright (c) 2022. Consensys Software Inc. All rights reserved.
// Licensed under the MIT license.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of the Copyright Notice. But given that it is a significant change, should we open a different PR for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was done by my IDE. I thought this was how all our JS files were marked? Intellij adds in copyrights based on your template by default on all unmarked files.

I can revert all this if you think best?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. If it not a big issue reverting, I believe it's better to create another PR to tackle this copyright thing.

@michaeljohnbennett
Copy link
Contributor Author

Hey @michaeljohnbennett, doing some early testing as discussed earlier.

The Contract Explorer now displays the whole workspace, instead of displaying the contracts folder only. This happens for both Truffle and Hardhat projects.

image image

Yes, this one of the questions I have. Contracts is really the wrong name going forward as we really need to show a bit more than just the contracts folder now, its a hierarchy of projects and their resulting folders.

Perhaps we need to have a filter list:

  • contracts (wherever that folder is)
  • tests
  • config files

?

@michaeljohnbennett
Copy link
Contributor Author

I'll revert the copy right stuff and merge in develop today.

@acuarica
Copy link
Contributor

Regarding #204 (comment), the only thing that worries me is that if we start including tests and config files into the Contract Explorer, not sure how much value provides over the File Explorer.

@michaeljohnbennett
Copy link
Contributor Author

Regarding #204 (comment), the only thing that worries me is that if we start including tests and config files into the Contract Explorer, not sure how much value provides over the File Explorer.

I agree it needs to change but to what?

  1. Stay as is and only show contracts, but how do we represent a monorepo of differing projects in this view? A folder for each root then a contracts folder? What about scripts/tests etc?
  2. We change the name to something more akin to a Project explorer and show more meaningful information/folders relating to a smart contract project (tests, contracts, artifacts, config) but filter out all the other non-essential to coding files (.ignore etc, build/node_modules)

Add in chai as promised to help with promise testing.

Fixed the tests around workspace resolving and got good coverage on all
paths.
@michaeljohnbennett
Copy link
Contributor Author

I have merged in develop and @xhulz fixes to tree view. I'll use them now as my changes I made are blasted away now but its ok, I still have to remove the copy right changes.

All tests fixed now as well.

@acuarica
Copy link
Contributor

I agree it needs to change but to what?

I'm leaning towards option 1. described in #204 (comment).

but how do we represent a monorepo of differing projects in this view? A folder for each root then a contracts folder?

That's the current behavior, but the contracts folder is the root itself. For example in a workspace with two Truffle config files

image

each project is shown separately with its own root

image

What about scripts/tests etc?

This seems to be an orthogonal feature, not necessarily related to this PR. Given said that, I do agree that we need to discuss what to display in this view.

Stopped updating copyright automagically.
Fixing tests and optimising the code before I can do the next part which
 is abstract out the truffle resolver code for config etc.
Reworking the mocks to work in the VSCode integration test environment.
@michaeljohnbennett michaeljohnbennett marked this pull request as ready for review November 21, 2022 05:55
@michaeljohnbennett michaeljohnbennett marked this pull request as draft November 29, 2022 22:51
@michaeljohnbennett
Copy link
Contributor Author

marking as draft so it doesn't get inadvertently merged right now pre-release of latest version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants