mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Bump lingo to 0.3 and remove hack associated with #333.
Now that lingo's language detection returns all possible results for a given filename, we're able to abolish the workaround where we parsed the string `"Hack"` into PHP. We have to check ourselves for spurious results associated with Hack, TSX, and Markdown files, but that's fitting and proper, rather than doing it behind the scenes in lingo.
This commit is contained in:
parent
63f48c1d35
commit
ba122b2aae
@ -33,6 +33,11 @@ package semantic-source
|
|||||||
package semantic-tags
|
package semantic-tags
|
||||||
ghc-options: -Werror
|
ghc-options: -Werror
|
||||||
|
|
||||||
|
source-repository-package
|
||||||
|
type: git
|
||||||
|
location: https://github.com/tclem/lingo-haskell
|
||||||
|
tag: 59b19fd7251bd247245dbb67859507391764270f
|
||||||
|
|
||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/tclem/proto-lens-jsonpb
|
location: https://github.com/tclem/proto-lens-jsonpb
|
||||||
|
@ -71,7 +71,7 @@ common dependencies
|
|||||||
, text ^>= 1.2.3.1
|
, text ^>= 1.2.3.1
|
||||||
, these >= 0.7 && <1
|
, these >= 0.7 && <1
|
||||||
, unix ^>= 2.7.2.2
|
, unix ^>= 2.7.2.2
|
||||||
, lingo >= 0.2.0.0
|
, lingo >= 0.3.0.0
|
||||||
|
|
||||||
common executable-flags
|
common executable-flags
|
||||||
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -A4m -n2m"
|
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -A4m -n2m"
|
||||||
|
@ -93,7 +93,15 @@ extensionsForLanguage language = T.unpack <$> maybe mempty Lingo.languageExtensi
|
|||||||
|
|
||||||
-- | Return a language based on a FilePath's extension.
|
-- | Return a language based on a FilePath's extension.
|
||||||
languageForFilePath :: FilePath -> Language
|
languageForFilePath :: FilePath -> Language
|
||||||
languageForFilePath path = maybe Unknown (textToLanguage . Lingo.languageName) (Lingo.languageForPath path)
|
languageForFilePath path =
|
||||||
|
let spurious lang = lang `elem` [ "Hack" -- .php files
|
||||||
|
, "GCC Machine Description" -- .md files
|
||||||
|
, "XML" -- .tsx files
|
||||||
|
]
|
||||||
|
allResults = Lingo.languageName <$> Lingo.languagesForPath path
|
||||||
|
in case filter (not . spurious) allResults of
|
||||||
|
[result] -> textToLanguage result
|
||||||
|
_ -> Unknown
|
||||||
|
|
||||||
supportedExts :: [String]
|
supportedExts :: [String]
|
||||||
supportedExts = foldr append mempty supportedLanguages
|
supportedExts = foldr append mempty supportedLanguages
|
||||||
@ -129,7 +137,6 @@ textToLanguage :: T.Text -> Language
|
|||||||
textToLanguage = \case
|
textToLanguage = \case
|
||||||
"Go" -> Go
|
"Go" -> Go
|
||||||
"Haskell" -> Haskell
|
"Haskell" -> Haskell
|
||||||
"Hack" -> PHP -- working around https://github.com/github/semantic/issues/330
|
|
||||||
"Java" -> Java
|
"Java" -> Java
|
||||||
"JavaScript" -> JavaScript
|
"JavaScript" -> JavaScript
|
||||||
"JSON" -> JSON
|
"JSON" -> JSON
|
||||||
|
@ -15,4 +15,5 @@ testTree = testGroup "Data.Language"
|
|||||||
, testCase "languageForFilePath works for languages with ambiguous lingo extensions" $ do
|
, testCase "languageForFilePath works for languages with ambiguous lingo extensions" $ do
|
||||||
languageForFilePath "foo.php" @=? PHP
|
languageForFilePath "foo.php" @=? PHP
|
||||||
languageForFilePath "foo.md" @=? Markdown
|
languageForFilePath "foo.md" @=? Markdown
|
||||||
|
languageForFilePath "foo.tsx" @=? TSX
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user