This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Feature/command provider poc #204
Draft
michaeljohnbennett
wants to merge
24
commits into
develop
Choose a base branch
from
feature/command-provider-poc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
001c69d
feat: command provider poc
michaeljohnbennett 0ed7d89
fix: adding in tests and typings to make chai/mocha work
michaeljohnbennett dabb72a
Merge remote-tracking branch 'origin/develop' into feature/command-pr…
michaeljohnbennett af4eaaa
fix: adjusting provider
michaeljohnbennett e8c58b6
fix: adjusting provider
michaeljohnbennett 8126c63
Merge remote-tracking branch 'origin/develop' into feature/command-pr…
michaeljohnbennett 2e804e2
fix: rework again after merging
michaeljohnbennett 27f20a7
fix: added logging wrapper
michaeljohnbennett b13ae39
Merge remote-tracking branch 'origin/develop' into feature/command-pr…
michaeljohnbennett b8904b6
fix: added in compiler
michaeljohnbennett 18b9882
fix: cleanup comments
michaeljohnbennett 5d84c97
fix: merging in changes from develop
michaeljohnbennett ecd92be
fix: logging fixed
michaeljohnbennett e002cb6
fix: project based compilation working
michaeljohnbennett b8f3da9
fix: cleaning up code
michaeljohnbennett 9ae11c7
fix: lots of refactoring
michaeljohnbennett 2c0f847
fix: lots of refactoring
michaeljohnbennett 3c01bfe
fix: tests
michaeljohnbennett 90a7f12
Merge branch 'develop' into feature/command-provider-poc
michaeljohnbennett 7bfb7fe
chore: removing copyright cleanup
michaeljohnbennett 75e4935
chore: post merge refactor/cleanup
michaeljohnbennett 19a3be6
fix: broken integration tests
michaeljohnbennett 5ed78f4
fix: windows paths on CICD
michaeljohnbennett 3addbe8
Merge branch 'develop' into feature/command-provider-poc
michaeljohnbennett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: lots of refactoring
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.
- Loading branch information
commit 9ae11c7efc64048491bd2a610572034d3b593042
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Copyright (c) 2022. Consensys Software Inc. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import {Constants} from '@/Constants'; | ||
import {showQuickPick} from '@/helpers/userInteraction'; | ||
import {Telemetry} from '@/TelemetryClient'; | ||
import glob from 'glob'; | ||
import * as path from 'path'; | ||
import {Uri, workspace} from 'vscode'; | ||
|
||
/** | ||
* 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'; | ||
|
||
class ResolverConfig { | ||
constructor(public type: WorkspaceType, public glob: string) {} | ||
|
||
async resolvePath(_uri: Uri): Promise<AbstractWorkspace | undefined> { | ||
return undefined; | ||
} | ||
} | ||
|
||
export enum WorkspaceType { | ||
TRUFFLE = 'Truffle', | ||
HARDHAT = 'Hardhat', | ||
UNKNOWN = 'Unknown', | ||
} | ||
|
||
export const WorkspaceResolvers: Array<ResolverConfig> = [ | ||
new ResolverConfig(WorkspaceType.TRUFFLE, TRUFFLE_CONFIG_GLOB), | ||
new ResolverConfig(WorkspaceType.HARDHAT, HARDHAT_CONFIG_GLOB), | ||
]; | ||
|
||
export class AbstractWorkspace { | ||
/** | ||
* Creates a `Workspace` of varying Type. | ||
* | ||
* @param configPath the full path of the config file. | ||
* @param workspaceType - the type of config we have found. | ||
*/ | ||
constructor(configPath: string, public readonly workspaceType: WorkspaceType) { | ||
this.configName = path.basename(configPath); | ||
this.dirName = path.dirname(configPath).split(path.sep).pop()!.toString(); | ||
this.workspace = Uri.parse(path.dirname(configPath)); | ||
this.configPath = Uri.parse(configPath); | ||
} | ||
|
||
/** | ||
* Represents the `basename`, _i.e._, the file name portion | ||
*/ | ||
readonly configName: string; | ||
|
||
/** | ||
* The last directory name where this config file is located. | ||
*/ | ||
readonly dirName: string; | ||
|
||
/** | ||
* The `Uri` path of the directory where this config file is located. | ||
*/ | ||
readonly workspace: Uri; | ||
|
||
/** | ||
* The full `Uri` path where this config file is located. | ||
*/ | ||
readonly configPath: Uri; | ||
} | ||
|
||
/** | ||
* Using all the resolvers, resolve the projects/config files present in the workspaces. | ||
*/ | ||
export function resolveAllWorkspaces(includeUnknown = true): AbstractWorkspace[] { | ||
if (workspace.workspaceFolders === undefined) { | ||
return []; | ||
} | ||
return workspace.workspaceFolders.flatMap((ws) => { | ||
const foundWs = findWorkspaces(ws.uri.fsPath); | ||
// patch in the unknown ones. | ||
if (includeUnknown && foundWs?.length === 0) { | ||
const configPath = path.join(ws.uri.fsPath, 'UNKNOWN'); | ||
foundWs.push(new AbstractWorkspace(configPath, WorkspaceType.UNKNOWN)); | ||
} | ||
return foundWs; | ||
}); | ||
} | ||
|
||
export const findWorkspaces = (workspaceRootPath: string): AbstractWorkspace[] => { | ||
return WorkspaceResolvers.flatMap((r) => | ||
glob | ||
.sync(`${workspaceRootPath}/**/${r.glob}`, { | ||
ignore: Constants.workspaceIgnoredFolders, | ||
}) | ||
.map((f) => new AbstractWorkspace(f, r.type)) | ||
); | ||
}; | ||
|
||
export async function getWorkspaceForUri(contractUri?: Uri): Promise<AbstractWorkspace> { | ||
const workspaces = contractUri | ||
? findWorkspaces(workspace.getWorkspaceFolder(contractUri)!.uri.fsPath) | ||
: resolveAllWorkspaces(); | ||
// console.log(`getWorkspaceForUri: `, {workspaces}); | ||
if (workspaces.length === 0) { | ||
const error = new Error(Constants.errorMessageStrings.VariableShouldBeDefined('Workspace root')); | ||
Telemetry.sendException(error); | ||
throw error; | ||
} | ||
|
||
if (workspaces.length === 1) { | ||
return workspaces[0]; | ||
} | ||
|
||
return await selectConfigFromQuickPick(workspaces); | ||
} | ||
|
||
/** | ||
* Shows the list of `workspaces` in a quick pick so the user can select | ||
* the correct config file to use. | ||
* | ||
* @param workspaces list of workspace folders to display to the user. | ||
* @returns the config file of the selected Workspace. | ||
*/ | ||
export async function selectConfigFromQuickPick(workspaces: AbstractWorkspace[]): Promise<AbstractWorkspace> { | ||
const folders = workspaces.map((element) => { | ||
return { | ||
label: element.dirName, | ||
description: `Type: ${element.workspaceType} : ${element.configName}`, | ||
detail: process.platform === 'win32' ? element.dirName : element.workspace.fsPath, | ||
workspace: element, | ||
}; | ||
}); | ||
|
||
const result = await showQuickPick(folders, { | ||
ignoreFocusOut: true, | ||
placeHolder: `Select a config file to use`, | ||
}); | ||
|
||
return result.workspace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 globhardhat.config{,.*}.{js,ts}
.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 doThere was a problem hiding this comment.
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! 👍🏻