mirror of
https://github.com/github/semantic.git
synced 2024-11-28 01:47:01 +03:00
Move semantic-specific stuff back to Data.Language.
This commit is contained in:
parent
ef0960bd7b
commit
7c3b71a604
@ -25,6 +25,7 @@ fromBody :: HasCallStack => a -> File a
|
||||
fromBody body = File (Path.absRel (srcLocFile srcLoc)) (spanFromSrcLoc srcLoc) body where
|
||||
srcLoc = snd (fromJust (listToMaybe (getCallStack callStack)))
|
||||
|
||||
-- | The language of the provided file, as inferred by 'Language.forPath'.
|
||||
fileLanguage :: File a -> Language
|
||||
fileLanguage = Language.forPath . filePath
|
||||
|
||||
|
@ -11,13 +11,8 @@ module Analysis.Language
|
||||
, knownLanguage
|
||||
, forPath
|
||||
, pathIsMinified
|
||||
, supportedExts
|
||||
, codeNavLanguages
|
||||
, textToLanguage
|
||||
, languageToText
|
||||
, PerLanguageModes(..)
|
||||
, defaultLanguageModes
|
||||
, LanguageMode(..)
|
||||
) where
|
||||
|
||||
import Data.Aeson
|
||||
@ -109,17 +104,6 @@ forPath path =
|
||||
[result] -> textToLanguage result
|
||||
_ -> Unknown
|
||||
|
||||
supportedExts :: [String]
|
||||
supportedExts = foldr append mempty supportedLanguages
|
||||
where
|
||||
append (Just l) b = fmap T.unpack (Lingo.languageExtensions l) <> b
|
||||
append Nothing b = b
|
||||
supportedLanguages = fmap lookup (languageToText <$> codeNavLanguages)
|
||||
lookup k = Map.lookup k Lingo.languages
|
||||
|
||||
codeNavLanguages :: [Language]
|
||||
codeNavLanguages = [Go, Java, Ruby, Python, JavaScript, TypeScript, PHP]
|
||||
|
||||
pathIsMinified :: FilePath -> Bool
|
||||
pathIsMinified = OldPath.isExtensionOf ".min.js"
|
||||
|
||||
@ -156,29 +140,3 @@ textToLanguage = \case
|
||||
_ -> Unknown
|
||||
|
||||
|
||||
data PerLanguageModes = PerLanguageModes
|
||||
{ pythonMode :: LanguageMode
|
||||
, rubyMode :: LanguageMode
|
||||
, goMode :: LanguageMode
|
||||
, typescriptMode :: LanguageMode
|
||||
, tsxMode :: LanguageMode
|
||||
, javascriptMode :: LanguageMode
|
||||
, jsxMode :: LanguageMode
|
||||
}
|
||||
deriving (Eq, Ord, Show)
|
||||
|
||||
defaultLanguageModes :: PerLanguageModes
|
||||
defaultLanguageModes = PerLanguageModes
|
||||
{ pythonMode = ALaCarte
|
||||
, rubyMode = ALaCarte
|
||||
, goMode = ALaCarte
|
||||
, typescriptMode = ALaCarte
|
||||
, tsxMode = ALaCarte
|
||||
, javascriptMode = ALaCarte
|
||||
, jsxMode = ALaCarte
|
||||
}
|
||||
|
||||
data LanguageMode
|
||||
= ALaCarte
|
||||
| Precise
|
||||
deriving (Bounded, Enum, Eq, Ord, Read, Show)
|
||||
|
@ -74,6 +74,8 @@ instance FromJSON Blob where
|
||||
nullBlob :: Blob -> Bool
|
||||
nullBlob Blob{..} = Source.null blobSource
|
||||
|
||||
-- | Create a Blob from a provided path, language, and UTF-8 source.
|
||||
-- The resulting Blob's span is taken from the 'totalSpan' of the source.
|
||||
fromSource :: Path.PartClass.AbsRel ar => Path.File ar -> Language -> Source -> Blob
|
||||
fromSource filepath language source
|
||||
= Blob source (Analysis.File.File (Path.toAbsRel filepath) (totalSpan source) language)
|
||||
|
@ -1,5 +1,49 @@
|
||||
module Data.Language
|
||||
( module Analysis.Language
|
||||
, LanguageMode(..)
|
||||
, PerLanguageModes(..)
|
||||
, defaultLanguageModes
|
||||
, codeNavLanguages
|
||||
, supportedExts
|
||||
) where
|
||||
|
||||
import Analysis.Language
|
||||
|
||||
codeNavLanguages :: [Language]
|
||||
codeNavLanguages = [Go, Java, Ruby, Python, JavaScript, TypeScript, PHP]
|
||||
|
||||
supportedExts :: [String]
|
||||
supportedExts = foldr append mempty supportedLanguages
|
||||
where
|
||||
append (Just l) b = fmap T.unpack (Lingo.languageExtensions l) <> b
|
||||
append Nothing b = b
|
||||
supportedLanguages = fmap lookup (languageToText <$> codeNavLanguages)
|
||||
lookup k = Map.lookup k Lingo.languages
|
||||
|
||||
|
||||
data PerLanguageModes = PerLanguageModes
|
||||
{ pythonMode :: LanguageMode
|
||||
, rubyMode :: LanguageMode
|
||||
, goMode :: LanguageMode
|
||||
, typescriptMode :: LanguageMode
|
||||
, tsxMode :: LanguageMode
|
||||
, javascriptMode :: LanguageMode
|
||||
, jsxMode :: LanguageMode
|
||||
}
|
||||
deriving (Eq, Ord, Show)
|
||||
|
||||
defaultLanguageModes :: PerLanguageModes
|
||||
defaultLanguageModes = PerLanguageModes
|
||||
{ pythonMode = ALaCarte
|
||||
, rubyMode = ALaCarte
|
||||
, goMode = ALaCarte
|
||||
, typescriptMode = ALaCarte
|
||||
, tsxMode = ALaCarte
|
||||
, javascriptMode = ALaCarte
|
||||
, jsxMode = ALaCarte
|
||||
}
|
||||
|
||||
data LanguageMode
|
||||
= ALaCarte
|
||||
| Precise
|
||||
deriving (Bounded, Enum, Eq, Ord, Read, Show)
|
||||
|
@ -4,6 +4,7 @@ module Semantic.Spec (spec) where
|
||||
import Analysis.File
|
||||
import Control.Carrier.Reader
|
||||
import Control.Exception (fromException)
|
||||
import qualified Data.Blob as Blob
|
||||
import Source.Source (totalSpan)
|
||||
import SpecHelpers
|
||||
import qualified System.Path as Path
|
||||
|
Loading…
Reference in New Issue
Block a user