From 799d85034f6dff2f25383c60c8d034a9d2e89a06 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Wed, 11 Sep 2024 13:14:34 +0200 Subject: [PATCH] Store the `DocTable` in the .jvo file (#3021) This allows the ide to display documentation for identifiers defined in other modules. --- src/Juvix/Compiler/Concrete/Data/Highlight/Builder.hs | 6 ++++++ .../Concrete/Translation/FromParsed/Analysis/Scoping.hs | 5 ++++- src/Juvix/Compiler/Pipeline/Driver.hs | 5 ++++- src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs | 6 ++++++ src/Juvix/Compiler/Store/Scoped/Language.hs | 3 +++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Juvix/Compiler/Concrete/Data/Highlight/Builder.hs b/src/Juvix/Compiler/Concrete/Data/Highlight/Builder.hs index ed7d3c1f6c..1fbbf4ed71 100644 --- a/src/Juvix/Compiler/Concrete/Data/Highlight/Builder.hs +++ b/src/Juvix/Compiler/Concrete/Data/Highlight/Builder.hs @@ -5,12 +5,14 @@ module Juvix.Compiler.Concrete.Data.Highlight.Builder ) where +import Data.HashMap.Strict qualified as HashMap import Juvix.Compiler.Concrete.Data.Highlight.Input import Juvix.Compiler.Concrete.Data.ParsedItem import Juvix.Compiler.Concrete.Data.ScopedName import Juvix.Compiler.Concrete.Language.Base import Juvix.Compiler.Internal.Language qualified as Internal import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Context +import Juvix.Compiler.Store.Scoped.Data.InfoTable import Juvix.Prelude data HighlightBuilder :: Effect where @@ -19,6 +21,8 @@ data HighlightBuilder :: Effect where HighlightName :: AName -> HighlightBuilder m () HighlightParsedItem :: ParsedItem -> HighlightBuilder m () HighlightType :: NameId -> Internal.Expression -> HighlightBuilder m () + HighlightMergeDocTable :: DocTable -> HighlightBuilder m () + GetDocTable :: ModuleId -> HighlightBuilder m DocTable makeSem ''HighlightBuilder @@ -29,6 +33,8 @@ runHighlightBuilder = reinterpret (runStateShared emptyHighlightInput) $ \case HighlightParsedItem p -> modifyShared (over (highlightParsedItems) (p :)) HighlightDoc k md -> modifyShared (set (highlightDocTable . at k) md) HighlightType uid ty -> modifyShared (set (highlightTypes . typesTable . at uid) (Just ty)) + HighlightMergeDocTable tbl -> modifyShared (over highlightDocTable (HashMap.union tbl)) + GetDocTable uid -> filterByTopModule uid <$> getsShared (^. highlightDocTable) ignoreHighlightBuilder :: Sem (HighlightBuilder ': r) a -> Sem r a ignoreHighlightBuilder = fmap snd . runHighlightBuilder diff --git a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs index 1e254786f9..7dbf00d567 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs @@ -1340,6 +1340,7 @@ checkTopModule m@Module {..} = checkedModule return (e, body', path', doc') localModules <- getLocalModules e _moduleId <- getModuleId (topModulePathKey (path' ^. S.nameConcrete)) + doctbl <- getDocTable _moduleId let md = Module { _modulePath = path', @@ -1359,7 +1360,8 @@ checkTopModule m@Module {..} = checkedModule _scopedModuleFilePath = P.getModuleFilePath m, _scopedModuleExportInfo = e, _scopedModuleLocalModules = localModules, - _scopedModuleInfoTable = tab + _scopedModuleInfoTable = tab, + _scopedModuleDocTable = doctbl } return (md, smd, sc) @@ -1830,6 +1832,7 @@ checkLocalModule md@Module {..} = do ScopedModule { _scopedModulePath = set nameConcrete (moduleNameToTopModulePath (NameUnqualified _modulePath)) moduleName, _scopedModuleName = moduleName, + _scopedModuleDocTable = mempty, _scopedModuleFilePath = P.getModuleFilePath md, _scopedModuleExportInfo = moduleExportInfo, _scopedModuleLocalModules = localModules, diff --git a/src/Juvix/Compiler/Pipeline/Driver.hs b/src/Juvix/Compiler/Pipeline/Driver.hs index bf3d8dfb4f..139e9477b5 100644 --- a/src/Juvix/Compiler/Pipeline/Driver.hs +++ b/src/Juvix/Compiler/Pipeline/Driver.hs @@ -44,6 +44,7 @@ import Juvix.Compiler.Store.Language import Juvix.Compiler.Store.Language qualified as Store import Juvix.Compiler.Store.Options qualified as StoredModule import Juvix.Compiler.Store.Options qualified as StoredOptions +import Juvix.Compiler.Store.Scoped.Language qualified as Scoped import Juvix.Data.CodeAnn import Juvix.Data.SHA256 qualified as SHA256 import Juvix.Extra.Serialize qualified as Serialize @@ -268,7 +269,9 @@ processModuleCacheMiss entryIx = do tid <- myThreadId logDecision tid (entryIx ^. entryIxImportNode) p case p of - ProcessModuleReuse r -> return r + ProcessModuleReuse r -> do + highlightMergeDocTable (r ^. pipelineResult . Store.moduleInfoScopedModule . Scoped.scopedModuleDocTable) + return r ProcessModuleRecompile recomp -> recomp ^. recompileDo processProject :: (Members '[ModuleInfoCache, Reader EntryPoint, Reader ImportTree] r) => Sem r [(ImportNode, PipelineResult ModuleInfo)] diff --git a/src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs b/src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs index 4fe2a86449..81b0abb048 100644 --- a/src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs +++ b/src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs @@ -83,3 +83,9 @@ instance Monoid InfoTable where combinePrecedenceGraphs :: PrecedenceGraph -> PrecedenceGraph -> PrecedenceGraph combinePrecedenceGraphs g1 g2 = HashMap.unionWith HashSet.union g1 g2 + +filterByTopModule :: ModuleId -> HashMap NameId b -> HashMap NameId b +filterByTopModule m = HashMap.filterWithKey (\k _v -> sameModule k) + where + sameModule :: NameId -> Bool + sameModule n = m == n ^. nameIdModuleId diff --git a/src/Juvix/Compiler/Store/Scoped/Language.hs b/src/Juvix/Compiler/Store/Scoped/Language.hs index 9f39719222..53816a85df 100644 --- a/src/Juvix/Compiler/Store/Scoped/Language.hs +++ b/src/Juvix/Compiler/Store/Scoped/Language.hs @@ -29,6 +29,9 @@ data ScopedModule = ScopedModule _scopedModuleName :: S.Name, _scopedModuleFilePath :: Path Abs File, _scopedModuleExportInfo :: ExportInfo, + -- | It contains documentation for stuff defined in this module if this + -- corresponds to a top module. It is empty for local modules + _scopedModuleDocTable :: DocTable, _scopedModuleLocalModules :: HashMap S.NameId ScopedModule, _scopedModuleInfoTable :: InfoTable }