1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Split out and include imports in this response

This commit is contained in:
Timothy Clem 2018-01-23 11:43:31 -08:00
parent a6fbebbf6d
commit 2ff77c9000

View File

@ -27,16 +27,30 @@ renderToImports :: (HasField fields (Maybe Declaration), HasField fields Span, F
renderToImports Blob{..} term = [toJSON (termToC blobPath term)] renderToImports Blob{..} term = [toJSON (termToC blobPath term)]
where where
termToC :: (HasField fields (Maybe Declaration), HasField fields Span, Foldable f, Functor f) => FilePath -> Term f (Record fields) -> Module termToC :: (HasField fields (Maybe Declaration), HasField fields Span, Foldable f, Functor f) => FilePath -> Term f (Record fields) -> Module
termToC path = Module (T.pack (takeBaseName path)) (T.pack path) (T.pack . show <$> blobLanguage) . mapMaybe declarationSummary . termTableOfContentsBy declaration termToC path term = let toc = termTableOfContentsBy declaration term in Module
{ moduleName = T.pack (takeBaseName path)
, modulePath = T.pack path
, moduleLanguage = T.pack . show <$> blobLanguage
, moduleImports = mapMaybe importSummary toc
, moduleDeclarations = mapMaybe declarationSummary toc
}
-- | Construct a 'Symbol' from a node annotation and a change type label.
declarationSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe SymbolDeclaration declarationSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe SymbolDeclaration
declarationSummary record = case getDeclaration record of declarationSummary record = case getDeclaration record of
Just ErrorDeclaration{} -> Nothing Just declaration | FunctionDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
Just declaration -> Just SymbolDeclaration | MethodDeclaration{} <- declaration -> Just (makeSymbolDeclaration declaration)
{ declarationName = declarationIdentifier declaration _ -> Nothing
, declarationKind = toCategoryName declaration where makeSymbolDeclaration declaration = SymbolDeclaration
, declarationSpan = getField record { declarationName = declarationIdentifier declaration
, declarationKind = toCategoryName declaration
, declarationSpan = getField record
}
importSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Maybe SymbolImport
importSummary record = case getDeclaration record of
Just ImportDeclaration{..} -> Just SymbolImport
{ symbolName = declarationIdentifier
, symbolSpan = getField record
} }
_ -> Nothing _ -> Nothing
@ -44,7 +58,7 @@ data Module = Module
{ moduleName :: T.Text { moduleName :: T.Text
, modulePath :: T.Text , modulePath :: T.Text
, moduleLanguage :: Maybe T.Text , moduleLanguage :: Maybe T.Text
-- , moduleImports :: [SymbolImports] , moduleImports :: [SymbolImport]
, moduleDeclarations :: [SymbolDeclaration] , moduleDeclarations :: [SymbolDeclaration]
-- , moduleReferences :: [SymbolReferences] -- , moduleReferences :: [SymbolReferences]
} deriving (Generic, Eq, Show) } deriving (Generic, Eq, Show)
@ -53,6 +67,7 @@ instance ToJSON Module where
toJSON Module{..} = object [ "name" .= moduleName toJSON Module{..} = object [ "name" .= moduleName
, "path" .= modulePath , "path" .= modulePath
, "langauge" .= moduleLanguage , "langauge" .= moduleLanguage
, "imports" .= moduleImports
, "declarations" .= moduleDeclarations , "declarations" .= moduleDeclarations
] ]
@ -67,3 +82,12 @@ instance ToJSON SymbolDeclaration where
, "kind" .= declarationKind , "kind" .= declarationKind
, "span" .= declarationSpan , "span" .= declarationSpan
] ]
data SymbolImport = SymbolImport
{ symbolName :: T.Text
, symbolSpan :: Span
} deriving (Generic, Eq, Show)
instance ToJSON SymbolImport where
toJSON SymbolImport{..} = object [ "name" .= symbolName
, "span" .= symbolSpan ]