0 | module Idris.IDEMode.SyntaxHighlight
2 | import Core.Directory
7 | import Idris.IDEMode.Commands
9 | import Libraries.Data.PosMap
15 | printOutput : {auto c : Ref Ctxt Defs} ->
16 | {auto o : Ref ROpts REPLOpts} ->
17 | SourceHighlight -> Core ()
18 | printOutput highlight
19 | = do opts <- get ROpts
20 | case idemode opts of
23 | send f (Intermediate (HighlightSource [highlight]) i)
25 | outputHighlight : {auto c : Ref Ctxt Defs} ->
26 | {auto opts : Ref ROpts REPLOpts} ->
27 | Highlight -> Core ()
28 | outputHighlight hl =
29 | printOutput $
Full hl
32 | {auto c : Ref Ctxt Defs} ->
33 | {auto opts : Ref ROpts REPLOpts} ->
34 | (FileName, NonEmptyFC, Decoration) -> Core ()
35 | lwOutputHighlight (fname, nfc, decor) =
36 | printOutput $
Lw $
MkLwHighlight {location = cast (fname, nfc), decor}
38 | outputNameSyntax : {auto c : Ref Ctxt Defs} ->
39 | {auto s : Ref Syn SyntaxInfo} ->
40 | {auto opts : Ref ROpts REPLOpts} ->
41 | (FileName, NonEmptyFC, Decoration, Name) -> Core ()
42 | outputNameSyntax (fname, nfc, decor, nm) = do
44 | log "ide-mode.highlight" 20 $
"highlighting at " ++ show nfc
46 | ++ "\nAs: " ++ show decor
48 | let (mns, name) = displayName nm
49 | outputHighlight $
MkHighlight
50 | { location = cast (fname, nfc)
52 | , isImplicit = False
57 | , ns = maybe "" show mns
61 | outputSyntaxHighlighting : {auto c : Ref Ctxt Defs} ->
62 | {auto m : Ref MD Metadata} ->
63 | {auto s : Ref Syn SyntaxInfo} ->
64 | {auto opts : Ref ROpts REPLOpts} ->
68 | outputSyntaxHighlighting fname loadResult = do
70 | when (opts.synHighlightOn) $
do
72 | modIdent <- ctxtPathToNS fname
74 | let allNames = filter ((PhysicalIdrSrc modIdent ==) . fst . fst)
75 | $
toList meta.nameLocMap
79 | decors <- allSemanticHighlighting meta
81 | traverse_ {b = Unit}
82 | (\(nfc, decor, mn) =>
84 | Nothing => lwOutputHighlight (fname, nfc, decor)
85 | Just n => outputNameSyntax (fname, nfc, decor, n))