@@ -255,7 +255,7 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
255255 ) do
256256 filter = struct_module_filter ( only_structs , env , metadata )
257257
258- case expand_dot_path ( path , env , metadata ) do
258+ case expand_dot_path ( path , env , metadata , cursor_position ) do
259259 { :ok , { :atom , mod } } when hint == "" ->
260260 expand_aliases (
261261 mod ,
@@ -284,23 +284,38 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
284284 end
285285
286286 # elixir >= 1.14
287- defp expand_dot_path ( { :var , ~c" __MODULE__" } , % State.Env { } = env , % Metadata { } = _metadata ) do
287+ defp expand_dot_path (
288+ { :var , ~c" __MODULE__" } ,
289+ % State.Env { } = env ,
290+ % Metadata { } = _metadata ,
291+ _cursor_position
292+ ) do
288293 if env . module != nil and Introspection . elixir_module? ( env . module ) do
289294 { :ok , { :atom , env . module } }
290295 else
291296 :error
292297 end
293298 end
294299
295- defp expand_dot_path ( { :var , var } , % State.Env { } = env , % Metadata { } = metadata ) do
296- value_from_binding ( { :variable , List . to_atom ( var ) , :any } , env , metadata )
300+ defp expand_dot_path ( { :var , var } , % State.Env { } = env , % Metadata { } = metadata , cursor_position ) do
301+ value_from_binding ( { :variable , List . to_atom ( var ) , :any } , env , metadata , cursor_position )
297302 end
298303
299- defp expand_dot_path ( { :module_attribute , attribute } , % State.Env { } = env , % Metadata { } = metadata ) do
300- value_from_binding ( { :attribute , List . to_atom ( attribute ) } , env , metadata )
304+ defp expand_dot_path (
305+ { :module_attribute , attribute } ,
306+ % State.Env { } = env ,
307+ % Metadata { } = metadata ,
308+ cursor_position
309+ ) do
310+ value_from_binding ( { :attribute , List . to_atom ( attribute ) } , env , metadata , cursor_position )
301311 end
302312
303- defp expand_dot_path ( { :alias , hint } , % State.Env { } = env , % Metadata { } = metadata ) do
313+ defp expand_dot_path (
314+ { :alias , hint } ,
315+ % State.Env { } = env ,
316+ % Metadata { } = metadata ,
317+ _cursor_position
318+ ) do
304319 alias = hint |> List . to_string ( ) |> String . split ( "." ) |> value_from_alias ( env , metadata )
305320
306321 case alias do
@@ -313,7 +328,8 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
313328 defp expand_dot_path (
314329 { :alias , { :local_or_var , var } , hint } ,
315330 % State.Env { } = env ,
316- % Metadata { } = metadata
331+ % Metadata { } = metadata ,
332+ _cursor_position
317333 ) do
318334 case var do
319335 ~c" __MODULE__" ->
@@ -333,9 +349,10 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
333349 defp expand_dot_path (
334350 { :alias , { :module_attribute , attribute } , hint } ,
335351 % State.Env { } = env ,
336- % Metadata { } = metadata
352+ % Metadata { } = metadata ,
353+ cursor_position
337354 ) do
338- case value_from_binding ( { :attribute , List . to_atom ( attribute ) } , env , metadata ) do
355+ case value_from_binding ( { :attribute , List . to_atom ( attribute ) } , env , metadata , cursor_position ) do
339356 { :ok , { :atom , atom } } ->
340357 if Introspection . elixir_module? ( atom ) do
341358 alias_suffix = hint |> List . to_string ( ) |> String . split ( "." )
@@ -354,26 +371,46 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
354371 end
355372 end
356373
357- defp expand_dot_path ( { :alias , _ , _hint } , % State.Env { } = _env , % Metadata { } = _metadata ) do
374+ defp expand_dot_path (
375+ { :alias , _ , _hint } ,
376+ % State.Env { } = _env ,
377+ % Metadata { } = _metadata ,
378+ _cursor_position
379+ ) do
358380 :error
359381 end
360382
361- defp expand_dot_path ( { :unquoted_atom , var } , % State.Env { } = _env , % Metadata { } = _metadata ) do
383+ defp expand_dot_path (
384+ { :unquoted_atom , var } ,
385+ % State.Env { } = _env ,
386+ % Metadata { } = _metadata ,
387+ _cursor_position
388+ ) do
362389 { :ok , { :atom , List . to_atom ( var ) } }
363390 end
364391
365- defp expand_dot_path ( { :dot , parent , call } , % State.Env { } = env , % Metadata { } = metadata ) do
366- case expand_dot_path ( parent , env , metadata ) do
392+ defp expand_dot_path (
393+ { :dot , parent , call } ,
394+ % State.Env { } = env ,
395+ % Metadata { } = metadata ,
396+ cursor_position
397+ ) do
398+ case expand_dot_path ( parent , env , metadata , cursor_position ) do
367399 { :ok , expanded } ->
368- value_from_binding ( { :call , expanded , List . to_atom ( call ) , [ ] } , env , metadata )
400+ value_from_binding (
401+ { :call , expanded , List . to_atom ( call ) , [ ] } ,
402+ env ,
403+ metadata ,
404+ cursor_position
405+ )
369406
370407 :error ->
371408 :error
372409 end
373410 end
374411
375412 # elixir >= 1.15
376- defp expand_dot_path ( :expr , % State.Env { } = _env , % Metadata { } = _metadata ) do
413+ defp expand_dot_path ( :expr , % State.Env { } = _env , % Metadata { } = _metadata , _cursor_position ) do
377414 # TODO expand expression
378415 :error
379416 end
@@ -672,7 +709,7 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
672709 cursor_position ,
673710 only_structs
674711 ) do
675- case value_from_binding ( { :attribute , List . to_atom ( attribute ) } , env , metadata ) do
712+ case value_from_binding ( { :attribute , List . to_atom ( attribute ) } , env , metadata , cursor_position ) do
676713 { :ok , { :atom , atom } } ->
677714 if Introspection . elixir_module? ( atom ) do
678715 expand_aliases ( "#{ atom } .#{ hint } " , env , metadata , cursor_position , only_structs , [ ] )
@@ -1503,9 +1540,14 @@ defmodule ElixirSense.Providers.Completion.CompletionEngine do
15031540 end
15041541 end
15051542
1506- defp value_from_binding ( binding_ast , % State.Env { } = env , % Metadata { } = metadata ) do
1543+ defp value_from_binding (
1544+ binding_ast ,
1545+ % State.Env { } = env ,
1546+ % Metadata { } = metadata ,
1547+ cursor_position
1548+ ) do
15071549 case Binding . expand (
1508- Binding . from_env ( env , metadata ) ,
1550+ Binding . from_env ( env , metadata , cursor_position ) ,
15091551 binding_ast
15101552 ) do
15111553 :none -> :error
0 commit comments