mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Merge branch 'split-diffs-in-haskell' of https://github.com/github/semantic-diff into split-diffs-in-haskell
This commit is contained in:
commit
4853095dbd
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -12,7 +12,7 @@
|
||||
url = https://github.com/typelift/SwiftCheck.git
|
||||
[submodule "prototype/External/tree-sitter"]
|
||||
path = prototype/External/tree-sitter
|
||||
url = https://github.com/joshvera/tree-sitter.git
|
||||
url = https://github.com/maxbrunsfeld/tree-sitter.git
|
||||
[submodule "prototype/External/tree-sitter-javascript"]
|
||||
path = prototype/External/tree-sitter-javascript
|
||||
url = https://github.com/maxbrunsfeld/tree-sitter-javascript.git
|
||||
|
@ -5,6 +5,7 @@ import Diff
|
||||
import Interpreter
|
||||
import Patch
|
||||
import Syntax
|
||||
import Range
|
||||
import Split
|
||||
import Term
|
||||
import Unified
|
||||
|
11
app/Split.hs
11
app/Split.hs
@ -4,7 +4,7 @@ import Diff
|
||||
import Patch
|
||||
import Syntax
|
||||
import Term
|
||||
import Unified
|
||||
import Range
|
||||
import Control.Comonad.Cofree
|
||||
import Control.Monad.Free
|
||||
import qualified Data.Map as Map
|
||||
@ -12,7 +12,6 @@ import qualified Data.Set as Set
|
||||
import Rainbow
|
||||
|
||||
type ClassName = String
|
||||
type Element a = Cofree (Syntax a) (Maybe ClassName, String)
|
||||
|
||||
data HTML =
|
||||
Text String
|
||||
@ -39,10 +38,10 @@ splitPatch before _ (Delete a) = Delete $ termToHTML before a
|
||||
|
||||
termToHTML :: String -> Term a Info -> (HTML, Range)
|
||||
termToHTML source = cata toElement where
|
||||
toElement (Info range lineRange categories) (Leaf _) = (Span (classify categories) $ substring range source, range)
|
||||
toElement (Info range lineRange categories) (Indexed i) = makeList i range categories
|
||||
toElement (Info range lineRange categories) (Fixed i) = makeList i range categories
|
||||
toElement (Info range lineRange categories) (Keyed k) = makeMap (Map.toList k) range categories
|
||||
toElement (Info range _ categories) (Leaf _) = (Span (classify categories) $ substring range source, range)
|
||||
toElement (Info range _ categories) (Indexed i) = makeList i range categories
|
||||
toElement (Info range _ categories) (Fixed i) = makeList i range categories
|
||||
toElement (Info range _ categories) (Keyed k) = makeMap (Map.toList k) range categories
|
||||
|
||||
accumulate (children, previous) (child, range) = (children ++ [ subtext previous $ start range, child ], end range)
|
||||
accumulateFromMap (children, previous) (key, (child, range)) = (children ++ [ subtext previous $ start range, Dt key, child ], end range)
|
||||
|
@ -4,6 +4,7 @@ import Diff
|
||||
import Patch
|
||||
import Syntax
|
||||
import Term
|
||||
import Range
|
||||
import Control.Arrow
|
||||
import Control.Monad.Free
|
||||
import Control.Comonad.Cofree
|
||||
@ -36,9 +37,6 @@ unified diff before after = do
|
||||
accumulateContext (out, previous) (child, Just range) = (mconcat [ out, pure . chunk $ substring Range { start = previous, end = start range } source, child ], end range)
|
||||
accumulateContext (out, previous) (child, _) = (out <> child, previous)
|
||||
|
||||
substring :: Range -> String -> String
|
||||
substring range = take (end range - start range) . drop (start range)
|
||||
|
||||
range :: Patch (Term a Info) -> Maybe Range
|
||||
range patch = range . extract <$> after patch where
|
||||
extract (annotation :< _) = annotation
|
||||
@ -47,5 +45,3 @@ range patch = range . extract <$> after patch where
|
||||
change :: String -> [Chunk String] -> [Chunk String]
|
||||
change bound content = [ chunk "{", chunk bound ] ++ content ++ [ chunk bound, chunk "}" ]
|
||||
|
||||
instance Ord Range where
|
||||
a <= b = start a <= start b
|
||||
|
2
prototype/External/tree-sitter
vendored
2
prototype/External/tree-sitter
vendored
@ -1 +1 @@
|
||||
Subproject commit 9da4aeaeffc73ffb9effd5cafaee0ea59dea556f
|
||||
Subproject commit b7decfa52ef6880d922ced8a725827fafa37a3e6
|
@ -22,6 +22,7 @@ library
|
||||
, SES
|
||||
, Categorizable
|
||||
, Term
|
||||
, Range
|
||||
build-depends: base >= 4.8 && < 5
|
||||
, containers
|
||||
, free
|
||||
|
@ -5,14 +5,12 @@ import Data.Set
|
||||
import Control.Monad.Free
|
||||
import Patch
|
||||
import Term
|
||||
import Range
|
||||
import Categorizable
|
||||
|
||||
data Annotated a annotation f = Annotated annotation (Syntax a f)
|
||||
deriving (Functor, Eq, Show, Foldable)
|
||||
|
||||
data Range = Range { start :: Int, end :: Int }
|
||||
deriving (Eq, Show)
|
||||
|
||||
|
||||
type Category = String
|
||||
data Info = Info { characterRange :: Range, lineRange :: Range, categories :: (Set Category) }
|
||||
|
10
src/Range.hs
Normal file
10
src/Range.hs
Normal file
@ -0,0 +1,10 @@
|
||||
module Range where
|
||||
|
||||
data Range = Range { start :: Int, end :: Int }
|
||||
deriving (Eq, Show)
|
||||
|
||||
substring :: Range -> String -> String
|
||||
substring range = take (end range - start range) . drop (start range)
|
||||
|
||||
instance Ord Range where
|
||||
a <= b = start a <= start b
|
Loading…
Reference in New Issue
Block a user