From 719dac766c539aa72615ce2a4f932c66ba041821 Mon Sep 17 00:00:00 2001 From: favonia Date: Sun, 15 Oct 2023 09:50:23 -0500 Subject: [PATCH] feat(Scope): add get_visible (#119) --- src/Scope.ml | 3 +++ src/ScopeSigs.ml | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/Scope.ml b/src/Scope.ml index af6ad001..cc5ca19b 100644 --- a/src/Scope.ml +++ b/src/Scope.ml @@ -80,6 +80,9 @@ struct let ns = Mod.modify ?context:context_modifier ~prefix:Emp modifier ns in { s with visible = Trie.union_subtree ~prefix:Emp (Mod.Perform.shadow context_visible) s.visible (path, ns) } + let get_visible () = + M.exclusively @@ fun () -> (S.get()).visible + let get_export () = M.exclusively @@ fun () -> (S.get()).export diff --git a/src/ScopeSigs.ml b/src/ScopeSigs.ml index bb605dd4..fd7b860c 100644 --- a/src/ScopeSigs.ml +++ b/src/ScopeSigs.ml @@ -131,6 +131,13 @@ sig @param context_modifier The context of modifier effects when applying the modifier [m]. @param context_export The context of modifier effects when merging the subtree into the export namespace. *) + val get_visible : unit -> (data, tag) Trie.t + (** [get_visible ()] returns the visible namespace of the current scope. + + This is useful for obtaining all visible names for auto-completion. It can also be used for checking whether a shadowed definition is still visible under another name. (However, scanning the entire visible namespace is expensive and should probably be avoided.) + + @since 5.2.0 *) + val get_export : unit -> (data, tag) Trie.t (** [get_export ()] returns the export namespace of the current scope.