on master help sign in
Highlight names in directives

Compiler directives that contain names now get full highlighting for those names.

commite04ba85c2f62a007265830575f1a60c4ddd6c768 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateFri 17 Jul 2015, 12:45 (11 years ago) parentd4f9deb
3 files changed+28−18
src/Idris/AbsSyntaxTree.hs+2−2 src/Idris/Directives.hs+19−9 src/Idris/Parser.hs+7−7
src/Idris/AbsSyntaxTree.hs+2−2
@@ -678,8 +678,8 @@ data Directive = DLib Codegen String |
678678 DDefault Bool |
679679 DLogging Integer |
680680 DDynamicLibs [String] |
681− DNameHint Name [Name] |
682− DErrorHandlers Name Name [Name] |
681+ DNameHint Name FC [(Name, FC)] |
682+ DErrorHandlers Name FC Name FC [(Name, FC)] |
683683 DLanguage LanguageExt |
684684 DUsed FC Name Name
685685
src/Idris/Directives.hs+19−9
@@ -4,6 +4,7 @@ module Idris.Directives(directiveAction) where
44import Idris.AbsSyntax
55import Idris.ASTUtils
66import Idris.Imports
7+import Idris.Output (sendHighlighting)
78
89import Idris.Core.Evaluate
910import Idris.Core.TT
@@ -43,15 +44,24 @@ directiveAction (DDynamicLibs libs) = do added <- addDyLib libs
4344 Left lib -> addIBC (IBCDyLib (lib_name lib))
4445 Right msg -> fail $ msg
4546
46−directiveAction (DNameHint ty ns) = do ty' <- disambiguate ty
47− mapM_ (addNameHint ty') ns
48− mapM_ (\n -> addIBC (IBCNameHint (ty', n))) ns
49−
50−directiveAction (DErrorHandlers fn arg ns) = do fn' <- disambiguate fn
51− ns' <- mapM disambiguate ns
52− addFunctionErrorHandlers fn' arg ns'
53− mapM_ (addIBC .
54− IBCFunctionErrorHandler fn' arg) ns'
47+directiveAction (DNameHint ty tyFC ns) = do ty' <- disambiguate ty
48+ mapM_ (addNameHint ty' . fst) ns
49+ mapM_ (\n -> addIBC (IBCNameHint (ty', fst n))) ns
50+ sendHighlighting $
51+ [(tyFC, AnnName ty' Nothing Nothing Nothing)] ++
52+ map (\(n, fc) -> (fc, AnnBoundName n False)) ns
53+
54+directiveAction (DErrorHandlers fn nfc arg afc ns) =
55+ do fn' <- disambiguate fn
56+ ns' <- mapM (\(n, fc) -> do n' <- disambiguate n
57+ return (n', fc)) ns
58+ addFunctionErrorHandlers fn' arg (map fst ns')
59+ mapM_ (addIBC .
60+ IBCFunctionErrorHandler fn' arg . fst) ns'
61+ sendHighlighting $
62+ [(nfc, AnnName fn' Nothing Nothing Nothing),
63+ (afc, AnnBoundName arg False)] ++
64+ map (\(n, fc) -> (fc, AnnName n Nothing Nothing Nothing)) ns'
5565
5666directiveAction (DLanguage ext) = addLangExt ext
5767
src/Idris/Parser.hs+7−7
@@ -1146,14 +1146,14 @@ directive syn = do try (lchar '%' *> reserved "lib")
11461146 libs <- sepBy1 (fmap fst stringLiteral) (lchar ',')
11471147 return [PDirective (DDynamicLibs libs)]
11481148 <|> do try (lchar '%' *> reserved "name")
1149− ty <- fst <$> fnName
1150− ns <- sepBy1 (fst <$> name) (lchar ',')
1151− return [PDirective (DNameHint ty ns)]
1149+ (ty, tyFC) <- fnName
1150+ ns <- sepBy1 name (lchar ',')
1151+ return [PDirective (DNameHint ty tyFC ns)]
11521152 <|> do try (lchar '%' *> reserved "error_handlers")
1153− fn <- fst <$> fnName
1154− arg <- fst <$> fnName
1155− ns <- sepBy1 (fst <$> name) (lchar ',')
1156− return [PDirective (DErrorHandlers fn arg ns) ]
1153+ (fn, nfc) <- fnName
1154+ (arg, afc) <- fnName
1155+ ns <- sepBy1 name (lchar ',')
1156+ return [PDirective (DErrorHandlers fn nfc arg afc ns) ]
11571157 <|> do try (lchar '%' *> reserved "language"); ext <- pLangExt;
11581158 return [PDirective (DLanguage ext)]
11591159 <|> do fc <- getFC