Skip to content

Commit

Permalink
fix: add version check for using "-" (stdin) as input to meson format
Browse files Browse the repository at this point in the history
now we have two version checks atm, but this is here, to make it clear, why only > 1.7.0 is supported for this feature
  • Loading branch information
Totto16 committed Jan 26, 2025
1 parent 7cb8dd1 commit 8f9a2f0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/tools/meson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export async function format(meson: Tool, root: string, document: vscode.TextDoc

const { stdout, stderr, error } = await execFeed(meson.path, args, { cwd: root }, originalDocumentText);
if (error) {
getOutputChannel().appendLine(`Failed to format document with meson: ${stderr}`);
//TODO: file a bug report, meson prints some errors on stdout :(
const errorString = stderr.trim().length > 0 ? stderr : stdout;

getOutputChannel().appendLine(`Failed to format document with meson: ${errorString}`);
getOutputChannel().show(true);
return [];
}
Expand All @@ -31,6 +34,7 @@ export async function format(meson: Tool, root: string, document: vscode.TextDoc
}

const formattingSupportedSinceVersion = new Version([1, 5, 0]);
const formattingWithStdinSupportedSinceVersion = new Version([1, 7, 0]);

export async function check(): Promise<ToolCheckResult> {
const meson_path = mesonProgram();
Expand All @@ -52,5 +56,12 @@ export async function check(): Promise<ToolCheckResult> {
);
}

// using "-" as stdin is only supported since 1.7.0 (see https://github.com/mesonbuild/meson/pull/13793)
if (mesonVersion.compareWithOther(formattingWithStdinSupportedSinceVersion) < 0) {
return ToolCheckResult.newError(
`Meson supports formatting from stdin only since version ${formattingWithStdinSupportedSinceVersion}, but you have version ${mesonVersion}`,
);
}

return ToolCheckResult.newTool({ path: meson_path, version: mesonVersion });
}

0 comments on commit 8f9a2f0

Please sign in to comment.