diff --git a/src/Commands.newt b/src/Commands.newt index 85d48de..006edf2 100644 --- a/src/Commands.newt +++ b/src/Commands.newt @@ -16,6 +16,7 @@ import Data.SortedMap import Lib.Parser import Lib.Syntax import Lib.Parser.Impl +import Lib.Error -- For now we cheat and assume capitalized directories are a module component decomposeName : String → String × String @@ -31,8 +32,12 @@ decomposeName fn = switchModule : FileSource → String → M (Maybe ModContext) switchModule repo modns = do + -- TODO processing on hover is expensive, but info is not always there + -- I suspect this picks up the case where a file has been invalidated by a change to + -- another file and we switch editors. Handle that (enqueue a check) and switch this back. top <- getTop - let (Just mod) = lookupMap' modns top.modules | Nothing => pure Nothing + mod <- processModule emptyFC repo Nil modns + -- let (Just mod) = lookupMap' modns top.modules | Nothing => pure Nothing modifyTop [ currentMod := mod; ops := mod.modOps ] pure $ Just mod diff --git a/src/LSP.newt b/src/LSP.newt index 5b46134..9520db8 100644 --- a/src/LSP.newt +++ b/src/LSP.newt @@ -15,6 +15,7 @@ import Node import Commands import Lib.ProcessDecl import Lib.Prettier +import Lib.Error pfunc js_castArray : Array JSObject → JSObject := `x => x` pfunc js_castInt : Int → JSObject := `x => x` diff --git a/src/Lib/Common.newt b/src/Lib/Common.newt index 6940598..d5304e2 100644 --- a/src/Lib/Common.newt +++ b/src/Lib/Common.newt @@ -113,6 +113,8 @@ record FC where file : String bnds : Bounds +instance Show FC where + show (MkFC file (MkBounds l c el ec)) = "\{file}:\{show $ l + 1}:\{show $ c + 1}--\{show $ el + 1}:\{show $ ec + 1}" instance Add FC where MkFC fn a + MkFC _ b = MkFC fn (a + b) @@ -158,40 +160,6 @@ instance Show QName where instance Ord QName where compare (QN ns nm) (QN ns' nm') = if ns == ns' then compare nm nm' else compare ns ns' --- I'll want to get Context / Val in some of these --- and a pretty printer in the monad -data Error - = E FC String - | ENotFound FC String - | Postpone FC QName String - -instance Show FC where - show (MkFC file (MkBounds l c el ec)) = "\{file}:\{show $ l + 1}:\{show $ c + 1}--\{show $ el + 1}:\{show $ ec + 1}" - -instance HasFC Error where - getFC (E x str) = x - getFC (ENotFound x _) = x - getFC (Postpone x k str) = x - -errorMsg : Error -> String -errorMsg (E x str) = str -errorMsg (ENotFound x nm) = "\{nm} not in scope" -errorMsg (Postpone x k str) = str - -showError : (src : String) -> Error -> String -showError src err = - let fc = getFC err - in "ERROR at \{show $ getFC err}: \{errorMsg err}\n" ++ go fc 0 (lines src) - where - go : FC → Int → List String → String - go fc l Nil = "" - go fc l (x :: xs) = - if l == fcLine fc then - let width = fc.bnds.endCol - fc.bnds.startCol in - " \{x}\n \{replicate (cast $ fcCol fc) ' '}\{replicate (cast width) '^'}\n" - else if fcLine fc - 3 < l then " " ++ x ++ "\n" ++ go fc (l + 1) xs - else go fc (l + 1) xs - data Fixity = InfixL | InfixR | Infix diff --git a/src/Lib/Elab.newt b/src/Lib/Elab.newt index 8e689d9..1327991 100644 --- a/src/Lib/Elab.newt +++ b/src/Lib/Elab.newt @@ -13,6 +13,7 @@ import Lib.Util import Lib.TopContext import Lib.Syntax import Lib.Types +import Lib.Error vprint : Context -> Val -> M String vprint ctx v = do diff --git a/src/Lib/Error.newt b/src/Lib/Error.newt new file mode 100644 index 0000000..b8c91a2 --- /dev/null +++ b/src/Lib/Error.newt @@ -0,0 +1,37 @@ +module Lib.Error + +import Prelude +import Lib.Common + +-- I'll want to get Context / Val in some of these +-- and a pretty printer in the monad +data Error + = E FC String + | ENotFound FC String + | Postpone FC QName String + + +instance HasFC Error where + getFC (E x str) = x + getFC (ENotFound x _) = x + getFC (Postpone x k str) = x + +errorMsg : Error -> String +errorMsg (E x str) = str +errorMsg (ENotFound x nm) = "\{nm} not in scope" +errorMsg (Postpone x k str) = str + +showError : (src : String) -> Error -> String +showError src err = + let fc = getFC err + in "ERROR at \{show $ getFC err}: \{errorMsg err}\n" ++ go fc 0 (lines src) + where + go : FC → Int → List String → String + go fc l Nil = "" + go fc l (x :: xs) = + if l == fcLine fc then + let width = fc.bnds.endCol - fc.bnds.startCol in + " \{x}\n \{replicate (cast $ fcCol fc) ' '}\{replicate (cast width) '^'}\n" + else if fcLine fc - 3 < l then " " ++ x ++ "\n" ++ go fc (l + 1) xs + else go fc (l + 1) xs + diff --git a/src/Lib/Parser/Impl.newt b/src/Lib/Parser/Impl.newt index a58fbd9..0ebb516 100644 --- a/src/Lib/Parser/Impl.newt +++ b/src/Lib/Parser/Impl.newt @@ -7,7 +7,7 @@ import Data.String import Data.Int import Data.List1 import Data.SortedMap - +import Lib.Error TokenList : U TokenList = List BTok diff --git a/src/Lib/ProcessDecl.newt b/src/Lib/ProcessDecl.newt index 6bb8605..179efc6 100644 --- a/src/Lib/ProcessDecl.newt +++ b/src/Lib/ProcessDecl.newt @@ -6,6 +6,7 @@ import Data.String import Lib.Common import Lib.Elab +import Lib.Error import Lib.Parser import Lib.Syntax import Data.SortedMap diff --git a/src/Lib/ProcessModule.newt b/src/Lib/ProcessModule.newt index 9cb5463..4d0ecb9 100644 --- a/src/Lib/ProcessModule.newt +++ b/src/Lib/ProcessModule.newt @@ -4,6 +4,7 @@ import Prelude import Lib.Types import Lib.Common import Lib.Syntax +import Lib.Error import Lib.ProcessDecl import Lib.TopContext import Lib.Tokenizer diff --git a/src/Lib/Tokenizer.newt b/src/Lib/Tokenizer.newt index 4c659f5..7109be9 100644 --- a/src/Lib/Tokenizer.newt +++ b/src/Lib/Tokenizer.newt @@ -12,6 +12,7 @@ import Lib.Token import Lib.Common import Data.String import Data.SnocList +import Lib.Error standalone : List Char standalone = unpack "()\\{}[],.@;" diff --git a/src/Lib/TopContext.newt b/src/Lib/TopContext.newt index cb201f9..d48201e 100644 --- a/src/Lib/TopContext.newt +++ b/src/Lib/TopContext.newt @@ -6,6 +6,7 @@ import Data.String import Prelude import Lib.Common import Lib.Types +import Lib.Error -- TODO move the def in here (along with M) or merge this into types -- The Monad can be its own file if we pull all of the monad update functions there. diff --git a/src/Lib/Types.newt b/src/Lib/Types.newt index dd427a4..0818801 100644 --- a/src/Lib/Types.newt +++ b/src/Lib/Types.newt @@ -3,6 +3,7 @@ module Lib.Types import Prelude import Lib.Common import Lib.Prettier +import Lib.Error import Data.IORef import Data.SnocList diff --git a/src/Main.newt b/src/Main.newt index a7ecc02..d8a1a6c 100644 --- a/src/Main.newt +++ b/src/Main.newt @@ -19,6 +19,7 @@ import Lib.Syntax import Lib.ReplParser import Node import Revision +import Lib.Error dirFileSource : String → FileSource dirFileSource base = MkFileSource base $ \fc fn => do