Skip to content

Commit fb513d7

Browse files
committed
🐛 Fix compilation issues caused by unreliable remappings.txt files in Foundry projects
1 parent d7d825f commit fb513d7

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [1.19.2]
4+
### Fixes
5+
- Fixed compilation issues caused by unreliable `remappings.txt` files in Foundry projects
6+
7+
## [1.19.1]
8+
### Features
9+
- Added Wake version information to the bottom status bar
10+
- Implemented filtering for ignored detections in the detections UI
11+
12+
### Improvements
13+
- Store ignored detections toggle setting in workspace storage for better persistence
14+
15+
### Fixes
16+
- Fixed state loading issues and disabled autosave by default
17+
318
## [1.19.0]
419
### Features
520
- Introduced pre-configured chains, such as Ethereum Mainnet and popular L2 networks (Optimism, Arbitrum, Base, Polygon, etc.), significantly streamlining the forking process

src/commands.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ export async function importFoundryRemappings(out: vscode.OutputChannel, silent:
9292
let remappings: string[] = [];
9393

9494
try {
95-
// First, try to read from remappings.txt
96-
remappings = fs
97-
.readFileSync(cwd + '/remappings.txt')
95+
// First, try to execute forge from PATH
96+
remappings = execFileSync('forge', ['remappings'], {
97+
cwd: cwd
98+
})
9899
.toString('utf8')
99100
.split(/\r?\n/);
100101
} catch (e) {
101-
// If remappings.txt doesn't exist or can't be read, try using forge
102+
// If forge is not in PATH, try specific locations
102103
try {
103104
remappings = execFileSync(os.homedir() + '/.foundry/bin/forge', ['remappings'], {
104105
cwd: cwd
@@ -113,12 +114,20 @@ export async function importFoundryRemappings(out: vscode.OutputChannel, silent:
113114
.toString('utf8')
114115
.split(/\r?\n/);
115116
} catch (e) {
116-
if (!silent) {
117-
vscode.window.showErrorMessage(
118-
'Failed to find `remappings.txt` file or `forge` executable.'
119-
);
117+
// Fall back to reading remappings.txt
118+
try {
119+
remappings = fs
120+
.readFileSync(cwd + '/remappings.txt')
121+
.toString('utf8')
122+
.split(/\r?\n/);
123+
} catch (e) {
124+
if (!silent) {
125+
vscode.window.showErrorMessage(
126+
'Failed to find `forge` executable or `remappings.txt` file.'
127+
);
128+
}
129+
return;
120130
}
121-
return;
122131
}
123132
}
124133
}

src/extension.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ export async function activate(context: vscode.ExtensionContext) {
254254
};
255255
wakeProvider = new WakeTreeDataProvider(context);
256256
solcProvider = new SolcTreeDataProvider(context);
257-
257+
258258
// Initialize showIgnoredDetections from workspace state (already loaded by WakeTreeDataProvider)
259-
showIgnoredDetections = context.workspaceState.get("detections.showIgnored", false);
259+
showIgnoredDetections = context.workspaceState.get('detections.showIgnored', false);
260260

261261
const clientOptions: LanguageClientOptions = {
262262
documentSelector: [{ scheme: 'file', language: 'solidity' }],
@@ -719,7 +719,7 @@ function watchFoundryRemappings() {
719719

720720
const workspace = workspaces[0];
721721
const fileWatcher = vscode.workspace.createFileSystemWatcher(
722-
new vscode.RelativePattern(workspace, 'remappings.txt')
722+
new vscode.RelativePattern(workspace, '.gitmodules')
723723
);
724724

725725
let configWatcher: vscode.Disposable;
@@ -755,6 +755,14 @@ function watchFoundryRemappings() {
755755
return;
756756
}
757757

758+
// Check if this is a Foundry project by looking for .gitmodules or foundry.toml
759+
// const gitmodulesPath = path.join(workspace.uri.fsPath, '.gitmodules');
760+
// const foundryTomlPath = path.join(workspace.uri.fsPath, 'foundry.toml');
761+
762+
// if (!fs.existsSync(gitmodulesPath) && !fs.existsSync(foundryTomlPath)) {
763+
// return;
764+
// }
765+
758766
// start file system watcher
759767
fileWatcher.onDidChange(async () => {
760768
vscode.commands.executeCommand('Tools-for-Solidity.foundry.import_remappings_silent');
@@ -763,6 +771,7 @@ function watchFoundryRemappings() {
763771
vscode.commands.executeCommand('Tools-for-Solidity.foundry.import_remappings_silent');
764772
});
765773
fileWatcher.onDidDelete(async () => {
774+
// When .gitmodules is deleted, clear remappings since dependencies are gone
766775
vscode.workspace
767776
.getConfiguration('wake.compiler.solc')
768777
.update('remappings', undefined, vscode.ConfigurationTarget.Workspace);

0 commit comments

Comments
 (0)