diff --git a/src/Rendering/Imports.hs b/src/Rendering/Imports.hs index 38d4344bc..ea6f08e04 100644 --- a/src/Rendering/Imports.hs +++ b/src/Rendering/Imports.hs @@ -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 diff --git a/test/fixtures/go/import-graph/main.json b/test/fixtures/go/import-graph/main.json index 6eb571247..7cee8511e 100644 --- a/test/fixtures/go/import-graph/main.json +++ b/test/fixtures/go/import-graph/main.json @@ -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": [ diff --git a/test/fixtures/python/import-graph/main.json b/test/fixtures/python/import-graph/main.json index 83f7b6607..3b8e74379 100644 --- a/test/fixtures/python/import-graph/main.json +++ b/test/fixtures/python/import-graph/main.json @@ -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": [ diff --git a/test/fixtures/ruby/import-graph/app.json b/test/fixtures/ruby/import-graph/app.json index d1c0dcc36..495b40290 100644 --- a/test/fixtures/ruby/import-graph/app.json +++ b/test/fixtures/ruby/import-graph/app.json @@ -48,7 +48,8 @@ ] }, "kind": "Method", - "name": "foo" + "name": "foo", + "module": "app" } ], "paths": [ diff --git a/test/fixtures/typescript/import-graph/app.json b/test/fixtures/typescript/import-graph/app.json index 76d871891..fb0724e50 100644 --- a/test/fixtures/typescript/import-graph/app.json +++ b/test/fixtures/typescript/import-graph/app.json @@ -263,7 +263,8 @@ ] }, "kind": "Function", - "name": "someFunction" + "name": "someFunction", + "module": "app" } ], "paths": [