-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache module_info of interpreted modules
call to module_info may deadlock when stopped on a breakpoint Fixes #940
- Loading branch information
1 parent
b2792a0
commit 0481fb8
Showing
5 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule ElixirLS.Debugger.ModuleInfoCache do | ||
@moduledoc """ | ||
Caches module_info of interpreted modules. There are cases when module_info call | ||
may deadlock (https://github.com/elixir-lsp/elixir-ls/issues/940) | ||
""" | ||
|
||
use Agent | ||
|
||
def start_link(args) do | ||
Agent.start_link(fn -> args end, name: __MODULE__) | ||
end | ||
|
||
def get(module) do | ||
Agent.get(__MODULE__, & &1[module]) | ||
end | ||
|
||
def store(module) do | ||
Agent.update(__MODULE__, fn map -> | ||
if Map.has_key?(map, module) do | ||
map | ||
else | ||
Map.put(map, module, module.module_info()) | ||
end | ||
end) | ||
end | ||
|
||
def clear() do | ||
Agent.update(__MODULE__, fn _map -> %{} end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters