@@ -719,9 +719,12 @@ function _complete_methods(ex_org::Expr, context_module::Module, shift::Bool)
719719 return kwargs_flag, funct, args_ex, kwargs_ex
720720end
721721
722- function complete_methods (ex_org:: Expr , context_module:: Module = Main, shift:: Bool = false )
722+ # cursor_pos: either :positional (complete either kwargs or positional) or :kwargs (beyond semicolon)
723+ function complete_methods (ex_org:: Expr , context_module:: Module = Main, shift:: Bool = false , cursor_pos:: Symbol = :positional )
723724 kwargs_flag, funct, args_ex, kwargs_ex = _complete_methods (ex_org, context_module, shift):: Tuple{Int, Any, Vector{Any}, Set{Symbol}}
724725 out = Completion[]
726+ # Allow more arguments when cursor before semicolon, even if kwargs are present
727+ cursor_pos == :positional && kwargs_flag == 1 && (kwargs_flag = 0 )
725728 kwargs_flag == 2 && return out # one of the kwargs is invalid
726729 kwargs_flag == 0 && push! (args_ex, Vararg{Any}) # allow more arguments if there is no semicolon
727730 complete_methods! (out, funct, args_ex, kwargs_ex, shift ? - 2 : MAX_METHOD_COMPLETIONS, kwargs_flag == 1 )
@@ -898,14 +901,16 @@ end
898901end
899902
900903# Provide completion for keyword arguments in function calls
904+ # Returns true if the current argument must be a keyword because the cursor is beyond the semicolon
901905function complete_keyword_argument! (suggestions:: Vector{Completion} ,
902906 ex:: Expr , last_word:: String ,
903- context_module:: Module ; shift:: Bool = false )
907+ context_module:: Module ,
908+ arg_pos:: Symbol ; shift:: Bool = false )
904909 kwargs_flag, funct, args_ex, kwargs_ex = _complete_methods (ex, context_module, true ):: Tuple{Int, Any, Vector{Any}, Set{Symbol}}
905- kwargs_flag == 2 && false # one of the previous kwargs is invalid
910+ kwargs_flag == 2 && return false # one of the previous kwargs is invalid
906911
907912 methods = Completion[]
908- complete_methods! (methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? - 1 : MAX_METHOD_COMPLETIONS, kwargs_flag == 1 )
913+ complete_methods! (methods, funct, Any[Vararg{Any}], kwargs_ex, shift ? - 1 : MAX_METHOD_COMPLETIONS, arg_pos == :kwargs )
909914 # TODO : use args_ex instead of Any[Vararg{Any}] and only provide kwarg completion for
910915 # method calls compatible with the current arguments.
911916
@@ -935,7 +940,7 @@ function complete_keyword_argument!(suggestions::Vector{Completion},
935940 for kwarg in kwargs
936941 push! (suggestions, KeywordArgumentCompletion (kwarg))
937942 end
938- return kwargs_flag != 0
943+ return kwargs_flag != 0 && arg_pos == :kwargs
939944end
940945
941946function get_loading_candidates (pkgstarts:: String , project_file:: String )
@@ -1071,7 +1076,8 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
10711076 (kind (cur) in KSet " String Comment ErrorEofMultiComment" || inside_cmdstr) &&
10721077 return Completion[], 1 : 0 , false
10731078
1074- if (n = find_prefix_call (cur_not_ws)) != = nothing
1079+ n, arg_pos = find_prefix_call (cur_not_ws)
1080+ if n != = nothing
10751081 func = first (children_nt (n))
10761082 e = Expr (n)
10771083 # Remove arguments past the first parse error (allows unclosed parens)
@@ -1088,15 +1094,15 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
10881094 # foo(x, TAB => list of methods signatures for foo with x as first argument
10891095 if kind (cur_not_ws) in KSet " ( , ;"
10901096 # Don't provide method completions unless the cursor is after: '(' ',' ';'
1091- return complete_methods (e, context_module, shift), char_range (func), false
1097+ return complete_methods (e, context_module, shift, arg_pos ), char_range (func), false
10921098
10931099 # Keyword argument completion:
10941100 # foo(ar TAB => keyword arguments like `arg1=`
10951101 elseif kind (cur) == K " Identifier"
10961102 r = char_range (cur)
10971103 s = string[intersect (r, 1 : pos)]
10981104 # Return without adding more suggestions if kwargs only
1099- complete_keyword_argument! (suggestions, e, s, context_module; shift) &&
1105+ complete_keyword_argument! (suggestions, e, s, context_module, arg_pos ; shift) &&
11001106 return sort_suggestions (), r, true
11011107 end
11021108 end
@@ -1184,18 +1190,20 @@ function find_str(cur::CursorNode)
11841190end
11851191
11861192# Is the cursor directly inside of the arguments of a prefix call (no nested
1187- # expressions)?
1193+ # expressions)? If so, return:
1194+ # - The call node
1195+ # - Either :positional or :kwargs, if the cursor is before or after the `;`
11881196function find_prefix_call (cur:: CursorNode )
11891197 n = cur. parent
1190- n != = nothing || return nothing
1198+ n != = nothing || return nothing , nothing
11911199 is_call (n) = kind (n) in KSet " call dotcall" && is_prefix_call (n)
11921200 if kind (n) == K " parameters"
1193- is_call (n. parent) || return nothing
1194- n. parent
1201+ is_call (n. parent) || return nothing , nothing
1202+ n. parent, :kwargs
11951203 else
11961204 # Check that we are beyond the function name.
1197- is_call (n) && cur. index > children_nt (n)[1 ]. index || return nothing
1198- n
1205+ is_call (n) && cur. index > children_nt (n)[1 ]. index || return nothing , nothing
1206+ n, :positional
11991207 end
12001208end
12011209
0 commit comments