Skip to content

Commit f8711f2

Browse files
josevalimJosé Valim
authored andcommitted
Merge pull request #2932 from tonini/add-modules-load-path-to-autocomplete
Fetch module names from load path for autocomplete Signed-off-by: José Valim <[email protected]>
1 parent 0251f56 commit f8711f2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/iex/lib/iex/autocomplete.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,25 @@ defmodule IEx.Autocomplete do
188188
end
189189

190190
defp modules_as_lists(true) do
191-
["Elixir.Elixir"] ++ modules_as_lists(false)
191+
modules = ["Elixir.Elixir"] ++ modules_as_lists(false)
192+
modules = if :code.get_mode() === :interactive do
193+
modules ++ loaded_applications_as_lists
194+
end
195+
Enum.uniq(modules)
192196
end
193197

194198
defp modules_as_lists(false) do
195199
Enum.map(:code.all_loaded, fn({m, _}) -> Atom.to_string(m) end)
196200
end
197201

202+
defp loaded_applications_as_lists do
203+
for {app, _, _} <- :application.loaded_applications,
204+
{_, modules} = :application.get_key(app, :modules),
205+
module <- modules do
206+
Atom.to_string(module)
207+
end
208+
end
209+
198210
## Helpers
199211

200212
defp module_funs(mod, hint) do

lib/iex/test/iex/autocomplete_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ defmodule IEx.AutocompleteTest do
3434
assert expand('Enumerable') == {:yes, '.', []}
3535
end
3636

37+
test :elixir_auto_completion_on_modules_from_load_path do
38+
assert expand('Str') == {:yes, [], ['String', 'StringIO', 'Stream']}
39+
assert expand('Ma') == {:yes, '', ['Macro', 'Map', 'MatchError']}
40+
assert expand('Dic') == {:yes, 't.', []}
41+
assert expand('Ex') == {:yes, [], ['Exception', 'ExUnit']}
42+
end
43+
3744
test :elixir_no_completion do
3845
assert expand('.') == {:no, '', []}
3946
assert expand('Xyz') == {:no, '', []}

0 commit comments

Comments
 (0)