1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Merge branch 'master' into definition-list-definitions

This commit is contained in:
Rob Rix 2016-02-25 11:12:18 -07:00
commit d4ab962b3e
8 changed files with 40 additions and 6 deletions

View File

@ -116,8 +116,11 @@ body {
.diff .category-undefined,
.diff .category-number,
.diff .category-function_call>li>.category-identifier,
.diff .category-function_call>li>.category-argument_list>li>.category-identifier,
.diff .category-function_call>li>.category-member_access>.category-identifier,
.diff .category-member_access>:not(:first-child)>.category-identifier {
.diff .category-member_access>:not(:first-child)>.category-identifier,
.diff .category-scope_resolution_expression>li>.category-identifier,
.diff .category-symbol {
color: #0086b3;
}
@ -127,6 +130,10 @@ body {
.diff [class^="category-"][class$="_op"],
.diff .category-ternary,
.diff .category-conditional,
.diff .category-additive,
.diff .category-multiplicative,
.diff .category-complement,
.diff .category-var_declaration,
.diff .category-new_expression,
.diff .category-if_statement,
@ -136,13 +143,23 @@ body {
.diff .category-return_statement,
.diff .category-function,
.diff .category-assignment,
.diff .category-var_assignment {
.diff .category-var_assignment,
.diff .category-method_declaration,
.diff .category-case_statement,
.diff .category-else_block,
.diff .category-when_block,
.diff .category-then_block,
.diff .category-class_declaration,
.diff .category-module_declaration {
color: #a71d5d;
}
.diff .category-function>li:first-child>.category-identifier,
.diff .category-method_declaration>li:first-child>.category-identifier,
.diff .category-new_expression>li>.category-function_call>li:first-child>.category-identifier,
.diff .category-pair>li:first-child>.category-identifier,
.diff .category-assignment>li:first-child>.category-member_access>:not(:first-child)>.category-identifier {
.diff .category-assignment>li:first-child>.category-member_access>:not(:first-child)>.category-identifier,
.diff .category-class_declaration>li>.category-identifier,
.diff .category-module_declaration>li>.category-identifier {
color: #795da3;
}

View File

@ -16,6 +16,12 @@ data Category =
| Pair
-- | A call to a function.
| FunctionCall
-- | A string literal.
| StringLiteral
-- | An integer literal.
| IntegerLiteral
-- | A symbol literal.
| SymbolLiteral
-- | A non-standard category, which can be used for comparability.
| Other String
deriving (Eq, Show, Ord)

View File

@ -26,6 +26,7 @@ parserForType :: T.Text -> Parser
parserForType mediaType = case languageForType mediaType of
Just C -> treeSitterParser C ts_language_c
Just JavaScript -> treeSitterParser JavaScript ts_language_javascript
Just Ruby -> treeSitterParser Ruby ts_language_ruby
_ -> lineByLineParser
-- | A fallback parser that treats a file simply as rows of strings.
@ -49,7 +50,7 @@ parserForFilepath = parserForType . T.pack . takeExtension
breakDownLeavesByWord :: Source Char -> Term T.Text Info -> Term T.Text Info
breakDownLeavesByWord source = cata replaceIn
where
replaceIn info@(Info range categories) (Leaf _) | ranges <- rangesAndWordsInSource range, length ranges > 1 = info :< (Indexed $ makeLeaf categories <$> ranges)
replaceIn info@(Info range categories) (Leaf _) | ranges <- rangesAndWordsInSource range, length ranges > 1 = info :< Indexed (makeLeaf categories <$> ranges)
replaceIn info syntax = info :< syntax
rangesAndWordsInSource range = rangesAndWordsFrom (start range) (Source.toList $ slice range source)
makeLeaf categories (range, substring) = Info range categories :< Leaf (T.pack substring)

View File

@ -27,4 +27,5 @@ languageForType mediaType = case mediaType of
".h" -> Just C
".c" -> Just C
".js" -> Just JavaScript
".rb" -> Just Ruby
_ -> Nothing

View File

@ -21,4 +21,4 @@ before _ = Nothing
-- | Calculate the cost of the patch given a function to compute the cost of a item.
patchSum :: (a -> Integer) -> Patch a -> Integer
patchSum termCost patch = (maybe 0 termCost $ before patch) + (maybe 0 termCost $ after patch)
patchSum termCost patch = maybe 0 termCost (before patch) + maybe 0 termCost (after patch)

View File

@ -42,6 +42,9 @@ styleName category = "category-" ++ case category of
DictionaryLiteral -> "dictionary"
Pair -> "pair"
FunctionCall -> "function_call"
StringLiteral -> "string"
SymbolLiteral -> "symbol"
IntegerLiteral -> "integer"
Other string -> string
-- | Render a diff as an HTML split diff.

View File

@ -15,6 +15,7 @@ import qualified GHC.Generics as Generics
data TSLanguage = TsLanguage deriving (Show, Eq)
foreign import ccall "prototype/doubt-difftool/doubt-difftool-Bridging-Header.h ts_language_c" ts_language_c :: Ptr TSLanguage
foreign import ccall "prototype/doubt-difftool/doubt-difftool-Bridging-Header.h ts_language_javascript" ts_language_javascript :: Ptr TSLanguage
foreign import ccall "prototype/doubt-difftool/doubt-difftool-Bridging-Header.h ts_language_ruby" ts_language_ruby :: Ptr TSLanguage
data TSDocument = TsDocument deriving (Show, Eq)
foreign import ccall "prototype/External/tree-sitter/include/tree_sitter/runtime.h ts_document_make" ts_document_make :: IO (Ptr TSDocument)
@ -57,6 +58,8 @@ categoriesForLanguage :: Language -> String -> Set.Set Category
categoriesForLanguage language name = case (language, name) of
(JavaScript, "object") -> Set.singleton DictionaryLiteral
(JavaScript, "rel_op") -> Set.singleton BinaryOperator -- relational operator, e.g. >, <, <=, >=, ==, !=
(Ruby, "hash") -> Set.singleton DictionaryLiteral
_ -> defaultCategoryForNodeName name
-- | Given a node name from TreeSitter, return the correct categories.
@ -64,6 +67,9 @@ defaultCategoryForNodeName :: String -> Set.Set Category
defaultCategoryForNodeName name = case name of
"function_call" -> Set.singleton FunctionCall
"pair" -> Set.singleton Pair
"string" -> Set.singleton StringLiteral
"integer" -> Set.singleton IntegerLiteral
"symbol" -> Set.singleton SymbolLiteral
_ -> Set.singleton (Other name)
-- | Given a constructor and a tree sitter document, return a parser.

@ -1 +1 @@
Subproject commit fa44c40c5225f01ca5d06228978ce1120f677f58
Subproject commit f6ce772297a632b644cbed1f9942de5251b32e16