1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 14:13:27 +03:00

Store the DocTable in the .jvo file (#3021)

This allows the ide to display documentation for identifiers defined in
other modules.
This commit is contained in:
Jan Mas Rovira 2024-09-11 13:14:34 +02:00 committed by GitHub
parent 5d3550b760
commit 799d85034f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)]

View File

@ -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

View File

@ -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
}