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 only temporary, and will be changed before merging, if this ends in main, it was a mistake xD
  • Loading branch information
Totto16 committed Dec 9, 2024
1 parent 4fb1d48 commit a162fea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 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,13 @@ export async function check(): Promise<ToolCheckResult> {
};
}

//TODO: this isn't released yet, so wait until it is, as 1.7.0 is only a guess of the author of the PR, it could also end in 1.6.1 or some other version
// using "-" as stdin is only supported since 1.7.0 (see https://github.com/mesonbuild/meson/pull/13793)
if (mesonVersion.compareWithOther(formattingWithStdinSupportedSinceVersion) < 0) {
return {
error: `Meson supports formatting from stdin only since version ${formattingWithStdinSupportedSinceVersion}, but you have version ${mesonVersion}`,
};
}

return { tool: { path: meson_path, version: mesonVersion } };
}

0 comments on commit a162fea

Please sign in to comment.