1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 21:01:35 +03:00

Merge remote-tracking branch 'origin/master' into add-bribe

This commit is contained in:
Patrick Thomson 2019-03-18 15:30:53 -04:00
commit 5a0a841c69
18 changed files with 1032 additions and 245 deletions

View File

@ -1,7 +1,7 @@
---
type: cabal
name: cmark-gfm
version: 0.1.6
version: 0.1.8
summary: Fast, accurate GitHub Flavored Markdown parser and renderer
homepage: https://github.com/kivikakk/cmark-gfm-hs
license: bsd-3-clause

View File

@ -44,19 +44,19 @@ message ParseTreeGraphResponse {
message ParseTreeFileGraph {
string path = 1;
Language language = 2;
string language = 2;
repeated TermVertex vertices = 3;
repeated TermEdge edges = 4;
repeated ParseError errors = 5;
}
message TermEdge {
int64 source = 1;
int64 target = 2;
int32 source = 1;
int32 target = 2;
}
message TermVertex {
int64 vertex_id = 1;
int32 vertex_id = 1;
string term = 2;
Span span = 3;
}
@ -75,7 +75,7 @@ message DiffTreeTOCResponse {
message TOCSummaryFile {
string path = 1;
Language language = 2;
string language = 2;
repeated TOCSummaryChange changes = 3;
repeated TOCSummaryError errors = 4;
}
@ -105,19 +105,19 @@ message DiffTreeGraphResponse {
message DiffTreeFileGraph {
string path = 1;
Language language = 2;
string language = 2;
repeated DiffTreeVertex vertices = 3;
repeated DiffTreeEdge edges = 4;
repeated ParseError errors = 5;
}
message DiffTreeEdge {
int64 source = 1;
int64 target = 2;
int32 source = 1;
int32 target = 2;
}
message DiffTreeVertex {
int64 diff_vertex_id = 1;
int32 diff_vertex_id = 1;
oneof diff_term {
DeletedTerm deleted = 2;
InsertedTerm inserted = 3;
@ -149,25 +149,10 @@ message MergedTerm {
Span after_span = 3;
}
enum Language {
UNKNOWN = 0;
GO = 1;
HASKELL = 2;
JAVA = 3;
JAVASCRIPT = 4;
JSON = 5;
JSX = 6;
MARKDOWN = 7;
PYTHON = 8;
RUBY = 9;
TYPESCRIPT = 10;
PHP = 11;
}
message Blob {
string content = 1;
string path = 2;
Language language = 3;
string language = 3;
}
message BlobPair {
@ -177,7 +162,7 @@ message BlobPair {
message File {
string path = 1;
Language language = 2;
string language = 2;
repeated Symbol symbols = 3;
repeated ParseError errors = 4;
}
@ -195,8 +180,8 @@ message Docstring {
}
message Position {
int64 line = 1;
int64 column = 2;
int32 line = 1;
int32 column = 2;
}
message Span {

View File

@ -30,7 +30,7 @@ import Data.Abstract.Declarations as X
import Data.Abstract.FreeVariables as X
import Data.Abstract.Module
import Data.Abstract.Name as X
import qualified Data.Abstract.ScopeGraph as ScopeGraph
import qualified Data.Abstract.ScopeGraph as ScopeGraph
import Data.Abstract.ScopeGraph (Relation(..))
import Data.Abstract.AccessControls.Class as X
import Data.Language

View File

@ -5,8 +5,8 @@ module Data.Syntax.Expression where
import Prelude hiding (null)
import Prologue hiding (This, index, null)
import Control.Abstract hiding (Bitwise (..), Call, Member, Void)
import Data.Abstract.Evaluatable as Abstract hiding (Member, Void)
import Control.Abstract hiding (Bitwise (..), Call, Member)
import Data.Abstract.Evaluatable as Abstract hiding (Member)
import Data.Abstract.Name as Name
import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedFloorDiv)
import Data.Fixed

View File

@ -2,7 +2,7 @@
{-# OPTIONS_GHC -Wno-missing-export-lists #-}
module Data.Syntax.Type where
import Data.Abstract.Evaluatable hiding (Void)
import Data.Abstract.Evaluatable
import Data.JSON.Fields
import Diffing.Algorithm
import Prelude hiding (Bool, Float, Int, Double)

View File

@ -11,6 +11,7 @@ import Analysis.ConstructorName
import Control.Effect
import Control.Effect.Fresh
import Control.Effect.Reader
import Control.Effect.State
import Data.Diff
import Data.Graph
import Data.Location
@ -28,9 +29,13 @@ renderTreeGraph :: (Ord vertex, Recursive t, ToTreeGraph vertex (Base t)) => t -
renderTreeGraph = simplify . runGraph . cata toTreeGraph
runGraph :: ReaderC (Graph vertex)
(FreshC VoidC) (Graph vertex)
(FreshC PureC) (Graph vertex)
-> Graph vertex
runGraph = run . runFresh . runReader mempty
runGraph = run . runFresh' . runReader mempty
where
-- NB: custom runFresh so that we count starting at 1 in order to avoid
-- default values for proto encoding.
runFresh' = evalState 1 . runFreshC
-- | GraphViz styling for terms
termStyle :: (IsString string, Monoid string) => String -> Style TermVertex string

View File

@ -20,7 +20,7 @@ import qualified Data.Source as Source
type Translator
= StateC [Scope]
( ErrorC TranslationError VoidC)
( ErrorC TranslationError PureC)
contextualizing :: ProcessT Translator Token Fragment
contextualizing = repeatedly $ await >>= \case

View File

@ -11,4 +11,4 @@ import Semantic.Api.Diffs as DiffsAPI
import Semantic.Api.Symbols as SymbolsAPI
import Semantic.Api.Terms as TermsAPI
import Semantic.Api.TOCSummaries as TOCSummariesAPI
import Semantic.Api.V1.CodeAnalysisPB as Types hiding (Language(..))
import Semantic.Api.V1.CodeAnalysisPB as Types

View File

@ -63,37 +63,37 @@ instance APIConvert Legacy.Span Data.Span where
toAPI Data.Span{..} = Legacy.Span (bridging #? spanStart) (bridging #? spanEnd)
fromAPI Legacy.Span {..} = Data.Span <$> (start >>= preview bridging) <*> (end >>= preview bridging)
instance APIBridge API.Language Data.Language where
instance APIBridge T.Text Data.Language where
bridging = iso apiLanguageToLanguage languageToApiLanguage where
languageToApiLanguage :: Data.Language -> API.Language
languageToApiLanguage :: Data.Language -> T.Text
languageToApiLanguage = \case
Data.Unknown -> API.Unknown
Data.Go -> API.Go
Data.Haskell -> API.Haskell
Data.Java -> API.Java
Data.JavaScript -> API.Javascript
Data.JSON -> API.Json
Data.JSX -> API.Jsx
Data.Markdown -> API.Markdown
Data.Python -> API.Python
Data.Ruby -> API.Ruby
Data.TypeScript -> API.Typescript
Data.PHP -> API.Php
Data.Unknown -> "Unknown"
Data.Go -> "Go"
Data.Haskell -> "Haskell"
Data.Java -> "Java"
Data.JavaScript -> "JavaScript"
Data.JSON -> "JSON"
Data.JSX -> "JSX"
Data.Markdown -> "Markdown"
Data.Python -> "Python"
Data.Ruby -> "Ruby"
Data.TypeScript -> "TypeScript"
Data.PHP -> "PHP"
apiLanguageToLanguage :: API.Language -> Data.Language
apiLanguageToLanguage :: T.Text -> Data.Language
apiLanguageToLanguage = \case
API.Unknown -> Data.Unknown
API.Go -> Data.Go
API.Haskell -> Data.Haskell
API.Java -> Data.Java
API.Javascript -> Data.JavaScript
API.Json -> Data.JSON
API.Jsx -> Data.JSX
API.Markdown -> Data.Markdown
API.Python -> Data.Python
API.Ruby -> Data.Ruby
API.Typescript -> Data.TypeScript
API.Php -> Data.PHP
"Go" -> Data.Go
"Haskell" -> Data.Haskell
"Java" -> Data.Java
"JavaScript" -> Data.JavaScript
"JSON" -> Data.JSON
"JSX" -> Data.JSX
"Markdown" -> Data.Markdown
"Python" -> Data.Python
"Ruby" -> Data.Ruby
"TypeScript" -> Data.TypeScript
"PHP" -> Data.PHP
_ -> Data.Unknown
instance APIBridge API.Blob Data.Blob where
bridging = iso apiBlobToBlob blobToApiBlob where

View File

@ -35,7 +35,7 @@ import Rendering.Graph
import Rendering.JSON hiding (JSON)
import qualified Rendering.JSON
import Semantic.Api.Bridge
import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, BlobPair, Language(..))
import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, BlobPair)
import Semantic.Task as Task
import Semantic.Telemetry as Stat
import Serializing.Format hiding (JSON)

View File

@ -38,7 +38,7 @@ import Rendering.Graph
import Rendering.JSON hiding (JSON)
import qualified Rendering.JSON
import Semantic.Api.Bridge
import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, Language (..))
import Semantic.Api.V1.CodeAnalysisPB hiding (Blob)
import Semantic.Task
import Serializing.Format hiding (JSON)
import qualified Serializing.Format as Format

File diff suppressed because it is too large Load Diff

View File

@ -479,6 +479,9 @@ scopeGraphRubyProject = justEvaluatingCatchingErrors <=< evaluateProjectForScope
scopeGraphPHPProject :: ProjectEvaluator Language.PHP.Assignment.Syntax
scopeGraphPHPProject = justEvaluatingCatchingErrors <=< evaluateProjectForScopeGraph (Proxy @'Language.PHP) phpParser
scopeGraphPythonProject :: ProjectEvaluator Language.Python.Assignment.Syntax
scopeGraphPythonProject = justEvaluatingCatchingErrors <=< evaluateProjectForScopeGraph (Proxy @'Language.Python) pythonParser
scopeGraphGoProject :: ProjectEvaluator Language.Go.Assignment.Syntax
scopeGraphGoProject = justEvaluatingCatchingErrors <=< evaluateProjectForScopeGraph (Proxy @'Language.Go) goParser

View File

@ -39,7 +39,7 @@ type ContextToken = (Text, Maybe Range)
type Contextualizer
= StateC [ContextToken]
( ErrorC TranslationError VoidC)
( ErrorC TranslationError PureC)
contextualizing :: Blob -> Machine.ProcessT Contextualizer Token Tag
contextualizing Blob{..} = repeatedly $ await >>= \case

View File

@ -149,22 +149,22 @@ spec = parallel $ do
it "produces JSON output" $ do
blobs <- blobsForPaths (Both "ruby/toc/methods.A.rb" "ruby/toc/methods.B.rb")
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.B.rb\",\"changes\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"category\":\"Method\",\"term\":\"self.foo\",\"changeType\":\"Added\"},{\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":6,\"column\":4}},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"Modified\"},{\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"Removed\"}],\"language\":\"Ruby\",\"errors\":[]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.B.rb\",\"language\":\"Ruby\",\"changes\":[{\"category\":\"Method\",\"term\":\"self.foo\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"changeType\":\"ADDED\"},{\"category\":\"Method\",\"term\":\"bar\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":6,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Method\",\"term\":\"baz\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"changeType\":\"REMOVED\"}]}]}\n" :: ByteString)
it "produces JSON output if there are parse errors" $ do
blobs <- blobsForPaths (Both "ruby/toc/methods.A.rb" "ruby/toc/methods.X.rb")
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\",\"changes\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"Removed\"},{\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"Removed\"}],\"language\":\"Ruby\",\"errors\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":3}},\"error\":\"expected end of input nodes, but got ParseError\"}]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\",\"language\":\"Ruby\",\"changes\":[{\"category\":\"Method\",\"term\":\"bar\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"changeType\":\"REMOVED\"},{\"category\":\"Method\",\"term\":\"baz\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"changeType\":\"REMOVED\"}],\"errors\":[{\"error\":\"expected end of input nodes, but got ParseError\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":3}}}]}]}\n" :: ByteString)
it "ignores anonymous functions" $ do
blobs <- blobsForPaths (Both "ruby/toc/lambda.A.rb" "ruby/toc/lambda.B.rb")
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/lambda.A.rb -> test/fixtures/ruby/toc/lambda.B.rb\",\"changes\":[],\"language\":\"Ruby\",\"errors\":[]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/lambda.A.rb -> test/fixtures/ruby/toc/lambda.B.rb\",\"language\":\"Ruby\"}]}\n" :: ByteString)
it "summarizes Markdown headings" $ do
blobs <- blobsForPaths (Both "markdown/toc/headings.A.md" "markdown/toc/headings.B.md")
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/markdown/toc/headings.A.md -> test/fixtures/markdown/toc/headings.B.md\",\"changes\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":3,\"column\":16}},\"category\":\"Heading 1\",\"term\":\"Introduction\",\"changeType\":\"Removed\"},{\"span\":{\"start\":{\"line\":5,\"column\":1},\"end\":{\"line\":7,\"column\":4}},\"category\":\"Heading 2\",\"term\":\"Two\",\"changeType\":\"Modified\"},{\"span\":{\"start\":{\"line\":9,\"column\":1},\"end\":{\"line\":11,\"column\":10}},\"category\":\"Heading 3\",\"term\":\"This heading is new\",\"changeType\":\"Added\"},{\"span\":{\"start\":{\"line\":13,\"column\":1},\"end\":{\"line\":14,\"column\":4}},\"category\":\"Heading 1\",\"term\":\"Final\",\"changeType\":\"Added\"}],\"language\":\"Markdown\",\"errors\":[]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/markdown/toc/headings.A.md -> test/fixtures/markdown/toc/headings.B.md\",\"language\":\"Markdown\",\"changes\":[{\"category\":\"Heading 1\",\"term\":\"Introduction\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":3,\"column\":16}},\"changeType\":\"REMOVED\"},{\"category\":\"Heading 2\",\"term\":\"Two\",\"span\":{\"start\":{\"line\":5,\"column\":1},\"end\":{\"line\":7,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Heading 3\",\"term\":\"This heading is new\",\"span\":{\"start\":{\"line\":9,\"column\":1},\"end\":{\"line\":11,\"column\":10}},\"changeType\":\"ADDED\"},{\"category\":\"Heading 1\",\"term\":\"Final\",\"span\":{\"start\":{\"line\":13,\"column\":1},\"end\":{\"line\":14,\"column\":4}},\"changeType\":\"ADDED\"}]}]}\n" :: ByteString)
type Diff' = Diff ListableSyntax (Maybe Declaration) (Maybe Declaration)

View File

@ -2,8 +2,11 @@
"files": [
{
"path": "test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb",
"language": "Ruby",
"changes": [
{
"category": "Method",
"term": "bar",
"span":
{
"start":
@ -17,11 +20,7 @@
"column": 4
}
},
"category": "Method",
"term": "bar",
"changeType": "Modified"
}],
"language": "Ruby",
"errors": []
"changeType": "MODIFIED"
}]
}]
}

View File

@ -2,8 +2,12 @@
"files": [
{
"path": "test/fixtures/ruby/corpus/method-declaration.A.rb",
"language": "Ruby",
"symbols": [
{
"symbol": "foo",
"kind": "Method",
"line": "def foo",
"span":
{
"start":
@ -16,13 +20,7 @@
"line": 2,
"column": 4
}
},
"kind": "Method",
"symbol": "foo",
"line": "def foo",
"docs": null
}],
"language": "Ruby",
"errors": []
}
}]
}]
}

@ -1 +1 @@
Subproject commit 17b0a846aa50fd0dea157624c031a550d8edd469
Subproject commit 25e66959978147b9ee1510ec3d90cd0045cfba54