@@ -14,7 +14,7 @@ import Idris.Primitives
1414import Idris.Inliner
1515import Idris.PartialEval
1616import Idris.DeepSeq
17−import Idris.Output (iputStrLn, pshow, iWarn)
17+import Idris.Output (iputStrLn, pshow, iWarn, sendHighlighting)
1818import IRTS.Lang
1919
2020import Idris.ParseExpr (tryFullExpr)
@@ -37,21 +37,22 @@ elabRecord :: ElabInfo
3737 -> (Docstring (Either Err PTerm)) -- ^ The documentation for the whole declaration
3838 -> SyntaxInfo -> FC -> DataOpts
3939 -> Name -- ^ The name of the type being defined
40+ -> FC -- ^ The precise source location of the tycon name
4041 -> [(Name, FC, Plicity, PTerm)] -- ^ Parameters
4142 -> [(Name, Docstring (Either Err PTerm))] -- ^ Parameter Docs
42− -> [((Maybe Name), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -- ^ Fields
43− -> Maybe Name -- ^ Constructor Name
43+ -> [(Maybe (Name, FC), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -- ^ Fields
44+ -> Maybe (Name, FC) -- ^ Constructor Name
4445 -> (Docstring (Either Err PTerm)) -- ^ Constructor Doc
4546 -> SyntaxInfo -- ^ Constructor SyntaxInfo
4647 -> Idris ()
47−elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
48+elabRecord info doc rsyn fc opts tyn nfc params paramDocs fields cname cdoc csyn
4849 = do logLvl 1 $ "Building data declaration for " ++ show tyn
4950 -- Type constructor
5051 let tycon = generateTyConType params
5152 logLvl 1 $ "Type constructor " ++ showTmImpls tycon
5253
5354 -- Data constructor
54− dconName <- generateDConName cname
55+ dconName <- generateDConName (fmap fst cname)
5556 let dconTy = generateDConType params fieldsWithNameAndDoc
5657 logLvl 1 $ "Data constructor: " ++ showTmImpls dconTy
5758
@@ -62,7 +63,13 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
6263
6364 iLOG $ "fieldsWithName " ++ show fieldsWithName
6465 iLOG $ "fieldsWIthNameAndDoc " ++ show fieldsWithNameAndDoc
65− elabRecordFunctions info rsyn fc tyn [(n, p, t, d) | (n, _, p, t, d) <- paramsAndDoc] fieldsWithNameAndDoc dconName target
66+ elabRecordFunctions info rsyn fc tyn paramsAndDoc fieldsWithNameAndDoc dconName target
67+
68+ sendHighlighting $
69+ [(nfc, AnnName tyn Nothing Nothing Nothing)] ++
70+ maybe [] (\(_, cnfc) -> [(cnfc, AnnName dconName Nothing Nothing Nothing)]) cname ++
71+ [(ffc, AnnBoundName fn False) | (fn, ffc, _, _, _) <- fieldsWithName]
72+
6673 where
6774 -- | Generates a type constructor.
6875 generateTyConType :: [(Name, FC, Plicity, PTerm)] -> PTerm
@@ -81,9 +88,9 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
8188 Nothing -> return n
8289
8390 -- | Generates the data constructor type.
84− generateDConType :: [(Name, FC, Plicity, PTerm)] -> [(Name, Plicity, PTerm, a)] -> PTerm
91+ generateDConType :: [(Name, FC, Plicity, PTerm)] -> [(Name, FC, Plicity, PTerm, a)] -> PTerm
8592 generateDConType ((n, nfc, _, t) : ps) as = PPi impl (nsroot n) NoFC t (generateDConType ps as)
86− generateDConType [] ((n, p, t, _) : as) = PPi p (nsroot n) NoFC t (generateDConType [] as)
93+ generateDConType [] ((n, _, p, t, _) : as) = PPi p (nsroot n) NoFC t (generateDConType [] as)
8794 generateDConType [] [] = target
8895
8996 -- | The target for the constructor and projection functions. Also the source of the update functions.
@@ -104,42 +111,43 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
104111 dconsArgDocs :: [(Name, Docstring (Either Err PTerm))]
105112 dconsArgDocs = paramDocs ++ (dcad fieldsWithName)
106113 where
107− dcad :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Docstring (Either Err PTerm))]
108− dcad ((n, _, _, (Just d)) : rest) = ((nsroot n), d) : (dcad rest)
114+ dcad :: [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Docstring (Either Err PTerm))]
115+ dcad ((n, _, _, _, (Just d)) : rest) = ((nsroot n), d) : (dcad rest)
109116 dcad (_ : rest) = dcad rest
110117 dcad [] = []
111118
112− fieldsWithName :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
119+ fieldsWithName :: [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
113120 fieldsWithName = fwn [] fields
114121 where
115− fwn :: [Name] -> [(Maybe Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
122+ fwn :: [Name] -> [(Maybe (Name, FC), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
116123 fwn ns ((n, p, t, d) : rest)
117124 = let nn = case n of
118125 Just n' -> n'
119126 Nothing -> newName ns baseName
120− in (expandNS rsyn $ nn, p, t, d) : (fwn (nn : ns) rest)
127+ withNS = expandNS rsyn (fst nn)
128+ in (withNS, snd nn, p, t, d) : (fwn (fst nn : ns) rest)
121129 fwn _ _ = []
122130
123− baseName = sUN "__pi_arg"
131+ baseName = (sUN "__pi_arg", NoFC)
124132
125− newName :: [Name] -> Name -> Name
126− newName ns n
127− | n `elem` ns = newName ns (nextName n)
128− | otherwise = n
129−
130− fieldsWithNameAndDoc :: [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
133+ newName :: [Name] -> (Name, FC) -> (Name, FC)
134+ newName ns (n, nfc)
135+ | n `elem` ns = newName ns (nextName n, nfc)
136+ | otherwise = (n, nfc)
137+
138+ fieldsWithNameAndDoc :: [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))]
131139 fieldsWithNameAndDoc = fwnad fieldsWithName
132140 where
133− fwnad :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
134− fwnad ((n, p, t, d) : rest)
141+ fwnad :: [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))]
142+ fwnad ((n, nfc, p, t, d) : rest)
135143 = let doc = fromMaybe emptyDocstring d
136− in (n, p, t, doc) : (fwnad rest)
144+ in (n, nfc, p, t, doc) : (fwnad rest)
137145 fwnad [] = []
138146
139147elabRecordFunctions :: ElabInfo -> SyntaxInfo -> FC
140148 -> Name -- ^ Record type name
141− -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Parameters
142− -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Fields
149+ -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Parameters
150+ -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Fields
143151 -> Name -- ^ Constructor Name
144152 -> PTerm -- ^ Target type
145153 -> Idris ()
@@ -164,11 +172,11 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
164172
165173 -- The parameters for elaboration with their documentation
166174 -- Parameter functions are all prefixed with "param_".
167− let paramsForElab = [((nsroot n), (paramName n), impl, t, d) | (n, _, t, d) <- params] -- zipParams i params paramDocs]
168−
175+ let paramsForElab = [((nsroot n), (paramName n), impl, t, d) | (n, _, _, t, d) <- params] -- zipParams i params paramDocs]
176+
169177 -- The fields (written by the user) with their documentation.
170− let userFieldsForElab = [((nsroot n), n, p, t, d) | (n, p, t, d) <- fields]
171−
178+ let userFieldsForElab = [((nsroot n), n, p, t, d) | (n, nfc, p, t, d) <- fields]
179+
172180 -- All things we need to elaborate projection functions for, together with a number denoting their position in the constructor.
173181 let projectors = [(n, n', p, t, d, i) | ((n, n', p, t, d), i) <- zip (freeFieldsForElab ++ paramsForElab ++ userFieldsForElab) [0..]]
174182 -- Build and elaborate projection functions
@@ -189,10 +197,10 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
189197
190198 -- | Root names of all fields in the current record declarations
191199 fieldNames :: [Name]
192− fieldNames = [nsroot n | (n, _, _, _) <- fields]
200+ fieldNames = [nsroot n | (n, _, _, _, _) <- fields]
193201
194202 paramNames :: [Name]
195− paramNames = [nsroot n | (n, _, _, _) <- params]
203+ paramNames = [nsroot n | (n, _, _, _, _) <- params]
196204
197205 isFieldOrParam :: Name -> Bool
198206 isFieldOrParam n = n `elem` (fieldNames ++ paramNames)
@@ -207,7 +215,7 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
207215 isField' (n, _, _, _, _, _) = isField n
208216
209217 fieldTerms :: [PTerm]
210− fieldTerms = [t | (_, _, t, _) <- fields]
218+ fieldTerms = [t | (_, _, _, t, _) <- fields]
211219
212220 -- Delabs the TT to PTerm
213221 -- This is not good.
@@ -263,7 +271,7 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
263271
264272 -- | A map from a field name to the other fields it depends on.
265273 fieldDependencies :: [(Name, [Name])]
266− fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, t, _) <- fields ++ params]
274+ fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, _, t, _) <- fields ++ params]
267275 where
268276 fieldDep :: Name -> PTerm -> (Name, [Name])
269277 fieldDep n t = ((nsroot n), paramNames ++ fieldNames `intersect` allNamesIn t)