mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 13:11:18 -05:00
refactor(reference): consolidate source extension classification (#16053)
This commit is contained in:
@@ -15,36 +15,7 @@ const SOURCE_CLASSIFICATIONS = [
|
||||
export type ReferenceSourceClassification =
|
||||
(typeof SOURCE_CLASSIFICATIONS)[number];
|
||||
|
||||
const CODE_EXTENSIONS = new Set([
|
||||
"js",
|
||||
"mjs",
|
||||
"cjs",
|
||||
"jsx",
|
||||
"ts",
|
||||
"tsx",
|
||||
"mts",
|
||||
"cts",
|
||||
"py",
|
||||
"rs",
|
||||
"go",
|
||||
"java",
|
||||
"kt",
|
||||
"kts",
|
||||
"c",
|
||||
"h",
|
||||
"cpp",
|
||||
"hpp",
|
||||
"cc",
|
||||
"cxx",
|
||||
"swift",
|
||||
"m",
|
||||
"mm",
|
||||
"sh",
|
||||
"cs",
|
||||
"php",
|
||||
]);
|
||||
|
||||
const LANGUAGE_BY_EXTENSION = new Map<string, string>([
|
||||
const CODE_LANGUAGE_BY_EXTENSION = new Map<string, string>([
|
||||
["js", "JavaScript"],
|
||||
["mjs", "JavaScript"],
|
||||
["cjs", "JavaScript"],
|
||||
@@ -71,6 +42,9 @@ const LANGUAGE_BY_EXTENSION = new Map<string, string>([
|
||||
["m", "Objective-C"],
|
||||
["mm", "Objective-C++"],
|
||||
["sh", "Shell"],
|
||||
]);
|
||||
|
||||
const OTHER_LANGUAGE_BY_EXTENSION = new Map<string, string>([
|
||||
["json", "JSON"],
|
||||
["jsonc", "JSON"],
|
||||
["yaml", "YAML"],
|
||||
@@ -358,7 +332,12 @@ export const detectReferenceSourceLanguage = (path: string): string | null => {
|
||||
const extension = sourceExtension(filename);
|
||||
if (extension === "C") return "C++";
|
||||
if (extension === "M") return "Objective-C++";
|
||||
return LANGUAGE_BY_EXTENSION.get(extension.toLowerCase()) ?? null;
|
||||
const suffix = extension.toLowerCase();
|
||||
return (
|
||||
CODE_LANGUAGE_BY_EXTENSION.get(suffix) ??
|
||||
OTHER_LANGUAGE_BY_EXTENSION.get(suffix) ??
|
||||
null
|
||||
);
|
||||
};
|
||||
|
||||
/** Classify a reference source path deterministically. */
|
||||
@@ -433,5 +412,5 @@ const addFilenameClassifications = (
|
||||
classifications.add("documentation");
|
||||
if (DOCUMENTATION_FILENAMES.has(filename.toLowerCase()))
|
||||
classifications.add("documentation");
|
||||
if (CODE_EXTENSIONS.has(extension)) classifications.add("source");
|
||||
if (CODE_LANGUAGE_BY_EXTENSION.has(extension)) classifications.add("source");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user