From bf2d5fd3bc78b64ae8bd2ad49f6107f1a6939683 Mon Sep 17 00:00:00 2001 From: Fredrik Frantzen Date: Wed, 8 Jan 2025 09:32:14 +0100 Subject: [PATCH] stdlib: cache code:get_docs calls when completing types in the shell --- lib/stdlib/src/edlin_type_suggestion.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/stdlib/src/edlin_type_suggestion.erl b/lib/stdlib/src/edlin_type_suggestion.erl index 1dcbb53b0a5b..aa5ca05da1d8 100644 --- a/lib/stdlib/src/edlin_type_suggestion.erl +++ b/lib/stdlib/src/edlin_type_suggestion.erl @@ -220,10 +220,19 @@ simplified_type(file, name_all, 0) -> {type, erlang, string, []}; simplified_type(file, name, 0) -> {type, erlang, string, []}; simplified_type(_Module, _TypeName, _Arity) -> none. +code_get_doc_cache(Mod) -> + case get(Mod) of + undefined -> + Docs = code:get_doc(Mod, #{sources => [debug_info]}), + put(Mod, Docs), + Docs; + Docs -> Docs + end. + lookup_type(Mod, Type, Arity, FT) -> case simplified_type(Mod, Type, Arity) of none -> - case code:get_doc(Mod, #{sources => [debug_info]}) of + case code_get_doc_cache(Mod) of {ok, #docs_v1{ docs = Docs } } -> FnFunctions = lists:filter(fun({{type, T, A},_Anno,_Sig,_Doc,_Meta}) ->