semantic
semantic copied to clipboard
Fix how Lingo handles ambiguous extensions
Ran into this while working on Rust Tagging. I wasn't able to compile and test because .rs files imply either Rust source of Renderscript. We omit spurious extensions in Source.Language, but instead of a result that returns Unknown -> "Unknown", we should probably throw an exception indicating why this is tripping up (ie., "ambiguous file extension").
for the time being, I added RenderScript for my PR:
forPath :: Path.PartClass.AbsRel ar => Path.File ar -> Language
forPath path =
let spurious lang = lang `elem` [ "Hack" -- .php files
, "GCC Machine Description" -- .md files
, "XML" -- .tsx files
, "RenderScript" -- .rs files
]
allResults = Lingo.languageName <$> Lingo.languagesForPath (Path.toString path)
in case filter (not . spurious) allResults of
[result] -> textToLanguage result
_ -> Unknown
forPath should probably return a Maybe Language.