Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GeneratedInfo from HieAST before generating references map #73

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/HieDb/Create.hs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,20 @@ addRefsFromLoaded_unsafe
mod = moduleName smod
uid = moduleUnit smod
smod = hie_module hf
refmap = generateReferencesMap $ getAsts $ hie_asts hf
refmap = generateReferencesMap $ fmap dropGeneratedInfo $ getAsts $ hie_asts hf
(srcFile, isReal) = case sourceFile of
RealFile f -> (Just f, True)
FakeFile mf -> (mf, False)
modrow = HieModuleRow path (ModuleInfo mod uid isBoot srcFile isReal hash)

-- We only want to index references to things that actually occur in source code
-- (i.e. NodeOrigin is SourceInfo, not GeneratedInfo).
-- So before generating RefMap we drop all GeneratedInfo from the AST.
dropGeneratedInfo :: HieAST a -> HieAST a
dropGeneratedInfo (Node (SourcedNodeInfo sniMap) sp children) =
let sourceOnlyNodeInfo = SourcedNodeInfo $ M.delete GeneratedInfo sniMap
in Node sourceOnlyNodeInfo sp (map dropGeneratedInfo children)

execute conn "INSERT INTO mods VALUES (?,?,?,?,?,?,?)" modrow

let AstInfo rows decls imports = genAstInfo path smod refmap
Expand Down