Skip to content

Commit

Permalink
add topDef property for vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Dec 3, 2024
1 parent 7db7444 commit 38cd7e7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
11 changes: 11 additions & 0 deletions src/Juvix/Compiler/Concrete/Data/Highlight.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ buildProperties HighlightInput {..} =
<> mapMaybe goFaceName _highlightNames
<> map goFaceError _highlightErrors,
_propertiesGoto = map goGotoProperty _highlightNames,
_propertiesTopDef = mapMaybe goDefProperty _highlightNames,
_propertiesInfo = mapMaybe (goDocProperty _highlightDocTable _highlightTypes) _highlightNames
}

goFaceError :: Interval -> WithLoc PropertyFace
goFaceError i = WithLoc i (PropertyFace FaceError)

goDefProperty :: AName -> Maybe (WithLoc PropertyTopDef)
goDefProperty n = do
guard (n ^. anameIsTop)
guard ((n ^. anameLoc) == (n ^. anameDefinedLoc))
return
WithLoc
{ _withLocInt = n ^. anameLoc,
_withLocParam = PropertyTopDef (n ^. anameVerbatim)
}

goFaceSemanticItem :: SemanticItem -> Maybe (WithLoc PropertyFace)
goFaceSemanticItem i = WithLoc (getLoc i) . PropertyFace <$> f
where
Expand Down
13 changes: 7 additions & 6 deletions src/Juvix/Compiler/Concrete/Data/InfoTableBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ data InfoTableBuilder :: Effect where
RegisterConstructor :: ConstructorDef 'Scoped -> InfoTableBuilder m ()
RegisterInductive :: InductiveDef 'Scoped -> InfoTableBuilder m ()
RegisterFunctionDef :: FunctionDef 'Scoped -> InfoTableBuilder m ()
RegisterName :: (HasLoc c) => S.Name' c -> InfoTableBuilder m ()
RegisterScopedIden :: ScopedIden -> InfoTableBuilder m ()
RegisterName :: (HasLoc c) => Bool -> S.Name' c -> InfoTableBuilder m ()
RegisterScopedIden :: Bool -> ScopedIden -> InfoTableBuilder m ()
RegisterModuleDoc :: S.NameId -> Maybe (Judoc 'Scoped) -> InfoTableBuilder m ()
RegisterFixity :: FixityDef -> InfoTableBuilder m ()
RegisterPrecedence :: S.NameId -> S.NameId -> InfoTableBuilder m ()
Expand Down Expand Up @@ -65,8 +65,8 @@ runInfoTableBuilder ini = reinterpret (runState ini) $ \case
fid = f ^. functionDefName . functionDefNameScoped . nameId
modify' (over infoFunctions (HashMap.insert fid f))
highlightDoc fid j
RegisterName n -> highlightName (S.anameFromName n)
RegisterScopedIden n -> highlightName (anameFromScopedIden n)
RegisterName isTop n -> highlightName (S.anameFromName isTop n)
RegisterScopedIden isTop n -> highlightName (anameFromScopedIden isTop n)
RegisterModuleDoc uid doc -> highlightDoc uid doc
RegisterFixity f -> do
let sid = f ^. fixityDefSymbol . S.nameId
Expand Down Expand Up @@ -143,10 +143,11 @@ runInfoTableBuilderRepl tab = ignoreHighlightBuilder . runInfoTableBuilder tab .
ignoreInfoTableBuilder :: (Members '[Error ScoperError, HighlightBuilder] r) => Sem (InfoTableBuilder ': r) a -> Sem r a
ignoreInfoTableBuilder = fmap snd . runInfoTableBuilder mempty

anameFromScopedIden :: ScopedIden -> AName
anameFromScopedIden s =
anameFromScopedIden :: Bool -> ScopedIden -> AName
anameFromScopedIden isTop s =
AName
{ _anameLoc = getLoc s,
_anameIsTop = isTop,
_anameKindPretty = getNameKindPretty s,
_anameDocId = s ^. scopedIdenFinal . nameId,
_anameDefinedLoc = s ^. scopedIdenSrcName . nameDefined,
Expand Down
6 changes: 4 additions & 2 deletions src/Juvix/Compiler/Concrete/Data/ScopedName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ data AName = AName
{ _anameLoc :: Interval,
_anameDefinedLoc :: Interval,
_anameKindPretty :: NameKind,
_anameIsTop :: Bool,
_anameDocId :: NameId,
_anameVerbatim :: Text
}
Expand All @@ -118,13 +119,14 @@ instance NFData AName
makeLenses ''Name'
makeLenses ''AName

anameFromName :: (HasLoc c) => Name' c -> AName
anameFromName n =
anameFromName :: (HasLoc c) => Bool -> Name' c -> AName
anameFromName isTop n =
AName
{ _anameLoc = getLoc n,
_anameDefinedLoc = n ^. nameDefined,
_anameKindPretty = getNameKindPretty n,
_anameDocId = n ^. nameId,
_anameIsTop = isTop,
_anameVerbatim = n ^. nameVerbatim
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ reserveSymbolOfNameSpace ns kind kindPretty nameSig builtin s = do
whenJust nameSig (modify' . set (scoperNameSignatures . at (s' ^. S.nameId)) . Just)
whenJust nameSig (registerParsedNameSig (s' ^. S.nameId))
modify (set (scopeNameSpaceLocal sns . at s) (Just s'))
registerName s'
let isTop = case strat of
BindingLocal -> False
BindingTop -> True
registerName isTop s'
let u = S.unqualifiedSymbol s'
entry :: NameSpaceEntryType ns
entry =
Expand Down Expand Up @@ -644,8 +647,8 @@ checkImportNoPublic import_@Import {..} = do
qual' = do
asName <- _importAsName
return (set S.nameConcrete asName sname')
registerName importName
whenJust synonymName registerName
registerName False importName
whenJust synonymName (registerName False)
registerScoperModules scopedModule
importOpen' <- mapM (checkOpenModuleShort scopedModule) _importOpen
usingHiding' <- mapM (checkUsingHiding importName exportInfoOriginal) _importUsingHiding
Expand Down Expand Up @@ -852,7 +855,7 @@ entryToScopedIden name e = do
{ _scopedIdenAlias = Just scopedName',
_scopedIdenFinal = helper (e' ^. symbolEntry)
}
registerScopedIden si
registerScopedIden False si
return si

-- | We gather all symbols which have been defined or marked to be public in the given scope.
Expand Down Expand Up @@ -1492,7 +1495,7 @@ checkTopModule m@Module {..} = checkedModule
_nameIterator :: Maybe IteratorInfo
_nameIterator = Nothing
moduleName = S.Name' {..}
registerName moduleName
registerName True moduleName
return moduleName

iniScope :: Scope
Expand Down Expand Up @@ -2007,7 +2010,7 @@ checkLocalModule md@Module {..} = do
}
modify (over scoperModules (HashMap.insert mid smod))
registerLocalModule smod
registerName _modulePath'
registerName True _modulePath'
return m
where
inheritScope :: (Members '[Error ScoperError, State Scope, Reader ScopeParameters, State ScoperState, InfoTableBuilder, Reader InfoTable, NameIdGen, Reader PackageId, Reader BindingStrategy] r') => Sem r' ()
Expand Down Expand Up @@ -2111,7 +2114,7 @@ checkUsingHiding modulepath exportInfo = \case
}
entry <- maybe err return mentry
let scopedSym = entryToSymbol entry s
registerName scopedSym
registerName False scopedSym
return scopedSym

checkHidingList :: HidingList 'Parsed -> Sem r (HidingList 'Scoped)
Expand Down Expand Up @@ -2157,7 +2160,7 @@ checkUsingHiding modulepath exportInfo = \case
let scopedAs = do
c <- i ^. usingAs
return (set S.nameConcrete c scopedSym)
mapM_ registerName scopedAs
mapM_ (registerName False) scopedAs
return
UsingItem
{ _usingSymbol = scopedSym,
Expand All @@ -2174,7 +2177,7 @@ checkOpenModuleHelper ::
Sem r (OpenModule 'Scoped short)
checkOpenModuleHelper openedModule OpenModule {..} = do
let exportInfo = openedModule ^. scopedModuleExportInfo
registerName (openedModule ^. scopedModuleName)
registerName False (openedModule ^. scopedModuleName)
usingHiding' <- mapM (checkUsingHiding (openedModule ^. scopedModulePath) exportInfo) _openModuleUsingHiding
mergeScope (filterExportInfo _openModulePublic usingHiding' exportInfo)
let openName :: OpenModuleNameType 'Scoped short = case sing :: SIsOpenShort short of
Expand Down Expand Up @@ -2711,7 +2714,7 @@ checkFixitySymbol s = do
[] -> throw (ErrSymNotInScope (NotInScope s scope))
[x] -> do
let res = entryToSymbol x s
registerName res
registerName False res
return res
es -> throw (ErrAmbiguousSym (AmbiguousSym n (map (PreSymbolFinal . SymbolEntry . (^. fixityEntry)) es)))
where
Expand Down
1 change: 1 addition & 0 deletions src/Juvix/Compiler/Nockma/Highlight.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ buildProperties HighlightInput {..} =
mapMaybe goFaceSemanticItem _highlightSemanticItems
<> map goFaceError _highlightErrors,
_propertiesGoto = [],
_propertiesTopDef = [],
_propertiesInfo = map goInfoNockOp _highlightNockOps <> map goInfoPath _highlightPaths
}

Expand Down
15 changes: 14 additions & 1 deletion src/Juvix/Emacs/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ data PropertyGoto = PropertyGoto
_gotoPos :: FileLoc
}

-- | Location where a top symbol is defined
newtype PropertyTopDef = PropertyTopDef
{ _topDef :: Text
}

newtype PropertyFace = PropertyFace
{ _faceFace :: Face
}
Expand All @@ -100,13 +105,15 @@ data PropertyInfo = PropertyInfo
data LocProperties = LocProperties
{ _propertiesGoto :: [WithLoc PropertyGoto],
_propertiesFace :: [WithLoc PropertyFace],
_propertiesTopDef :: [WithLoc PropertyTopDef],
_propertiesInfo :: [WithLoc PropertyInfo]
}

data RawProperties = RawProperties
{ _rawPropertiesFace :: [RawWithLoc RawFace],
_rawPropertiesGoto :: [RawWithLoc RawGoto],
_rawPropertiesDoc :: [RawWithLoc RawType]
_rawPropertiesDoc :: [RawWithLoc RawType],
_rawPropertiesTopDef :: [RawWithLoc RawTopDef]
}

-- | (File, Start Row, Start Col, Length, End Row, End Col)
Expand All @@ -119,6 +126,8 @@ type RawFace = Face
-- | (TargetFile, TargetLine, TargetColumn)
type RawGoto = (Path Abs File, Int, Int)

type RawTopDef = Text

-- | (Type)
type RawType = Text

Expand All @@ -135,6 +144,7 @@ rawProperties LocProperties {..} =
RawProperties
{ _rawPropertiesGoto = map (rawWithLoc rawGoto) _propertiesGoto,
_rawPropertiesFace = map (rawWithLoc rawFace) _propertiesFace,
_rawPropertiesTopDef = map (rawWithLoc rawTopDef) _propertiesTopDef,
_rawPropertiesDoc = map (rawWithLoc rawType) _propertiesInfo
}
where
Expand All @@ -160,6 +170,9 @@ rawProperties LocProperties {..} =
rawFace :: PropertyFace -> RawFace
rawFace PropertyFace {..} = _faceFace

rawTopDef :: PropertyTopDef -> RawTopDef
rawTopDef PropertyTopDef {..} = _topDef

rawGoto :: PropertyGoto -> RawGoto
rawGoto PropertyGoto {..} =
( _gotoFile,
Expand Down

0 comments on commit 38cd7e7

Please sign in to comment.