Skip to content
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

Platform specific remappings #322

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ If you want to use the solidity user settings for your workspace / global remapp
Or if you want to include them in the remappings.txt file, just put the file at the root of your project folder. Note: These will override your solidity settings if included
![image](https://user-images.githubusercontent.com/562371/136204736-be94e8d8-1954-4981-891c-278145b27cdf.png)

#### Platform specific remappings

There are situations when cross-platform paths are needed, in this case you can use the ```solidity.remappingsWindows``` or ```solidity.remappingsUnix``` settings.

```
"solidity.remappingsWindows": [
"@openzeppelin/=C:/Users/<USERNAME>/.brownie/packages/OpenZeppelin/[email protected]"
],
"solidity.remappingsUnix": [
"@openzeppelin/=/Users/<USERNAME>/.brownie/packages/OpenZeppelin/[email protected]"
]
```

## Code completion

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@
"type": "array",
"default": [],
"description": "Remappings to resolve contracts to local files / directories, i.e: [\"@openzeppelin/=lib/openzeppelin-contracts\",\"ds-test/=lib/ds-test/src/\"]"
},
"solidity.remappingsWindows": {
"type": "array",
"default": [],
"description": "Remappings to resolve contracts to local Windows files / directories, i.e: [\"@openzeppelin/=C:/lib/openzeppelin-contracts\",\"ds-test/=C:/lib/ds-test/src/\"]"
},
"solidity.remappingsUnix": {
"type": "array",
"default": [],
"description": "Remappings to resolve contracts to local Unix files / directories, i.e: [\"@openzeppelin/=/opt/lib/openzeppelin-contracts\",\"ds-test/=/opt/lib/ds-test/src/\"]"
}
}
},
Expand Down
111 changes: 111 additions & 0 deletions soljson-latest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/client/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function getBuildPath() {
const packageDefaultDependenciesDirectory = vscode.workspace.getConfiguration('solidity').get<string>('packageDefaultDependenciesDirectory');
const packageDefaultDependenciesContractsDirectory = vscode.workspace.getConfiguration('solidity').get<string>('packageDefaultDependenciesContractsDirectory');
const rootPath = workspaceUtil.getCurrentWorkspaceRootFsPath();
const remappings = vscode.workspace.getConfiguration('solidity').get<string[]>('remappings');
const remappings = workspaceUtil.getSolidityRemappings();
const project = initialiseProject(rootPath, packageDefaultDependenciesDirectory, packageDefaultDependenciesContractsDirectory, remappings);
return path.join(rootPath, project.projectPackage.build_dir);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/compileActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function compileActiveContract(compiler: Compiler, overrideDefaultCompile
const packageDefaultDependenciesDirectory = vscode.workspace.getConfiguration('solidity').get<string>('packageDefaultDependenciesDirectory');
const packageDefaultDependenciesContractsDirectory = vscode.workspace.getConfiguration('solidity').get<string>('packageDefaultDependenciesContractsDirectory');
const compilationOptimisation = vscode.workspace.getConfiguration('solidity').get<number>('compilerOptimization');
const remappings = vscode.workspace.getConfiguration('solidity').get<string[]>('remappings');
const remappings = workspaceUtil.getSolidityRemappings();
const project = initialiseProject(workspaceUtil.getCurrentWorkspaceRootFsPath(), packageDefaultDependenciesDirectory, packageDefaultDependenciesContractsDirectory, remappings);
const contract = contractsCollection.addContractAndResolveImports(contractPath, contractCode, project);

Expand Down
2 changes: 1 addition & 1 deletion src/client/compileAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function compileAllContracts(compiler: Compiler, diagnosticCollection: vs
const packageDefaultDependenciesDirectory = vscode.workspace.getConfiguration('solidity').get<string>('packageDefaultDependenciesDirectory');
const packageDefaultDependenciesContractsDirectory = vscode.workspace.getConfiguration('solidity').get<string>('packageDefaultDependenciesContractsDirectory');
const compilationOptimisation = vscode.workspace.getConfiguration('solidity').get<number>('compilerOptimization');
const remappings = vscode.workspace.getConfiguration('solidity').get<string[]>('remappings');
const remappings = workspaceUtil.getSolidityRemappings();

const contractsCollection = new ContractCollection();
const project = initialiseProject(rootPath, packageDefaultDependenciesDirectory, packageDefaultDependenciesContractsDirectory, remappings);
Expand Down
10 changes: 9 additions & 1 deletion src/client/workspaceUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ export function getCurrentWorkspaceRootFolder(){
var editor = vscode.window.activeTextEditor;
const currentDocument = editor.document.uri;
return vscode.workspace.getWorkspaceFolder(currentDocument);
}
}

export function getSolidityRemappings(): string[] {
const remappings = vscode.workspace.getConfiguration('solidity').get<string[]>('remappings');
if (process.platform === 'win32') {
return remappings.concat(vscode.workspace.getConfiguration('solidity').get<string[]>('remappingsWindows'));
}
return remappings.concat(vscode.workspace.getConfiguration('solidity').get<string[]>('remappingsUnix'));
}
9 changes: 9 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface SoliditySettings {
packageDefaultDependenciesDirectory: string;
packageDefaultDependenciesContractsDirectory: string;
remappings: string[];
remappingsWindows: string[];
remappingsUnix: string[];
}


Expand Down Expand Up @@ -303,6 +305,13 @@ connection.onDidChangeConfiguration((change) => {
packageDefaultDependenciesContractsDirectory = settings.solidity.packageDefaultDependenciesContractsDirectory;
packageDefaultDependenciesDirectory = settings.solidity.packageDefaultDependenciesDirectory;
remappings = settings.solidity.remappings;

if (process.platform === 'win32') {
remappings = remappings.concat(settings.solidity.remappingsWindows);
} else {
remappings = remappings.concat(settings.solidity.remappingsUnix);
}

switch (linterName(settings.solidity)) {
case 'solhint': {
linter = new SolhintService(rootPath, solhintDefaultRules);
Expand Down