1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Merge branch 'master' into improve-memory-usage

This commit is contained in:
Josh Vera 2016-10-13 16:21:11 -04:00 committed by GitHub
commit 9f9dc4feab
3 changed files with 13 additions and 203 deletions

View File

@ -70,6 +70,7 @@ isErrorSummary _ = False
data DiffInfo = LeafInfo { categoryName :: Text, termName :: Text, sourceSpan :: SourceSpan }
| BranchInfo { branches :: [ DiffInfo ], categoryName :: Text, branchType :: Branch }
| ErrorInfo { errorSpan :: SourceSpan, termName :: Text }
| HideInfo -- Hide/Strip from summary output entirely.
deriving (Eq, Show)
data Branch = BIndexed | BFixed | BCommented deriving (Show, Eq, Generic)
@ -147,6 +148,7 @@ determiner _ = "the"
toLeafInfos :: DiffInfo -> [JSONSummary Doc SourceSpan]
toLeafInfos err@ErrorInfo{..} = pure $ ErrorSummary (pretty err) errorSpan
toLeafInfos BranchInfo{..} = branches >>= toLeafInfos
toLeafInfos HideInfo = []
toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
(LeafInfo "number" termName _) -> squotes $ toDoc termName
(LeafInfo "boolean" termName _) -> squotes $ toDoc termName
@ -242,7 +244,8 @@ termToDiffInfo blob term = case unwrap term of
S.Indexed children -> BranchInfo (termToDiffInfo' <$> children) (toCategoryName term) BIndexed
S.Fixed children -> BranchInfo (termToDiffInfo' <$> children) (toCategoryName term) BFixed
S.AnonymousFunction _ _ -> LeafInfo "anonymous function" (toTermName' term) (getField $ extract term)
Commented cs leaf -> BranchInfo (termToDiffInfo' <$> cs <> maybeToList leaf) (toCategoryName term) BCommented
S.Comment _ -> HideInfo
S.Commented cs leaf -> BranchInfo (termToDiffInfo' <$> cs <> maybeToList leaf) (toCategoryName term) BCommented
S.Error _ -> ErrorInfo (getField $ extract term) (toTermName' term)
_ -> LeafInfo (toCategoryName term) (toTermName' term) (getField $ extract term)
where toTermName' = toTermName blob
@ -347,3 +350,4 @@ instance P.Pretty DiffInfo where
pretty LeafInfo{..} = squotes (string $ toSL termName) <+> string (toSL categoryName)
pretty BranchInfo{..} = mconcat $ punctuate (string "," P.<> space) (pretty <$> branches)
pretty ErrorInfo{..} = squotes (string $ toSL termName) <+> "at" <+> (string . toSL $ displayStartEndPos errorSpan)
pretty HideInfo = ""

View File

@ -49,6 +49,7 @@ termConstructor source sourceSpan name range children
("case", [ expr, body ]) -> S.Case expr body
("object", _) -> S.Object $ foldMap toTuple children
("pair", _) -> S.Fixed children
("comment", _) -> S.Comment . toText $ slice range source
("if_statement", [ expr, clause1, clause2 ]) -> S.If expr clause1 (Just clause2)
("if_statement", [ expr, clause ]) -> S.If expr clause Nothing
("while_statement", [ expr, body ]) -> S.While expr body

View File

@ -1,25 +1,7 @@
[{
"testCaseDescription": "javascript-comment-insert-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"insert": {
"start": [
1,
1
],
"end": [
1,
22
]
}
},
"summary": "Added the '// This is a property' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [
@ -32,40 +14,7 @@
,{
"testCaseDescription": "javascript-comment-replacement-insert-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"insert": {
"start": [
1,
1
],
"end": [
3,
3
]
}
},
"summary": "Added the '/*\n * This is a method\n*/' comment"
},
{
"span": {
"insert": {
"start": [
4,
1
],
"end": [
4,
22
]
}
},
"summary": "Added the '// This is a property' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [
@ -78,37 +27,7 @@
,{
"testCaseDescription": "javascript-comment-delete-insert-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"replace": [
{
"start": [
1,
1
],
"end": [
3,
3
]
},
{
"start": [
1,
1
],
"end": [
1,
22
]
}
]
},
"summary": "Replaced the '/*\n * This is a method\n*/' comment with the '// This is a property' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [
@ -121,37 +40,7 @@
,{
"testCaseDescription": "javascript-comment-replacement-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"replace": [
{
"start": [
1,
1
],
"end": [
1,
22
]
},
{
"start": [
1,
1
],
"end": [
3,
3
]
}
]
},
"summary": "Replaced the '// This is a property' comment with the '/*\n * This is a method\n*/' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [
@ -164,55 +53,7 @@
,{
"testCaseDescription": "javascript-comment-delete-replacement-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
3,
3
]
}
},
"summary": "Deleted the '/*\n * This is a method\n*/' comment"
},
{
"span": {
"delete": {
"start": [
4,
1
],
"end": [
4,
22
]
}
},
"summary": "Deleted the '// This is a property' comment"
},
{
"span": {
"insert": {
"start": [
2,
1
],
"end": [
4,
3
]
}
},
"summary": "Added the '/*\n * This is a method\n*/' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [
@ -225,25 +66,7 @@
,{
"testCaseDescription": "javascript-comment-delete-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
1,
22
]
}
},
"summary": "Deleted the '// This is a property' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [
@ -256,25 +79,7 @@
,{
"testCaseDescription": "javascript-comment-delete-rest-test",
"expectedResult": {
"changes": {
"comment.js": [
{
"span": {
"delete": {
"start": [
1,
1
],
"end": [
3,
3
]
}
},
"summary": "Deleted the '/*\n * This is a method\n*/' comment"
}
]
},
"changes": {},
"errors": {}
},
"filePaths": [