diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab415a..89c7e30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.6.1 + +- fix: improved error message when swiftformat is missing + # 1.6.0 - docs: clarified `swiftformat.options` #17 diff --git a/package.json b/package.json index e2ef14e..c346e9d 100755 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/vknabel/vscode-swiftformat" }, - "version": "1.6.0", + "version": "1.6.1", "license": "MIT", "author": { "name": "Valentin Knabel", diff --git a/src/UserInteraction.ts b/src/UserInteraction.ts index 029f0e4..5f5b329 100644 --- a/src/UserInteraction.ts +++ b/src/UserInteraction.ts @@ -3,7 +3,8 @@ import Current from "./Current"; enum FormatErrorInteraction { configure = "Configure", - reset = "Reset" + reset = "Reset", + howTo = "How?" } enum UnknownErrorInteraction { @@ -14,21 +15,32 @@ export async function handleFormatError( error: any, document: vscode.TextDocument ) { - if (error.code === "ENOENT") { + function matches(...codeOrStatus: Array) { + return codeOrStatus.some(c => c === error.code || c === error.status); + } + if (matches("ENOENT", 127)) { const selection = await Current.editor.showErrorMessage( - `Could not find SwiftFormat: ${Current.config.swiftFormatPath(document)}`, + `Could not find SwiftFormat: ${Current.config + .swiftFormatPath(document) + ?.join(" ")}.\nEnsure it is installed and in your PATH.`, FormatErrorInteraction.reset, - FormatErrorInteraction.configure + FormatErrorInteraction.configure, + FormatErrorInteraction.howTo ); switch (selection) { case FormatErrorInteraction.reset: - await Current.config.resetSwiftFormatPath(); + Current.config.resetSwiftFormatPath(); break; case FormatErrorInteraction.configure: - await Current.config.configureSwiftFormatPath(); + Current.config.configureSwiftFormatPath(); + break; + case FormatErrorInteraction.howTo: + await Current.editor.openURL( + "https://github.com/nicklockwood/SwiftFormat#command-line-tool" + ); break; } - } else if (error.status === 70) { + } else if (matches(70)) { await Current.editor.showErrorMessage( `SwiftFormat failed. ${error.stderr || ""}` );