semantic icon indicating copy to clipboard operation
semantic copied to clipboard

Fix how Lingo handles ambiguous extensions

Open aymannadeem opened this issue 5 years ago • 1 comments

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

aymannadeem avatar Jul 08 '20 20:07 aymannadeem

forPath should probably return a Maybe Language.

patrickt avatar Jul 13 '20 16:07 patrickt