-
Notifications
You must be signed in to change notification settings - Fork 19
Load foundry compiled projects #325
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
base: master
Are you sure you want to change the base?
Changes from all commits
568ecb9
5f47964
ea6b0b8
f7e151d
d152bc0
9756c2e
df1abbe
f82bc2f
26c66d1
a96fc43
a249226
19bd694
73645a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,13 +18,18 @@ import { | |||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| createERC4907Contract, | ||||||||||||||||||||||||||||||||||
| parseBatchCompiledJSON, | ||||||||||||||||||||||||||||||||||
| parseFoundryCompiledJSON, | ||||||||||||||||||||||||||||||||||
| parseHardhatCompiledJSON, | ||||||||||||||||||||||||||||||||||
| parseCompiledJSONPayload, | ||||||||||||||||||||||||||||||||||
| selectContract | ||||||||||||||||||||||||||||||||||
| selectContract, | ||||||||||||||||||||||||||||||||||
| parseFoundryConfig | ||||||||||||||||||||||||||||||||||
| } from './utils' | ||||||||||||||||||||||||||||||||||
| import { isFoundryProject, isHardhatProject } from './utils/functions' | ||||||||||||||||||||||||||||||||||
| import { provider, status, wallet, contract } from './api' | ||||||||||||||||||||||||||||||||||
| import { events } from './api/events' | ||||||||||||||||||||||||||||||||||
| import { event } from './api/api' | ||||||||||||||||||||||||||||||||||
| import { type API } from './types' | ||||||||||||||||||||||||||||||||||
| import * as toml from 'toml' | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export async function activate (context: ExtensionContext): Promise<API | undefined> { | ||||||||||||||||||||||||||||||||||
| const disposables = [ | ||||||||||||||||||||||||||||||||||
|
|
@@ -154,6 +159,24 @@ export async function activate (context: ExtensionContext): Promise<API | undefi | |||||||||||||||||||||||||||||||||
| // Activate | ||||||||||||||||||||||||||||||||||
| commands.registerCommand('ethcode.activate', async () => { | ||||||||||||||||||||||||||||||||||
| logger.success('Welcome to Ethcode!') | ||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Load Foundry contracts | ||||||||||||||||||||||||||||||||||
| commands.registerCommand('ethcode.foundry.load', async () => { | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| await parseFoundryCompiledJSON(context) | ||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||
| logger.error(`Error loading Foundry contracts: ${error}`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Load Hardhat contracts | ||||||||||||||||||||||||||||||||||
| commands.registerCommand('ethcode.hardhat.load', async () => { | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| await parseHardhatCompiledJSON(context) | ||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||
| logger.error(`Error loading Hardhat contracts: ${error}`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -235,25 +258,61 @@ export async function activate (context: ExtensionContext): Promise<API | undefi | |||||||||||||||||||||||||||||||||
| await window.showErrorMessage('No folder selected please open one.') | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| const watcher = workspace.createFileSystemWatcher( | ||||||||||||||||||||||||||||||||||
| new RelativePattern(path_[0].uri.fsPath, '{artifacts, build, out, cache}/**/*.json') | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| watcher.onDidCreate(async (uri) => { | ||||||||||||||||||||||||||||||||||
| // Create dynamic file watcher based on project type | ||||||||||||||||||||||||||||||||||
| const createDynamicWatcher = async () => { | ||||||||||||||||||||||||||||||||||
| const watchPatterns: string[] = [] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| // Check for Foundry project using centralized parser | ||||||||||||||||||||||||||||||||||
| const foundryConfig = await parseFoundryConfig() | ||||||||||||||||||||||||||||||||||
| if (foundryConfig) { | ||||||||||||||||||||||||||||||||||
| const { outDir } = foundryConfig | ||||||||||||||||||||||||||||||||||
| watchPatterns.push(`${outDir}/**/*.json`) | ||||||||||||||||||||||||||||||||||
| logger.log(`Foundry project detected, watching: ${outDir}/**/*.json`) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Check for Hardhat project | ||||||||||||||||||||||||||||||||||
| if (isHardhatProject(path_[0].uri.fsPath)) { | ||||||||||||||||||||||||||||||||||
| watchPatterns.push('artifacts/**/*.json') | ||||||||||||||||||||||||||||||||||
| logger.log('Hardhat project detected, watching: artifacts/**/*.json') | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Fallback patterns for other frameworks | ||||||||||||||||||||||||||||||||||
| if (watchPatterns.length === 0) { | ||||||||||||||||||||||||||||||||||
| watchPatterns.push('{artifacts, build, out, cache, out-*/**/*.json}') | ||||||||||||||||||||||||||||||||||
| logger.log('No specific framework detected, using fallback patterns') | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||
| logger.error(`Error setting up file watcher: ${error}`) | ||||||||||||||||||||||||||||||||||
| // Fallback to original pattern | ||||||||||||||||||||||||||||||||||
| watchPatterns.push('{artifacts, build, out, cache, out-*/**/*.json}') | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+283
to
+290
|
||||||||||||||||||||||||||||||||||
| watchPatterns.push('{artifacts, build, out, cache, out-*/**/*.json}') | |
| logger.log('No specific framework detected, using fallback patterns') | |
| } | |
| } catch (error) { | |
| logger.error(`Error setting up file watcher: ${error}`) | |
| // Fallback to original pattern | |
| watchPatterns.push('{artifacts, build, out, cache, out-*/**/*.json}') | |
| watchPatterns.push('{artifacts,build,out,cache,out-*}/**/*.json') | |
| logger.log('No specific framework detected, using fallback patterns') | |
| } | |
| } catch (error) { | |
| logger.error(`Error setting up file watcher: ${error}`) | |
| // Fallback to original pattern | |
| watchPatterns.push('{artifacts,build,out,cache,out-*}/**/*.json') |
0mkara marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Jul 12, 2025
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.
[nitpick] Avoid using any for the uri parameter in onDidChange. Use the VS Code Uri type for stronger type safety.
| watcher.onDidChange(async (uri: any) => { | |
| watcher.onDidChange(async (uri: Uri) => { |
Copilot
AI
Jul 12, 2025
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.
[nitpick] Avoid using any for the uri parameter in onDidDelete. Use the VS Code Uri type for stronger type safety.
| watcher.onDidDelete(async (uri: any) => { | |
| watcher.onDidDelete(async (uri: Uri) => { |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||
| import { type AbiItem } from './types' | ||||
| import { logger } from '../lib' | ||||
|
||||
| import { logger } from '../lib' |
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.
Invalid glob pattern syntax. The pattern '{artifacts, build, out, cache, out-/**/.json}' mixes directory names with a nested path pattern. This should be '{artifacts,build,out,cache,out-}/**/.json' to correctly match JSON files in any of these directories.