mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 18:50:20 +00:00
Diffs: fall back on invalid language hints (#57902)
Merged via squash.
Prepared head SHA: 567ca3a56f
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
66777e140e
commit
9a94578d47
39
extensions/diffs/src/language-hints.ts
Normal file
39
extensions/diffs/src/language-hints.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { resolveLanguage } from "@pierre/diffs";
|
||||
import type { SupportedLanguages } from "@pierre/diffs";
|
||||
|
||||
const PASSTHROUGH_LANGUAGE_HINTS = new Set<SupportedLanguages>(["ansi", "text"]);
|
||||
|
||||
export async function normalizeSupportedLanguageHint(
|
||||
value?: string,
|
||||
): Promise<SupportedLanguages | undefined> {
|
||||
const normalized = value?.trim();
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
if (PASSTHROUGH_LANGUAGE_HINTS.has(normalized as SupportedLanguages)) {
|
||||
return normalized as SupportedLanguages;
|
||||
}
|
||||
try {
|
||||
await resolveLanguage(normalized as Exclude<SupportedLanguages, "text" | "ansi">);
|
||||
return normalized as SupportedLanguages;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function filterSupportedLanguageHints(
|
||||
values: Iterable<string>,
|
||||
): Promise<SupportedLanguages[]> {
|
||||
const supported = new Set<SupportedLanguages>();
|
||||
for (const value of values) {
|
||||
const normalized = await normalizeSupportedLanguageHint(value);
|
||||
if (!normalized) {
|
||||
continue;
|
||||
}
|
||||
supported.add(normalized);
|
||||
}
|
||||
if (supported.size === 0) {
|
||||
supported.add("text");
|
||||
}
|
||||
return [...supported];
|
||||
}
|
||||
Reference in New Issue
Block a user