Skip to content

Commit

Permalink
Tweak and pass a test
Browse files Browse the repository at this point in the history
  • Loading branch information
azdavis committed Dec 7, 2023
1 parent 3bee678 commit 47a7897
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions crates/sml-statics/src/top_dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ fn get_str_exp(
to_add = sig.env.clone();
realize::get_env(&mut st.syms_tys.tys, &subst, &mut to_add);
}
enrich_defs(&str_exp_env, &mut to_add);
if let Some(ov) = ov {
let ty_info = to_add.ty_env.get(ov.as_str()).expect("no overloaded ty");
match st.syms_tys.tys.data(ty_info.ty_scheme.ty) {
Expand Down Expand Up @@ -328,6 +329,29 @@ fn get_str_exp(
}
}

/// helps get the defs (and therefore e.g. docs) from a structure that ascribes to a signature, not
/// just the docs from the signature
fn enrich_defs(general: &Env, specific: &mut Env) {
if specific.def.is_none() {
specific.def = general.def;
}
for (name, specific) in specific.str_env.iter_mut() {
let Some(general) = general.str_env.get(name) else { continue };
enrich_defs(general, specific);
}
for (name, specific) in specific.ty_env.iter_mut() {
let Some(general) = general.ty_env.get(name) else { continue };
for (name, specific) in specific.val_env.iter_mut() {
let Some(general) = general.val_env.get(name) else { continue };
specific.defs.extend(general.defs.iter().copied());
}
}
for (name, specific) in specific.val_env.iter_mut() {
let Some(general) = general.val_env.get(name) else { continue };
specific.defs.extend(general.defs.iter().copied());
}
}

fn get_sig_exp(
st: &mut St<'_>,
bs: &Bs,
Expand Down
7 changes: 5 additions & 2 deletions crates/tests/src/hover/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ structure L = List

#[test]
fn override_sig_docs_with_structure() {
fail(
check(
r"
signature EXAMPLE = sig
(*!
Expand All @@ -155,12 +155,15 @@ structure Example: EXAMPLE = struct
(** ^^^ hover: structure foo docs *)
val bar = ()
(** ^^^ hover: signature bar docs *)
(** ^^^ hover: unit *)
end
val foo = Example.foo
(** ^^^^^^^^^^^ hover: structure foo docs *)
val foo = Example.foo
(** ^^^^^^^^^^^ hover: signature foo docs *)
val bar = Example.bar
(** ^^^^^^^^^^^ hover: signature bar docs *)
",
Expand Down

0 comments on commit 47a7897

Please sign in to comment.