Skip to content

Commit bcc9d83

Browse files
committed
use function
1 parent 1f54ac3 commit bcc9d83

File tree

2 files changed

+24
-54
lines changed

2 files changed

+24
-54
lines changed

apps/language_server/lib/language_server/providers/completion/reducers/record.ex

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,18 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Record do
4545
end
4646
end
4747

48-
defp find_record_fields(hint, text_before, env, metadata, cursor_position) do
49-
%State.Env{
50-
module: module,
51-
vars: vars,
52-
attributes: attributes
53-
} = env
54-
55-
%Metadata{
56-
structs: structs,
57-
records: records,
58-
mods_funs_to_positions: mods_funs,
59-
types: metadata_types,
60-
specs: specs
61-
} = metadata
62-
63-
binding_env = %ElixirSense.Core.Binding{
64-
attributes: attributes,
65-
variables: vars,
66-
structs: structs,
67-
functions: env.functions,
68-
macros: env.macros,
69-
current_module: module,
70-
specs: specs,
71-
types: metadata_types,
72-
mods_funs: mods_funs
73-
}
48+
defp find_record_fields(
49+
hint,
50+
text_before,
51+
%State.Env{} = env,
52+
%Metadata{
53+
records: records,
54+
types: metadata_types
55+
} = metadata,
56+
cursor_position
57+
) do
58+
59+
binding_env = ElixirSense.Core.Binding.from_env(env, metadata)
7460

7561
# check if we are inside local or remote call arguments and parameter is 0, 1 or 2
7662
# record fields can specified on 0, 1 and 2 position in the argument list

apps/language_server/lib/language_server/providers/completion/reducers/struct.ex

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,16 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Struct do
5050
end
5151
end
5252

53-
defp find_struct_fields(hint, text_before, env, buffer_metadata) do
54-
%State.Env{
55-
module: module,
56-
vars: vars,
57-
attributes: attributes,
58-
aliases: aliases
59-
} = env
60-
61-
%Metadata{
62-
structs: structs,
63-
mods_funs_to_positions: mods_funs,
64-
types: metadata_types,
65-
specs: specs
66-
} = buffer_metadata
67-
68-
env = %ElixirSense.Core.Binding{
69-
attributes: attributes,
70-
variables: vars,
71-
structs: structs,
72-
functions: env.functions,
73-
macros: env.macros,
74-
current_module: module,
75-
specs: specs,
76-
types: metadata_types,
77-
mods_funs: mods_funs
78-
}
53+
defp find_struct_fields(
54+
hint,
55+
text_before,
56+
%State.Env{
57+
module: module,
58+
aliases: aliases
59+
} = env,
60+
%Metadata{} = buffer_metadata
61+
) do
62+
binding_env = ElixirSense.Core.Binding.from_env(env, buffer_metadata)
7963

8064
case Source.which_struct(text_before, module) do
8165
{type, fields_so_far, elixir_prefix, var} ->
@@ -90,13 +74,13 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.Reducers.Struct do
9074
type
9175
end
9276

93-
type = Binding.expand(env, {:struct, [], type, var})
77+
type = Binding.expand(binding_env, {:struct, [], type, var})
9478

9579
result = get_fields(buffer_metadata, type, hint, fields_so_far)
9680
{result, if(fields_so_far == [], do: :maybe_struct_update)}
9781

9882
{:map, fields_so_far, var} ->
99-
var = Binding.expand(env, var)
83+
var = Binding.expand(binding_env, var)
10084

10185
result = get_fields(buffer_metadata, var, hint, fields_so_far)
10286
{result, if(fields_so_far == [], do: :maybe_struct_update)}

0 commit comments

Comments
 (0)