@@ -92,38 +92,52 @@ import System.IO
92 ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;
92 ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;
95−moduleHeader :: IdrisParser (Maybe (Docstring ()), [String])
95+moduleHeader :: IdrisParser (Maybe (Docstring ()), [String], [(FC, OutputAnnotation)])
96moduleHeader = try (do docs <- optional docComment
96moduleHeader = try (do docs <- optional docComment
97 noArgs docs
97 noArgs docs
98 reserved "module"
98 reserved "module"
99− i <- fst <$> identifier
99+ (i, ifc) <- identifier
100 option ';' (lchar ';')
100 option ';' (lchar ';')
101+ let modName = moduleName i
101− return (fmap fst docs, moduleName i))
102+ return (fmap fst docs,
104+ [(ifc, AnnNamespace (map T.pack modName) Nothing)]))
102 <|> try (do lchar '%'; reserved "unqualified"
105 <|> try (do lchar '%'; reserved "unqualified"
103− return (Nothing, []))
106+ return (Nothing, [], []))
104− <|> return (Nothing, moduleName "Main")
107+ <|> return (Nothing, moduleName "Main", [])
105 where moduleName x = case span (/='.') x of
108 where moduleName x = case span (/='.') x of
106 (x, "") -> [x]
109 (x, "") -> [x]
107 (x, '.':y) -> x : moduleName y
110 (x, '.':y) -> x : moduleName y
108 noArgs (Just (_, args)) | not (null args) = fail "Modules do not take arguments"
111 noArgs (Just (_, args)) | not (null args) = fail "Modules do not take arguments"
109 noArgs _ = return ()
112 noArgs _ = return ()
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
111{- | Parses an import statement
122{- | Parses an import statement
114 Import ::= 'import' Identifier_t ';'?;
125 Import ::= 'import' Identifier_t ';'?;
117−import_ :: IdrisParser (Bool, String, Maybe String, FC)
128+import_ :: IdrisParser ImportInfo
118import_ = do fc <- getFC
129import_ = do fc <- getFC
119 reserved "import"
130 reserved "import"
120 reexport <- option False (do reserved "public"; return True)
131 reexport <- option False (do reserved "public"; return True)
121− id <- fst <$> identifier
132+ (id, idfc) <- identifier
122− newName <- optional (reserved "as" *> (fst <$> identifier))
133+ newName <- optional (reserved "as" *> identifier)
123 option ';' (lchar ';')
134 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
125 <?> "import statement"
138 <?> "import statement"
139+ where ns = Spl.splitOn "."
126− where toPath = foldl1' (</>) . Spl.splitOn "."
140+ toPath = foldl1' (</>) . ns
128{- | Parses program source
142{- | Parses program source
@@ -594,11 +608,12 @@ Namespace ::=
595namespace :: SyntaxInfo -> IdrisParser [PDecl]
609namespace :: SyntaxInfo -> IdrisParser [PDecl]
596namespace syn =
610namespace syn =
597− do reserved "namespace"; n <- fst <$> identifier
611+ do reserved "namespace"
612+ (n, nfc) <- identifier
598 openBlock
613 openBlock
599 ds <- some (decl syn { syn_namespace = n : syn_namespace syn })
614 ds <- some (decl syn { syn_namespace = n : syn_namespace syn })
600 closeBlock
615 closeBlock
601− return [PNamespace n (concat ds)]
616+ return [PNamespace n nfc (concat ds)]
602 <?> "namespace declaration"
617 <?> "namespace declaration"
604{- | Parses a methods block (for instances)
619{- | Parses a methods block (for instances)
@@ -1222,16 +1237,21 @@ parseTactic :: IState -> String -> Result PTactic
1222parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
1237parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
1224-- | Parse module header and imports
1239-- | 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)
1226parseImports fname input
1241parseImports fname input
1227 = do i <- getIState
1242 = do i <- getIState
1228 case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
1243 case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
1229− Failure err -> fail (show err)
1244+ Failure err -> fail (show err)
1245+ Success (x, annots, i) ->
1230− Success (x, i) -> do putIState i
1246+ do putIState i
1247+ sendHighlighting (addPath annots fname)
1231− return x
1248+ return x
1232− where imports :: IdrisParser ((Maybe (Docstring ()), [String], [(Bool, String, Maybe String, FC)], Maybe Delta), IState)
1249+ where imports :: IdrisParser ((Maybe (Docstring ()), [String],
1252+ [(FC, OutputAnnotation)], IState)
1233 imports = do whiteSpace
1253 imports = do whiteSpace
1234− (mdoc, mname) <- moduleHeader
1254+ (mdoc, mname, annots) <- moduleHeader
1235 ps <- many import_
1255 ps <- many import_
1236 mrk <- mark
1256 mrk <- mark
1237 isEof <- lookAheadMatches eof
1257 isEof <- lookAheadMatches eof
@@ -1239,7 +1259,12 @@ parseImports fname input
1239 then Nothing
1259 then Nothing
1240 else Just mrk
1260 else Just mrk
1241 i <- get
1261 i <- get
1242− return ((mdoc, mname, ps, mrk'), i)
1262+ return ((mdoc, mname, ps, mrk'), annots, i)
1263+ addPath :: [(FC, OutputAnnotation)] -> FilePath -> [(FC, OutputAnnotation)]
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
1244-- | There should be a better way of doing this...
1269-- | There should be a better way of doing this...
1245findFC :: Doc -> (FC, String)
1270findFC :: Doc -> (FC, String)
@@ -1351,23 +1376,37 @@ loadSource lidr f toline
1351 file <- if lidr then tclift $ unlit f file_in else return file_in
1376 file <- if lidr then tclift $ unlit f file_in else return file_in
1352 (mdocs, mname, imports_in, pos) <- parseImports f file
1377 (mdocs, mname, imports_in, pos) <- parseImports f file
1353 ai <- getAutoImports
1378 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
1355 ids <- allImportDirs
1380 ids <- allImportDirs
1356 ibcsd <- valIBCSubDir i
1381 ibcsd <- valIBCSubDir i
1357− mapM_ (\(re, f) ->
1382+ mapM_ (\(re, f, ns, nfc) ->
1358 do fp <- findImport ids ibcsd f
1383 do fp <- findImport ids ibcsd f
1359 case fp of
1384 case fp of
1360 LIDR fn -> ifail $ "No ibc for " ++ f
1385 LIDR fn -> ifail $ "No ibc for " ++ f
1361 IDR fn -> ifail $ "No ibc for " ++ f
1386 IDR fn -> ifail $ "No ibc for " ++ f
1362− IBC fn src -> loadIBC True fn)
1388+ do loadIBC True fn
1389+ let srcFn = case src of
1393+ sendHighlighting [(nfc, AnnNamespace ns srcFn)])
1363− [(re, fn) | (re, fn, _, _) <- imports]
1394+ [(re, fn, ns, nfc) | ImportInfo re fn _ ns _ nfc <- imports]
1364 reportParserWarnings
1395 reportParserWarnings
1366 -- process and check module aliases
1397 -- process and check module aliases
1367 let modAliases = M.fromList
1398 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
1369 prep = map T.pack . reverse . Spl.splitOn [pathSeparator]
1405 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
1371 histogram = groupBy ((==) `on` fst) . sortBy (comparing fst) $ aliasNames
1410 histogram = groupBy ((==) `on` fst) . sortBy (comparing fst) $ aliasNames
1372 case map head . filter ((/= 1) . length) $ histogram of
1411 case map head . filter ((/= 1) . length) $ histogram of
1373 [] -> logLvl 3 $ "Module aliases: " ++ show (M.toList modAliases)
1412 [] -> logLvl 3 $ "Module aliases: " ++ show (M.toList modAliases)
@@ -1379,7 +1418,12 @@ loadSource lidr f toline
1379 -- record package info in .ibc
1418 -- record package info in .ibc
1380 imps <- allImportDirs
1419 imps <- allImportDirs
1381 mapM_ addIBC (map IBCImportDir imps)
1420 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
1383 let syntax = defaultSyntax{ syn_namespace = reverse mname,
1427 let syntax = defaultSyntax{ syn_namespace = reverse mname,
1384 maxline = toline }
1428 maxline = toline }
1385 ist <- getIState
1429 ist <- getIState
@@ -1463,11 +1507,11 @@ loadSource lidr f toline
1464 namespaces :: [String] -> [PDecl] -> [PDecl]
1508 namespaces :: [String] -> [PDecl] -> [PDecl]
1465 namespaces [] ds = ds
1509 namespaces [] ds = ds
1466− namespaces (x:xs) ds = [PNamespace x (namespaces xs ds)]
1510+ namespaces (x:xs) ds = [PNamespace x NoFC (namespaces xs ds)]
1468 toMutual :: PDecl -> PDecl
1512 toMutual :: PDecl -> PDecl
1469 toMutual m@(PMutual _ d) = m
1513 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)
1471 toMutual x = let r = PMutual (fileFC "single mutual") [x] in
1515 toMutual x = let r = PMutual (fileFC "single mutual") [x] in
1472 case x of
1516 case x of
1473 PClauses{} -> r
1517 PClauses{} -> r