Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
feat(solidity/extension): file with spaces are now formattable & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
EnergyCube authored and 0xmemorygrinder committed Jan 9, 2024
1 parent da7106a commit 5205de8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 62 deletions.
1 change: 0 additions & 1 deletion remove-me-cbf2e47a07ec45e48896.txt

This file was deleted.

13 changes: 0 additions & 13 deletions toolchains/solidity/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,8 @@
{
"command": "osmium.lint-sol-workspace",
"title": "Osmium: Lint Solidity Workspace"
},
{
"command": "osmium.lint-sol-file-from-explorer",
"title": "Osmium: Lint Solidity File"
}
],
"menus": {
"explorer/context": [
{
"when": "resourceLangId == solidity",
"command": "extension.lint-sol-file-from-explorer",
"group": "navigation"
}
]
},
"languages": [
{
"id": "solidity",
Expand Down
54 changes: 6 additions & 48 deletions toolchains/solidity/extension/src/fmt-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function forgeFmt(
const commandArgs = ["fmt"];

if (root) {
commandArgs.push("--root", root);
commandArgs.push("--root", `"${root}"`);
}

if (check) {
Expand All @@ -58,12 +58,14 @@ function forgeFmt(
commandArgs.push("--raw");
}

commandArgs.push(...files);
commandArgs.push(
...files.map((file) => (file.includes(" ") ? `"${file}"` : file))
);

const command = `forge ${commandArgs.join(" ")}`;

if (debug) {
console.debug(command);
console.debug("command =>", command);
}

return new Promise((resolve, reject) => {
Expand All @@ -81,48 +83,6 @@ function forgeFmt(
}

function registerForgeFmtLinter(context: vscode.ExtensionContext) {
const lintSolFromExplorer = vscode.commands.registerCommand(
"osmium.lint-sol-file-from-explorer",
function (uri) {
if (!isFmtInstalled()) {
vscode.window.showErrorMessage(
"Forge fmt is not installed. Please install it and try again."
);
return;
}

const options: ForgeFmtOptions = {
root: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
check: false,
raw: false,
};

const args: ForgeFmtArgs = {
options,
files: [uri.fsPath],
};

forgeFmt(args)
.then((result) => {
if (result.exitCode === 0) {
vscode.window.showInformationMessage("Forge fmt ran successfully.");
} else {
vscode.window.showErrorMessage(
"Forge fmt failed. Please check the output for details."
);

console.log(result.output);
}
})
.catch((error) => {
vscode.window.showErrorMessage(
"Forge fmt failed. Please check the output for details."
);
console.error(error);
});
}
);

const lintSolFile = vscode.commands.registerCommand(
"osmium.lint-sol-file",
function () {
Expand Down Expand Up @@ -216,7 +176,7 @@ function registerForgeFmtLinter(context: vscode.ExtensionContext) {
files: [vscode.workspace.workspaceFolders?.[0].uri.fsPath],
};

forgeFmt(args, true)
forgeFmt(args)
.then((result) => {
if (result.exitCode === 0) {
vscode.window.showInformationMessage("Forge fmt ran successfully.");
Expand Down Expand Up @@ -276,8 +236,6 @@ function registerForgeFmtLinter(context: vscode.ExtensionContext) {
}
);

context.subscriptions.push(lintSolFromExplorer);

context.subscriptions.push(lintSolFile);
context.subscriptions.push(lintSolWorkspace);

Expand Down

0 comments on commit 5205de8

Please sign in to comment.