Skip to content

Commit

Permalink
fix(bug): move offer of init to on-error only (#5)
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
isbecker authored Dec 21, 2024
1 parent 8a9369e commit 139648f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "treefmt-vscode",
"displayName": "treefmt-vscode",
"description": "treefmt streamlines the process of applying formatters to your project, making it a breeze with just one command line.",
"version": "2.1.0",
"version": "2.1.1",
"publisher": "ibecker",
"icon": "icon.png",
"engines": {
Expand Down
28 changes: 9 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,6 @@ async function runTreefmt() {
if (configPath && !path.isAbsolute(configPath)) {
configPath = path.join(workspaceRoot, configPath);
}
if (!configPath || !fs.existsSync(configPath)) {
let configFile = configPath ?? "treefmt.toml";

const create = await vscode.window.showInformationMessage(
`${configFile} not found. Would you like to create treefmt.toml?`,
"Yes",
"No",
);

if (create === "Yes") {
initTreefmt();
}

// Early return to prevent running treefmt with a config file that isn't configured
// treefmt --init makes a treefmt.toml file but it doesn't have any rules in it
return;
}

let args = "";
if (configPath) {
Expand All @@ -81,9 +64,16 @@ async function runTreefmt() {
exec(
`${command} ${args} ${editor.document.fileName}`,
{ cwd: workspaceRoot },
(error, stdout, stderr) => {
async (error, stdout, stderr) => {
if (error) {
vscode.window.showErrorMessage(`Error running ${command}: ${stderr}`);
const create = await vscode.window.showErrorMessage(
`Error running ${command}: ${stderr}`,
"OK",
"Create treefmt.toml",
);
if (create === "Create treefmt.toml") {
initTreefmt();
}
return;
}
},
Expand Down

0 comments on commit 139648f

Please sign in to comment.