From 9e2b026fea11ae89a53d4fc1c674ef8e43b2c2ce Mon Sep 17 00:00:00 2001 From: FrigoEU Date: Thu, 1 Aug 2019 09:57:46 +0200 Subject: Added file check to typeOf and always add Top and Basis to env in typeOf --- src/compiler.sml | 22 ++++++++++++---------- src/mod_db.sml | 7 ++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/compiler.sml b/src/compiler.sml index 46a035ee..51cf20e1 100644 --- a/src/compiler.sml +++ b/src/compiler.sml @@ -1781,11 +1781,13 @@ fun moduleOf fname = end end -fun isPosIn row col span = +fun isPosIn file row col span = let val start = #first span val end_ = #last span in + (String.isSuffix file (#file span)) + andalso ((#line start < row) orelse (#line start = row) andalso (#char start <= col)) andalso @@ -1827,10 +1829,10 @@ fun getTypeAt file row col = NONE => Print.PD.string ("ERROR: No module found: " ^ moduleOf file) | SOME (decl, deps) => let - (* TODO Top is not always found as a dep *) val () = ElabUtilPos.mliftConInCon := ElabEnv.mliftConInCon (* Adding dependencies to environment *) - val env = List.foldl (fn (d, e) => ElabEnv.declBinds e d) + val env = List.foldl (fn (d, e) => + ElabEnv.declBinds e d) ElabEnv.empty deps (* Adding previous declarations to environment *) @@ -1850,31 +1852,31 @@ fun getTypeAt file row col = val (atPosition, env) = ElabUtilPos.Decl.foldB { kind = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Kind (k, span), env) else acc , con = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Con (k, span), env) else acc, exp = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Exp (k, span), env) else acc, sgn_item = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Sgn_item (k, span), env) else acc, sgn = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Sgn (k, span), env) else acc, str = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Str (k, span), env) else acc, decl = fn (env, (k, span), acc) => - if isPosIn row col span andalso isSmallerThan span (getSpan acc) + if isPosIn file row col span andalso isSmallerThan span (getSpan acc) then (Decl (k, span), env) else acc, bind = fn (env, binder) => diff --git a/src/mod_db.sml b/src/mod_db.sml index fdf6d5ab..57d85195 100644 --- a/src/mod_db.sml +++ b/src/mod_db.sml @@ -214,7 +214,12 @@ fun lookupForTooling name = SOME (#Decl m, List.map (fn a => #Decl a) (List.mapPartial (fn d => SM.find (!byName, d)) - (SS.listItems (#Deps m)))) + (* Clumsy way of adding Basis and Top without adding doubles *) + (["Basis", "Top"] + @ + (List.filter + (fn x => x <> "Basis" andalso x <> "Top") + (SS.listItems (#Deps m)))))) val byNameBackup = ref (!byName) val byIdBackup = ref (!byId) -- cgit v1.2.3