packages feed

semantic-source 0.0.2.0 → 0.1.0.0

raw patch · 5 files changed

+34/−24 lines, 5 filesdep ~lingonew-uploaderPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: lingo

API changes (from Hackage documentation)

- Source.Span: instance Data.Semilattice.Lower.Lower Source.Span.Pos
- Source.Span: instance Data.Semilattice.Lower.Lower Source.Span.Span
+ Source.Language: CodeQL :: Language
+ Source.Language: instance Source.Language.SLanguage 'Source.Language.CodeQL

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+# 0.1.0.0++- Adds `CodeQL` language constructor.+- Bumps `lingo-haskell` to 0.3.2.+- Removes Span and Pos lower bound instances. This makes callers responsible for defining whether Span / Pos are 0 or 1 indexed.+ # 0.0.2.0  - Adds `Source.Language`.
semantic-source.cabal view
@@ -1,7 +1,7 @@ cabal-version:       2.4  name:                semantic-source-version:             0.0.2.0+version:             0.1.0.0 synopsis:            Types and functionality for working with source code description:         Types and functionality for working with source code (program text). homepage:            https://github.com/github/semantic/tree/master/semantic-source#readme@@ -55,7 +55,7 @@     , containers     ^>= 0.6.2     , generic-monoid ^>= 0.1.0.0     , hashable        >= 1.2.7 && < 1.4-    , lingo          ^>= 0.3+    , lingo          ^>= 0.3.2.0     , pathtype       ^>= 0.8.1     , semilattices   ^>= 0.0.0.3     , text           ^>= 1.2.3.1
src/Source/Language.hs view
@@ -33,11 +33,12 @@     | JSON     | JSX     | Markdown+    | PHP     | Python     | Ruby     | TypeScript-    | PHP     | TSX+    | CodeQL     deriving (Eq, Generic, Ord, Read, Show, Bounded, Hashable, ToJSON, Enum)  -- | Reifies a proxied type-level 'Language' to a value.@@ -47,6 +48,9 @@ instance SLanguage 'Unknown where   reflect _ = Unknown +instance SLanguage 'CodeQL where+  reflect _ = CodeQL+ instance SLanguage 'Go where   reflect _ = Go @@ -68,6 +72,9 @@ instance SLanguage 'Markdown where   reflect _ = Markdown +instance SLanguage 'PHP where+  reflect _ = PHP+ instance SLanguage 'Python where   reflect _ = Python @@ -77,9 +84,6 @@ instance SLanguage 'TypeScript where   reflect _ = TypeScript -instance SLanguage 'PHP where-  reflect _ = PHP- instance FromJSON Language where   parseJSON = withText "Language" $ \l ->     pure $ textToLanguage l@@ -106,6 +110,7 @@ languageToText :: Language -> T.Text languageToText = \case   Unknown -> "Unknown"+  CodeQL -> "CodeQL"   Go -> "Go"   Haskell -> "Haskell"   Java -> "Java"@@ -113,14 +118,15 @@   JSON -> "JSON"   JSX -> "JSX"   Markdown -> "Markdown"+  PHP -> "PHP"   Python -> "Python"   Ruby -> "Ruby"   TypeScript -> "TypeScript"   TSX -> "TSX"-  PHP -> "PHP"  textToLanguage :: T.Text -> Language textToLanguage = \case+  "CodeQL" -> CodeQL   "Go" -> Go   "Haskell" -> Haskell   "Java" -> Java@@ -128,9 +134,9 @@   "JSON" -> JSON   "JSX" -> JSX   "Markdown" -> Markdown+  "PHP" -> PHP   "Python" -> Python   "Ruby" -> Ruby   "TypeScript" -> TypeScript   "TSX" -> TSX-  "PHP" -> PHP   _ -> Unknown
src/Source/Source.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-| 'Source' models source code, represented as a thin wrapper around a 'B.ByteString' with conveniences for splitting by line, slicing, etc. @@ -37,7 +38,7 @@ import qualified Data.ByteString as B import           Data.Char (ord) import           Data.Maybe (fromMaybe)-import           Data.Monoid (Last(..))+import           Data.Monoid (Last (..)) import           Data.Semilattice.Lower import           Data.String (IsString (..)) import qualified Data.Text as T@@ -45,7 +46,7 @@ import           Data.Text.Encoding.Error (lenientDecode) import           GHC.Generics (Generic) import           Source.Range-import           Source.Span (Span(Span), Pos(..))+import           Source.Span (Pos (..), Span (Span))   -- | The contents of a source file. This is represented as a UTF-8@@ -75,7 +76,7 @@  -- | Return a 'Span' that covers the entire text. totalSpan :: Source -> Span-totalSpan source = Span lowerBound (Pos (Prelude.length ranges) (succ (end lastRange - start lastRange))) where+totalSpan source = Span (Pos 1 1) (Pos (Prelude.length ranges) (succ (end lastRange - start lastRange))) where   ranges = lineRanges source   lastRange = fromMaybe lowerBound (getLast (foldMap (Last . Just) ranges)) 
src/Source/Span.hs view
@@ -1,4 +1,6 @@-{-# LANGUAGE DeriveGeneric, OverloadedStrings, RankNTypes #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RankNTypes #-} -- | Source position and span information -- --   Mostly taken from purescript's SourcePos definition.@@ -16,9 +18,8 @@ import           Data.Aeson ((.:), (.=)) import qualified Data.Aeson as A import           Data.Hashable (Hashable)-import           Data.Semilattice.Lower (Lower(..)) import           GHC.Generics (Generic)-import           GHC.Stack (SrcLoc(..))+import           GHC.Stack (SrcLoc (..))  -- | A Span of position information data Span = Span@@ -44,10 +45,6 @@     <$> o .: "start"     <*> o .: "end" -instance Lower Span where-  lowerBound = Span lowerBound lowerBound-- -- | Construct a Span with a given value for both its start and end positions. point :: Pos -> Span point p = Span p p@@ -56,7 +53,11 @@ spanFromSrcLoc s = Span (Pos (srcLocStartLine s) (srcLocStartCol s)) (Pos (srcLocEndLine s) (srcLocEndCol s))  --- | Source position information (1-indexed)+-- | Source position information.+-- The 'Pos' values associated with ASTs returned from tree-sitter+-- 'Unmarshal' instances are zero-indexed. Unless you are displaying+-- span information to a user, you should write your code assuming+-- zero-indexing. data Pos = Pos   { line   :: {-# UNPACK #-} !Int   , column :: {-# UNPACK #-} !Int@@ -76,10 +77,6 @@   parseJSON arr = do     [ line, col ] <- A.parseJSON arr     pure $ Pos line col--instance Lower Pos where-  lowerBound = Pos 1 1-  line_, column_ :: Lens' Pos Int line_   = lens line   (\p l -> p { line   = l })