mirror of
https://github.com/github/semantic.git
synced 2024-12-27 17:05:33 +03:00
Merge pull request #1518 from github/graph-filename-module
Include module names in import-graph SymbolDeclarations.
This commit is contained in:
commit
70f30ab254
@ -46,7 +46,7 @@ renderToImports blob term = ImportSummary $ toMap (termToModule blob term)
|
|||||||
_ -> defaultModuleName
|
_ -> defaultModuleName
|
||||||
|
|
||||||
makeModule :: (HasField fields Span, HasField fields (Maybe Declaration)) => T.Text -> Blob -> [Record fields] -> Module
|
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
|
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 :: HasField fields (Maybe ModuleDef) => TermF f (Record fields) a -> Maybe (Record fields)
|
||||||
moduleDef (In annotation _) = annotation <$ getModuleDef annotation
|
moduleDef (In annotation _) = annotation <$ getModuleDef annotation
|
||||||
|
|
||||||
declarationSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe SymbolDeclaration
|
declarationSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Text -> Record fields -> Maybe SymbolDeclaration
|
||||||
declarationSummary record = case getDeclaration record of
|
declarationSummary module' record = case getDeclaration record of
|
||||||
Just declaration | FunctionDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
|
Just declaration | FunctionDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
|
||||||
| MethodDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
|
| MethodDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
@ -65,6 +65,7 @@ declarationSummary record = case getDeclaration record of
|
|||||||
{ declarationName = declarationIdentifier declaration
|
{ declarationName = declarationIdentifier declaration
|
||||||
, declarationKind = toCategoryName declaration
|
, declarationKind = toCategoryName declaration
|
||||||
, declarationSpan = getField record
|
, declarationSpan = getField record
|
||||||
|
, declarationModule = module'
|
||||||
}
|
}
|
||||||
|
|
||||||
importSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe ImportStatement
|
importSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe ImportStatement
|
||||||
@ -104,6 +105,7 @@ data SymbolDeclaration = SymbolDeclaration
|
|||||||
{ declarationName :: T.Text
|
{ declarationName :: T.Text
|
||||||
, declarationKind :: T.Text
|
, declarationKind :: T.Text
|
||||||
, declarationSpan :: Span
|
, declarationSpan :: Span
|
||||||
|
, declarationModule :: T.Text
|
||||||
} deriving (Generic, Eq, Show)
|
} deriving (Generic, Eq, Show)
|
||||||
|
|
||||||
instance ToJSON SymbolDeclaration where
|
instance ToJSON SymbolDeclaration where
|
||||||
@ -111,6 +113,7 @@ instance ToJSON SymbolDeclaration where
|
|||||||
[ "name" .= declarationName
|
[ "name" .= declarationName
|
||||||
, "kind" .= declarationKind
|
, "kind" .= declarationKind
|
||||||
, "span" .= declarationSpan
|
, "span" .= declarationSpan
|
||||||
|
, "module" .= declarationModule
|
||||||
]
|
]
|
||||||
|
|
||||||
data ImportStatement = ImportStatement
|
data ImportStatement = ImportStatement
|
||||||
|
6
test/fixtures/go/import-graph/main.json
vendored
6
test/fixtures/go/import-graph/main.json
vendored
@ -48,7 +48,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "foo"
|
"name": "foo",
|
||||||
|
"module": "app"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"span": {
|
"span": {
|
||||||
@ -62,7 +63,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "main"
|
"name": "main",
|
||||||
|
"module": "app"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": [
|
"paths": [
|
||||||
|
12
test/fixtures/python/import-graph/main.json
vendored
12
test/fixtures/python/import-graph/main.json
vendored
@ -177,7 +177,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "print_cwd"
|
"name": "print_cwd",
|
||||||
|
"module": "main"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"span": {
|
"span": {
|
||||||
@ -191,7 +192,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "create_array"
|
"name": "create_array",
|
||||||
|
"module": "main"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"span": {
|
"span": {
|
||||||
@ -205,7 +207,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "sum_array"
|
"name": "sum_array",
|
||||||
|
"module": "main"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"span": {
|
"span": {
|
||||||
@ -219,7 +222,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "sum_array2"
|
"name": "sum_array2",
|
||||||
|
"module": "main"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": [
|
"paths": [
|
||||||
|
3
test/fixtures/ruby/import-graph/app.json
vendored
3
test/fixtures/ruby/import-graph/app.json
vendored
@ -48,7 +48,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Method",
|
"kind": "Method",
|
||||||
"name": "foo"
|
"name": "foo",
|
||||||
|
"module": "app"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": [
|
"paths": [
|
||||||
|
@ -263,7 +263,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"kind": "Function",
|
"kind": "Function",
|
||||||
"name": "someFunction"
|
"name": "someFunction",
|
||||||
|
"module": "app"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": [
|
"paths": [
|
||||||
|
Loading…
Reference in New Issue
Block a user