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

Merge pull request #1518 from github/graph-filename-module

Include module names in import-graph SymbolDeclarations.
This commit is contained in:
Patrick Thomson 2018-03-02 15:42:20 -08:00 committed by GitHub
commit 70f30ab254
5 changed files with 22 additions and 11 deletions

View File

@ -46,7 +46,7 @@ renderToImports blob term = ImportSummary $ toMap (termToModule blob term)
_ -> defaultModuleName
makeModule :: (HasField fields Span, HasField fields (Maybe Declaration)) => T.Text -> Blob -> [Record fields] -> Module
makeModule name Blob{..} ds = Module name [T.pack blobPath] (T.pack . show <$> blobLanguage) (mapMaybe importSummary ds) (mapMaybe declarationSummary ds) (mapMaybe referenceSummary ds)
makeModule name Blob{..} ds = Module name [T.pack blobPath] (T.pack . show <$> blobLanguage) (mapMaybe importSummary ds) (mapMaybe (declarationSummary name) ds) (mapMaybe referenceSummary ds)
getModuleDef :: HasField fields (Maybe ModuleDef) => Record fields -> Maybe ModuleDef
@ -56,8 +56,8 @@ getModuleDef = getField
moduleDef :: HasField fields (Maybe ModuleDef) => TermF f (Record fields) a -> Maybe (Record fields)
moduleDef (In annotation _) = annotation <$ getModuleDef annotation
declarationSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe SymbolDeclaration
declarationSummary record = case getDeclaration record of
declarationSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Text -> Record fields -> Maybe SymbolDeclaration
declarationSummary module' record = case getDeclaration record of
Just declaration | FunctionDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
| MethodDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
_ -> Nothing
@ -65,6 +65,7 @@ declarationSummary record = case getDeclaration record of
{ declarationName = declarationIdentifier declaration
, declarationKind = toCategoryName declaration
, declarationSpan = getField record
, declarationModule = module'
}
importSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe ImportStatement
@ -104,6 +105,7 @@ data SymbolDeclaration = SymbolDeclaration
{ declarationName :: T.Text
, declarationKind :: T.Text
, declarationSpan :: Span
, declarationModule :: T.Text
} deriving (Generic, Eq, Show)
instance ToJSON SymbolDeclaration where
@ -111,6 +113,7 @@ instance ToJSON SymbolDeclaration where
[ "name" .= declarationName
, "kind" .= declarationKind
, "span" .= declarationSpan
, "module" .= declarationModule
]
data ImportStatement = ImportStatement

View File

@ -48,7 +48,8 @@
]
},
"kind": "Function",
"name": "foo"
"name": "foo",
"module": "app"
},
{
"span": {
@ -62,7 +63,8 @@
]
},
"kind": "Function",
"name": "main"
"name": "main",
"module": "app"
}
],
"paths": [

View File

@ -177,7 +177,8 @@
]
},
"kind": "Function",
"name": "print_cwd"
"name": "print_cwd",
"module": "main"
},
{
"span": {
@ -191,7 +192,8 @@
]
},
"kind": "Function",
"name": "create_array"
"name": "create_array",
"module": "main"
},
{
"span": {
@ -205,7 +207,8 @@
]
},
"kind": "Function",
"name": "sum_array"
"name": "sum_array",
"module": "main"
},
{
"span": {
@ -219,7 +222,8 @@
]
},
"kind": "Function",
"name": "sum_array2"
"name": "sum_array2",
"module": "main"
}
],
"paths": [

View File

@ -48,7 +48,8 @@
]
},
"kind": "Method",
"name": "foo"
"name": "foo",
"module": "app"
}
],
"paths": [

View File

@ -263,7 +263,8 @@
]
},
"kind": "Function",
"name": "someFunction"
"name": "someFunction",
"module": "app"
}
],
"paths": [