Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 2510df0

Browse files
committed
Switch over to using lingo
1 parent a6c0738 commit 2510df0

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

cabal.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ source-repository-package
1414
type: git
1515
location: https://github.com/joshvera/proto3-wire.git
1616
tag: 84664e22f01beb67870368f1f88ada5d0ad01f56
17+
18+
source-repository-package
19+
type: git
20+
location: https://github.com/tclem/lingo-haskell.git
21+
tag: 7a453568556d7b6ab6fb4573b158b41cef56f7cc

semantic.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ common dependencies
7373
, unix ^>= 2.7.2.2
7474
, proto3-suite
7575
, proto3-wire
76+
, lingo
7677

7778
common executable-flags
7879
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -A4m -n2m"

src/Data/Blob/IO.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ readBlobsFromDir :: MonadIO m => FilePath -> m [Blob]
3838
readBlobsFromDir path = liftIO . fmap catMaybes $
3939
findFilesInDir path supportedExts mempty >>= Async.mapConcurrently (readBlobFromFile . fileForPath)
4040

41-
-- | Read all blobs from the Git repo with Language.supportedExts
41+
-- | Read all blobs from a git repo
4242
readBlobsFromGitRepo :: MonadIO m => FilePath -> Git.OID -> [FilePath] -> [FilePath] -> m [Blob]
4343
readBlobsFromGitRepo path oid excludePaths includePaths = liftIO . fmap catMaybes $
4444
Git.lsTree path oid >>= Async.mapConcurrently (blobFromTreeEntry path)

src/Data/Language.hs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module Data.Language
77
, knownLanguage
88
, languageForFilePath
99
, pathIsMinified
10-
, languageForType
1110
, supportedExts
1211
, codeNavLanguages
1312
) where
1413

1514
import Data.Aeson
15+
import qualified Data.Languages as Lingo
1616
import qualified Data.Text as T
1717
import Prologue
1818
import System.FilePath.Posix
@@ -98,25 +98,6 @@ parseLanguage l = case T.toLower l of
9898
knownLanguage :: Language -> Bool
9999
knownLanguage = (/= Unknown)
100100

101-
-- | Returns a Language based on the file extension (including the ".").
102-
languageForType :: String -> Language
103-
languageForType mediaType = case mediaType of
104-
".java" -> Java
105-
".json" -> JSON
106-
".hs" -> Haskell
107-
".md" -> Markdown
108-
".rb" -> Ruby
109-
".go" -> Go
110-
".js" -> JavaScript
111-
".mjs" -> JavaScript
112-
".ts" -> TypeScript
113-
".tsx" -> TSX
114-
".jsx" -> JSX
115-
".py" -> Python
116-
".php" -> PHP
117-
".phpt" -> PHP
118-
_ -> Unknown
119-
120101
extensionsForLanguage :: Language -> [String]
121102
extensionsForLanguage language = case language of
122103
Go -> [".go"]
@@ -130,9 +111,22 @@ extensionsForLanguage language = case language of
130111
JSX -> [".jsx"]
131112
_ -> []
132113

133-
-- | Return a language based on a FilePath's extension, or Nothing if extension is not found or not supported.
114+
-- | Return a language based on a FilePath's extension.
134115
languageForFilePath :: FilePath -> Language
135-
languageForFilePath = languageForType . takeExtension
116+
languageForFilePath path = case Lingo.languageName <$> Lingo.languageForPath path of
117+
Just "Go" -> Go
118+
Just "Haskell" -> Haskell
119+
Just "Java" -> Java
120+
Just "JavaScript" -> JavaScript
121+
Just "JSON" -> JSON
122+
Just "JSX" -> JSX
123+
Just "Markdown" -> Markdown
124+
Just "PHP" -> PHP
125+
Just "Python" -> Python
126+
Just "Ruby" -> Ruby
127+
Just "TSX" -> TSX
128+
Just "TypeScript" -> TypeScript
129+
_ -> Unknown
136130

137131
supportedExts :: [String]
138132
supportedExts = [".go", ".py", ".rb", ".js", ".mjs", ".ts", ".php", ".phpt"]

0 commit comments

Comments
 (0)