From 9ecaeedcc35b0e11aa9c4f18669b1c529b8d38b1 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Tue, 28 Jan 2020 12:42:42 -0500 Subject: [PATCH] Depend on newer semantic-source. --- semantic-analysis/semantic-analysis.cabal | 3 +- semantic-analysis/src/Analysis/File.hs | 2 +- semantic-analysis/src/Analysis/Language.hs | 136 ------------------ semantic-ast/semantic-ast.cabal | 2 +- semantic-ast/src/Marshal/JSON.hs | 33 +++-- semantic-core/semantic-core.cabal | 4 +- semantic-go/semantic-go.cabal | 2 +- semantic-java/semantic-java.cabal | 2 +- semantic-python/semantic-python.cabal | 2 +- semantic-ruby/semantic-ruby.cabal | 2 +- .../semantic-scope-graph.cabal | 2 +- semantic-tags/semantic-tags.cabal | 2 +- semantic-tsx/semantic-tsx.cabal | 2 +- semantic-typescript/semantic-typescript.cabal | 2 +- semantic.cabal | 2 +- src/Data/Blob.hs | 2 +- src/Data/Language.hs | 4 +- 17 files changed, 33 insertions(+), 171 deletions(-) delete mode 100644 semantic-analysis/src/Analysis/Language.hs diff --git a/semantic-analysis/semantic-analysis.cabal b/semantic-analysis/semantic-analysis.cabal index f3f459fd9..5f20c3d79 100644 --- a/semantic-analysis/semantic-analysis.cabal +++ b/semantic-analysis/semantic-analysis.cabal @@ -52,7 +52,6 @@ library Analysis.FlowInsensitive Analysis.ImportGraph Analysis.Intro - Analysis.Language Analysis.Name Analysis.Typecheck Control.Carrier.Fail.WithLoc @@ -71,7 +70,7 @@ library , pathtype ^>= 0.8.1 , prettyprinter >= 1.2 && < 2 , prettyprinter-ansi-terminal ^>= 1.1.1 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semilattices , terminal-size ^>= 0.3 , text ^>= 1.2.3.1 diff --git a/semantic-analysis/src/Analysis/File.hs b/semantic-analysis/src/Analysis/File.hs index 67416e058..cfaeaac9e 100644 --- a/semantic-analysis/src/Analysis/File.hs +++ b/semantic-analysis/src/Analysis/File.hs @@ -6,10 +6,10 @@ module Analysis.File , fromPath ) where -import Analysis.Language as Language import Data.Maybe (fromJust, listToMaybe) import Data.Semilattice.Lower import GHC.Stack +import Source.Language as Language import Source.Span import qualified System.Path as Path import qualified System.Path.PartClass as Path.PartClass diff --git a/semantic-analysis/src/Analysis/Language.hs b/semantic-analysis/src/Analysis/Language.hs deleted file mode 100644 index 765beb6db..000000000 --- a/semantic-analysis/src/Analysis/Language.hs +++ /dev/null @@ -1,136 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE KindSignatures #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -module Analysis.Language - ( Language (..) - , SLanguage (..) - , extensionsForLanguage - , knownLanguage - , forPath - , textToLanguage - , languageToText - ) where - -import Data.Aeson -import Data.Hashable (Hashable) -import qualified Data.Languages as Lingo -import qualified Data.Map.Strict as Map -import qualified Data.Text as T -import GHC.Generics (Generic) -import qualified System.Path as Path -import qualified System.Path.PartClass as Path.PartClass - --- | The various languages we support. -data Language - = Unknown - | Go - | Haskell - | Java - | JavaScript - | JSON - | JSX - | Markdown - | Python - | Ruby - | TypeScript - | PHP - | TSX - deriving (Eq, Generic, Ord, Read, Show, Bounded, Hashable, ToJSON, Enum) - --- | Reifies a proxied type-level 'Language' to a value. -class SLanguage (lang :: Language) where - reflect :: proxy lang -> Language - -instance SLanguage 'Unknown where - reflect _ = Unknown - -instance SLanguage 'Go where - reflect _ = Go - -instance SLanguage 'Haskell where - reflect _ = Haskell - -instance SLanguage 'Java where - reflect _ = Java - -instance SLanguage 'JavaScript where - reflect _ = JavaScript - -instance SLanguage 'JSON where - reflect _ = JSON - -instance SLanguage 'JSX where - reflect _ = JSX - -instance SLanguage 'Markdown where - reflect _ = Markdown - -instance SLanguage 'Python where - reflect _ = Python - -instance SLanguage 'Ruby where - reflect _ = Ruby - -instance SLanguage 'TypeScript where - reflect _ = TypeScript - -instance SLanguage 'PHP where - reflect _ = PHP - -instance FromJSON Language where - parseJSON = withText "Language" $ \l -> - pure $ textToLanguage l - - --- | Predicate failing on 'Unknown' and passing in all other cases. -knownLanguage :: Language -> Bool -knownLanguage = (/= Unknown) - -extensionsForLanguage :: Language -> [String] -extensionsForLanguage language = T.unpack <$> maybe mempty Lingo.languageExtensions (Map.lookup (languageToText language) Lingo.languages) - -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 - ] - allResults = Lingo.languageName <$> Lingo.languagesForPath (Path.toString path) - in case filter (not . spurious) allResults of - [result] -> textToLanguage result - _ -> Unknown - -languageToText :: Language -> T.Text -languageToText = \case - Unknown -> "Unknown" - Go -> "Go" - Haskell -> "Haskell" - Java -> "Java" - JavaScript -> "JavaScript" - JSON -> "JSON" - JSX -> "JSX" - Markdown -> "Markdown" - Python -> "Python" - Ruby -> "Ruby" - TypeScript -> "TypeScript" - TSX -> "TSX" - PHP -> "PHP" - -textToLanguage :: T.Text -> Language -textToLanguage = \case - "Go" -> Go - "Haskell" -> Haskell - "Java" -> Java - "JavaScript" -> JavaScript - "JSON" -> JSON - "JSX" -> JSX - "Markdown" -> Markdown - "Python" -> Python - "Ruby" -> Ruby - "TypeScript" -> TypeScript - "TSX" -> TSX - "PHP" -> PHP - _ -> Unknown diff --git a/semantic-ast/semantic-ast.cabal b/semantic-ast/semantic-ast.cabal index b95ebb554..70735ba2f 100644 --- a/semantic-ast/semantic-ast.cabal +++ b/semantic-ast/semantic-ast.cabal @@ -43,7 +43,7 @@ library -- other-extensions: build-depends: base ^>= 4.13 , tree-sitter ^>= 0.8 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , tree-sitter-python ^>= 0.8.1 , bytestring ^>= 0.10.8.2 , optparse-applicative >= 0.14.3 && < 0.16 diff --git a/semantic-ast/src/Marshal/JSON.hs b/semantic-ast/src/Marshal/JSON.hs index 94fbb5ea2..9a8fb1acd 100644 --- a/semantic-ast/src/Marshal/JSON.hs +++ b/semantic-ast/src/Marshal/JSON.hs @@ -1,27 +1,26 @@ -{-# LANGUAGE DefaultSignatures #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ExistentialQuantification #-} -{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE DataKinds #-} -{-# LANGUAGE TypeSynonymInstances #-} -{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE UndecidableInstances #-} module Marshal.JSON ( MarshalJSON(..) ) where -import Data.Aeson as Aeson -import Data.List.NonEmpty (NonEmpty) -import GHC.Generics -import Data.Text (Text) +import Data.Aeson as Aeson +import Data.List.NonEmpty (NonEmpty) +import Data.Text (Text) import qualified Data.Text as Text +import GHC.Generics --- TODO: range and span will require a new release of semantic-source -- TODO: use toEncoding -- direct serialization to ByteString -- Serialize unmarshaled ASTs into JSON representation by auto-deriving Aeson instances generically @@ -33,7 +32,7 @@ class MarshalJSON t where fields acc = gfields acc . from1 -- Implement the sum case -instance {-# OVERLAPPING #-} (MarshalJSON f, MarshalJSON g) => MarshalJSON (f :+: g) where +instance {-# OVERLAPPING #-} (MarshalJSON f, MarshalJSON g) => MarshalJSON (f :+: g) where fields acc (L1 f) = fields acc f fields acc (R1 g) = fields acc g @@ -71,7 +70,7 @@ instance (MarshalJSON t) => GValue (Rec1 t) where instance (GValue t) => GValue (Maybe :.: t) where gvalue (Comp1 (Just t)) = gvalue t - gvalue (Comp1 Nothing) = Null + gvalue (Comp1 Nothing) = Null instance (GValue t) => GValue ([] :.: t) where gvalue (Comp1 ts) = toJSON $ map gvalue ts @@ -85,4 +84,4 @@ class GFields f where -- gvalue is a wrapper that calls to @toJSON@ (for leaf nodes such as @Text@) or recurses via @marshal@ class GValue f where - gvalue :: (ToJSON a) => f a -> Value \ No newline at end of file + gvalue :: (ToJSON a) => f a -> Value diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index dcfd376da..cca074771 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -54,7 +54,7 @@ library , prettyprinter >= 1.2.1 && < 2 , prettyprinter-ansi-terminal ^>= 1.1.1 , semantic-analysis ^>= 0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , text ^>= 1.2.3.1 , trifecta >= 2 && < 2.2 , unordered-containers ^>= 0.2.10 @@ -69,7 +69,7 @@ test-suite test base , semantic-analysis , semantic-core - , semantic-source ^>= 0.0.1 + , semantic-source , fused-effects , fused-syntax , hedgehog ^>= 1 diff --git a/semantic-go/semantic-go.cabal b/semantic-go/semantic-go.cabal index ea7ab5515..8639a241a 100644 --- a/semantic-go/semantic-go.cabal +++ b/semantic-go/semantic-go.cabal @@ -25,7 +25,7 @@ common haskell , fused-syntax , parsers ^>= 0.12.10 , semantic-core ^>= 0.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semantic-tags ^>= 0.0 , text ^>= 1.2.3 , tree-sitter ^>= 0.8 diff --git a/semantic-java/semantic-java.cabal b/semantic-java/semantic-java.cabal index fd63d2d26..0b7a2063e 100644 --- a/semantic-java/semantic-java.cabal +++ b/semantic-java/semantic-java.cabal @@ -25,7 +25,7 @@ library build-depends: base >= 4.13 && < 5 , fused-effects ^>= 1.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semantic-tags ^>= 0.0 , tree-sitter ^>= 0.8 , tree-sitter-java ^>= 0.6.1 diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index 435f50cfd..fd31957d2 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -25,7 +25,7 @@ common haskell , fused-syntax , parsers ^>= 0.12.10 , semantic-core ^>= 0.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semantic-tags ^>= 0.0 , semantic-scope-graph ^>= 0.0 , semilattices ^>= 0 diff --git a/semantic-ruby/semantic-ruby.cabal b/semantic-ruby/semantic-ruby.cabal index 0a50fc7c8..b592485bc 100644 --- a/semantic-ruby/semantic-ruby.cabal +++ b/semantic-ruby/semantic-ruby.cabal @@ -25,7 +25,7 @@ common haskell , fused-syntax , parsers ^>= 0.12.10 , semantic-core ^>= 0.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semantic-tags ^>= 0.0 , text ^>= 1.2.3 , tree-sitter ^>= 0.8 diff --git a/semantic-scope-graph/semantic-scope-graph.cabal b/semantic-scope-graph/semantic-scope-graph.cabal index 4dc0611d9..d819a1d71 100644 --- a/semantic-scope-graph/semantic-scope-graph.cabal +++ b/semantic-scope-graph/semantic-scope-graph.cabal @@ -38,7 +38,7 @@ library , semilattices , generic-monoid , pathtype - , semantic-source ^>= 0.0 + , semantic-source ^>= 0.0.2 , text ^>= 1.2.3.1 hs-source-dirs: src default-language: Haskell2010 diff --git a/semantic-tags/semantic-tags.cabal b/semantic-tags/semantic-tags.cabal index dfbe6e9a3..d2eee1a6d 100644 --- a/semantic-tags/semantic-tags.cabal +++ b/semantic-tags/semantic-tags.cabal @@ -26,7 +26,7 @@ library build-depends: base >= 4.13 && < 5 , fused-effects ^>= 1.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , text ^>= 1.2.3.1 hs-source-dirs: src default-language: Haskell2010 diff --git a/semantic-tsx/semantic-tsx.cabal b/semantic-tsx/semantic-tsx.cabal index e54353df0..8a9357bb6 100644 --- a/semantic-tsx/semantic-tsx.cabal +++ b/semantic-tsx/semantic-tsx.cabal @@ -25,7 +25,7 @@ common haskell , fused-syntax , parsers ^>= 0.12.10 , semantic-core ^>= 0.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semantic-tags ^>= 0.0 , text ^>= 1.2.3 , tree-sitter ^>= 0.8 diff --git a/semantic-typescript/semantic-typescript.cabal b/semantic-typescript/semantic-typescript.cabal index 66042abd9..d17942aed 100644 --- a/semantic-typescript/semantic-typescript.cabal +++ b/semantic-typescript/semantic-typescript.cabal @@ -25,7 +25,7 @@ common haskell , fused-syntax , parsers ^>= 0.12.10 , semantic-core ^>= 0.0 - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semantic-tags ^>= 0.0 , text ^>= 1.2.3 , tree-sitter ^>= 0.8 diff --git a/semantic.cabal b/semantic.cabal index 6d3308fcb..6059f1075 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -68,7 +68,7 @@ common dependencies , scientific ^>= 0.3.6.2 , safe-exceptions ^>= 0.1.7.0 , semantic-analysis - , semantic-source ^>= 0.0.1 + , semantic-source ^>= 0.0.2 , semilattices ^>= 0.0.0.3 , streaming ^>= 0.2.2.0 , text ^>= 1.2.3.1 diff --git a/src/Data/Blob.hs b/src/Data/Blob.hs index 805a77c96..2834cdb6b 100644 --- a/src/Data/Blob.hs +++ b/src/Data/Blob.hs @@ -28,13 +28,13 @@ module Data.Blob import Prologue import Analysis.File (File (..)) -import Analysis.Language as Language import Control.Effect.Error import Data.Aeson import qualified Data.ByteString.Lazy as BL import Data.Edit import Data.JSON.Fields import Data.Module +import Source.Language as Language import Source.Source (Source, totalSpan) import qualified Source.Source as Source import qualified System.FilePath as FP diff --git a/src/Data/Language.hs b/src/Data/Language.hs index 5a4015076..028ad2fcb 100644 --- a/src/Data/Language.hs +++ b/src/Data/Language.hs @@ -1,5 +1,5 @@ module Data.Language - ( module Analysis.Language + ( module Source.Language , LanguageMode(..) , PerLanguageModes(..) , defaultLanguageModes @@ -7,10 +7,10 @@ module Data.Language , supportedExts ) where -import Analysis.Language import qualified Data.Languages as Lingo import qualified Data.Map.Strict as Map import qualified Data.Text as T +import Source.Language codeNavLanguages :: [Language] codeNavLanguages = [Go, Java, Ruby, Python, JavaScript, TypeScript, PHP]