Skip to content

Commit 1abc6b7

Browse files
committed
rename struct fields
1 parent 37c3402 commit 1abc6b7

File tree

6 files changed

+170
-201
lines changed

6 files changed

+170
-201
lines changed

lib/elixir_sense/core/binding.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ defmodule ElixirSense.Core.Binding do
1010

1111
# TODO refactor to use env
1212
defstruct structs: %{},
13-
variables: [],
13+
vars: [],
1414
attributes: [],
15-
current_module: nil,
15+
module: nil,
1616
function: nil,
1717
functions: [],
1818
macros: [],
1919
specs: %{},
2020
types: %{},
21-
mods_funs: %{}
21+
mods_funs_to_positions: %{}
2222

2323
def from_env(%State.Env{} = env, %ElixirSense.Core.Metadata{} = metadata) do
2424
%Binding{
25-
variables: env.vars,
25+
vars: env.vars,
2626
attributes: env.attributes,
2727
structs: metadata.structs,
2828
functions: env.functions,
2929
macros: env.macros,
3030
specs: metadata.specs,
31-
current_module: env.module,
31+
module: env.module,
3232
function: env.function,
3333
types: metadata.types,
34-
mods_funs: metadata.mods_funs_to_positions
34+
mods_funs_to_positions: metadata.mods_funs_to_positions
3535
}
3636
end
3737

@@ -86,7 +86,7 @@ defmodule ElixirSense.Core.Binding do
8686
expand(env, combined, stack)
8787
end
8888

89-
def do_expand(%Binding{variables: variables} = env, {:variable, variable, version}, stack) do
89+
def do_expand(%Binding{vars: variables} = env, {:variable, variable, version}, stack) do
9090
sorted_variables = Enum.sort_by(variables, &{&1.name, -&1.version})
9191

9292
type =
@@ -299,7 +299,7 @@ defmodule ElixirSense.Core.Binding do
299299

300300
# local call
301301
def do_expand(
302-
%Binding{functions: functions, macros: macros, current_module: current_module} = env,
302+
%Binding{functions: functions, macros: macros} = env,
303303
{:local_call, function, arguments},
304304
stack
305305
) do
@@ -311,9 +311,9 @@ defmodule ElixirSense.Core.Binding do
311311
|> Introspection.combine_imports()
312312

313313
candidate_targets =
314-
if current_module && env.function do
314+
if env.module && env.function do
315315
# locals are available only in defs
316-
[current_module]
316+
[env.module]
317317
else
318318
[]
319319
end ++ combined_imports ++ [Kernel.SpecialForms]
@@ -329,7 +329,7 @@ defmodule ElixirSense.Core.Binding do
329329

330330
candidate ->
331331
# include private from current module
332-
include_private = candidate == current_module
332+
include_private = candidate == env.module
333333
expand_call(env, {:atom, candidate}, function, arguments, include_private, stack)
334334
end)
335335
|> drop_no_spec
@@ -1324,15 +1324,15 @@ defmodule ElixirSense.Core.Binding do
13241324
end
13251325

13261326
defp expand_call_from_metadata(
1327-
%Binding{specs: specs, mods_funs: mods_funs} = env,
1327+
%Binding{specs: specs, mods_funs_to_positions: mods_funs_to_positions} = env,
13281328
mod,
13291329
fun,
13301330
arity,
13311331
include_private,
13321332
stack
13331333
) do
13341334
arity =
1335-
Enum.find_value(mods_funs, nil, fn
1335+
Enum.find_value(mods_funs_to_positions, nil, fn
13361336
{{^mod, ^fun, _}, %State.ModFunInfo{type: fun_type} = info}
13371337
when (include_private and fun_type != :def) or
13381338
fun_type in [:def, :defmacro, :defguard, :defdelegate] ->

lib/elixir_sense/core/source.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ defmodule ElixirSense.Core.Source do
572572
end
573573

574574
def get_mod_fun([{:__MODULE__, _, nil}, fun], binding_env) do
575-
if binding_env.current_module != nil do
576-
{{binding_env.current_module, false}, fun}
575+
if binding_env.module != nil do
576+
{{binding_env.module, false}, fun}
577577
end
578578
end
579579

@@ -607,9 +607,9 @@ defmodule ElixirSense.Core.Source do
607607
end
608608

609609
def get_mod([{:__MODULE__, _, nil} | rest], binding_env) do
610-
if binding_env.current_module != nil do
610+
if binding_env.module != nil do
611611
mod =
612-
binding_env.current_module
612+
binding_env.module
613613
|> Module.split()
614614
|> Kernel.++(rest)
615615
|> Module.concat()

lib/elixir_sense/providers/completion/reducers/record.ex

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,17 @@ defmodule ElixirSense.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+
binding_env = ElixirSense.Core.Binding.from_env(env, metadata)
7459

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

lib/elixir_sense/providers/completion/reducers/struct.ex

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,16 @@ defmodule ElixirSense.Providers.Completion.Reducers.Struct do
4444
end
4545
end
4646

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

7458
case Source.which_struct(text_before, module) do
7559
{type, fields_so_far, elixir_prefix, var} ->
@@ -84,13 +68,13 @@ defmodule ElixirSense.Providers.Completion.Reducers.Struct do
8468
type
8569
end
8670

87-
type = Binding.expand(env, {:struct, [], type, var})
71+
type = Binding.expand(binding_env, {:struct, [], type, var})
8872

8973
result = get_fields(buffer_metadata, type, hint, fields_so_far)
9074
{result, if(fields_so_far == [], do: :maybe_struct_update)}
9175

9276
{:map, fields_so_far, var} ->
93-
var = Binding.expand(env, var)
77+
var = Binding.expand(binding_env, var)
9478

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

0 commit comments

Comments
 (0)