@@ -92,38 +92,52 @@ import System.IO
9292 ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;
9393@
9494-}
95−moduleHeader :: IdrisParser (Maybe (Docstring ()), [String])
95+moduleHeader :: IdrisParser (Maybe (Docstring ()), [String], [(FC, OutputAnnotation)])
9696moduleHeader = try (do docs <- optional docComment
9797 noArgs docs
9898 reserved "module"
99− i <- fst <$> identifier
99+ (i, ifc) <- identifier
100100 option ';' (lchar ';')
101− return (fmap fst docs, moduleName i))
101+ let modName = moduleName i
102+ return (fmap fst docs,
103+ modName,
104+ [(ifc, AnnNamespace (map T.pack modName) Nothing)]))
102105 <|> try (do lchar '%'; reserved "unqualified"
103− return (Nothing, []))
104− <|> return (Nothing, moduleName "Main")
106+ return (Nothing, [], []))
107+ <|> return (Nothing, moduleName "Main", [])
105108 where moduleName x = case span (/='.') x of
106109 (x, "") -> [x]
107110 (x, '.':y) -> x : moduleName y
108111 noArgs (Just (_, args)) | not (null args) = fail "Modules do not take arguments"
109112 noArgs _ = return ()
110113
114+data ImportInfo = ImportInfo { import_reexport :: Bool
115+ , import_path :: FilePath
116+ , import_rename :: Maybe (String, FC)
117+ , import_namespace :: [T.Text]
118+ , import_location :: FC
119+ , import_modname_location :: FC
120+ }
121+
111122{- | Parses an import statement
112123
113124@
114125 Import ::= 'import' Identifier_t ';'?;
115126@
116127 -}
117−import_ :: IdrisParser (Bool, String, Maybe String, FC)
128+import_ :: IdrisParser ImportInfo
118129import_ = do fc <- getFC
119130 reserved "import"
120131 reexport <- option False (do reserved "public"; return True)
121− id <- fst <$> identifier
122− newName <- optional (reserved "as" *> (fst <$> identifier))
132+ (id, idfc) <- identifier
133+ newName <- optional (reserved "as" *> identifier)
123134 option ';' (lchar ';')
124− return (reexport, toPath id, toPath <$> newName, fc)
135+ return $ ImportInfo reexport (toPath id)
136+ (fmap (\(n, fc) -> (toPath n, fc)) newName)
137+ (map T.pack $ ns id) fc idfc
125138 <?> "import statement"
126− where toPath = foldl1' (</>) . Spl.splitOn "."
139+ where ns = Spl.splitOn "."
140+ toPath = foldl1' (</>) . ns
127141
128142{- | Parses program source
129143
@@ -594,11 +608,12 @@ Namespace ::=
594608-}
595609namespace :: SyntaxInfo -> IdrisParser [PDecl]
596610namespace syn =
597− do reserved "namespace"; n <- fst <$> identifier
611+ do reserved "namespace"
612+ (n, nfc) <- identifier
598613 openBlock
599614 ds <- some (decl syn { syn_namespace = n : syn_namespace syn })
600615 closeBlock
601− return [PNamespace n (concat ds)]
616+ return [PNamespace n nfc (concat ds)]
602617 <?> "namespace declaration"
603618
604619{- | Parses a methods block (for instances)
@@ -1222,16 +1237,21 @@ parseTactic :: IState -> String -> Result PTactic
12221237parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
12231238
12241239-- | Parse module header and imports
1225−parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [(Bool, String, Maybe String, FC)], Maybe Delta)
1240+parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [ImportInfo], Maybe Delta)
12261241parseImports fname input
12271242 = do i <- getIState
12281243 case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
1229− Failure err -> fail (show err)
1230− Success (x, i) -> do putIState i
1231− return x
1232− where imports :: IdrisParser ((Maybe (Docstring ()), [String], [(Bool, String, Maybe String, FC)], Maybe Delta), IState)
1244+ Failure err -> fail (show err)
1245+ Success (x, annots, i) ->
1246+ do putIState i
1247+ sendHighlighting (addPath annots fname)
1248+ return x
1249+ where imports :: IdrisParser ((Maybe (Docstring ()), [String],
1250+ [ImportInfo],
1251+ Maybe Delta),
1252+ [(FC, OutputAnnotation)], IState)
12331253 imports = do whiteSpace
1234− (mdoc, mname) <- moduleHeader
1254+ (mdoc, mname, annots) <- moduleHeader
12351255 ps <- many import_
12361256 mrk <- mark
12371257 isEof <- lookAheadMatches eof
@@ -1239,7 +1259,12 @@ parseImports fname input
12391259 then Nothing
12401260 else Just mrk
12411261 i <- get
1242− return ((mdoc, mname, ps, mrk'), i)
1262+ return ((mdoc, mname, ps, mrk'), annots, i)
1263+ addPath :: [(FC, OutputAnnotation)] -> FilePath -> [(FC, OutputAnnotation)]
1264+ addPath [] _ = []
1265+ addPath ((fc, AnnNamespace ns Nothing) : annots) path =
1266+ (fc, AnnNamespace ns (Just path)) : addPath annots path
1267+ addPath (annot:annots) path = annot : addPath annots path
12431268
12441269-- | There should be a better way of doing this...
12451270findFC :: Doc -> (FC, String)
@@ -1351,23 +1376,37 @@ loadSource lidr f toline
13511376 file <- if lidr then tclift $ unlit f file_in else return file_in
13521377 (mdocs, mname, imports_in, pos) <- parseImports f file
13531378 ai <- getAutoImports
1354− let imports = map (\n -> (True, n, Just n, emptyFC)) ai ++ imports_in
1379+ let imports = map (\n -> ImportInfo True n Nothing [] NoFC NoFC) ai ++ imports_in
13551380 ids <- allImportDirs
13561381 ibcsd <- valIBCSubDir i
1357− mapM_ (\(re, f) ->
1382+ mapM_ (\(re, f, ns, nfc) ->
13581383 do fp <- findImport ids ibcsd f
13591384 case fp of
13601385 LIDR fn -> ifail $ "No ibc for " ++ f
13611386 IDR fn -> ifail $ "No ibc for " ++ f
1362− IBC fn src -> loadIBC True fn)
1363− [(re, fn) | (re, fn, _, _) <- imports]
1387+ IBC fn src ->
1388+ do loadIBC True fn
1389+ let srcFn = case src of
1390+ IDR fn -> Just fn
1391+ LIDR fn -> Just fn
1392+ _ -> Nothing
1393+ sendHighlighting [(nfc, AnnNamespace ns srcFn)])
1394+ [(re, fn, ns, nfc) | ImportInfo re fn _ ns _ nfc <- imports]
13641395 reportParserWarnings
13651396
13661397 -- process and check module aliases
13671398 let modAliases = M.fromList
1368− [(prep alias, prep realName) | (reexport, realName, Just alias, fc) <- imports]
1399+ [ (prep alias, prep realName)
1400+ | ImportInfo { import_reexport = reexport
1401+ , import_path = realName
1402+ , import_rename = Just (alias, _)
1403+ , import_location = fc } <- imports
1404+ ]
13691405 prep = map T.pack . reverse . Spl.splitOn [pathSeparator]
1370− aliasNames = [(alias, fc) | (_, _, Just alias, fc) <- imports]
1406+ aliasNames = [ (alias, fc)
1407+ | ImportInfo { import_rename = Just (alias, _)
1408+ , import_location = fc } <- imports
1409+ ]
13711410 histogram = groupBy ((==) `on` fst) . sortBy (comparing fst) $ aliasNames
13721411 case map head . filter ((/= 1) . length) $ histogram of
13731412 [] -> logLvl 3 $ "Module aliases: " ++ show (M.toList modAliases)
@@ -1379,7 +1418,12 @@ loadSource lidr f toline
13791418 -- record package info in .ibc
13801419 imps <- allImportDirs
13811420 mapM_ addIBC (map IBCImportDir imps)
1382− mapM_ (addIBC . IBCImport) [(reexport, realName) | (reexport, realName, alias, fc) <- imports]
1421+ mapM_ (addIBC . IBCImport)
1422+ [ (reexport, realName)
1423+ | ImportInfo { import_reexport = reexport
1424+ , import_path = realName
1425+ } <- imports
1426+ ]
13831427 let syntax = defaultSyntax{ syn_namespace = reverse mname,
13841428 maxline = toline }
13851429 ist <- getIState
@@ -1463,11 +1507,11 @@ loadSource lidr f toline
14631507 where
14641508 namespaces :: [String] -> [PDecl] -> [PDecl]
14651509 namespaces [] ds = ds
1466− namespaces (x:xs) ds = [PNamespace x (namespaces xs ds)]
1510+ namespaces (x:xs) ds = [PNamespace x NoFC (namespaces xs ds)]
14671511
14681512 toMutual :: PDecl -> PDecl
14691513 toMutual m@(PMutual _ d) = m
1470− toMutual (PNamespace x ds) = PNamespace x (map toMutual ds)
1514+ toMutual (PNamespace x fc ds) = PNamespace x fc (map toMutual ds)
14711515 toMutual x = let r = PMutual (fileFC "single mutual") [x] in
14721516 case x of
14731517 PClauses{} -> r