@@ -19,6 +19,10 @@ struct KeywordCompletion <: Completion
1919 keyword:: String
2020end
2121
22+ struct KeyvalCompletion <: Completion
23+ keyval:: String
24+ end
25+
2226struct PathCompletion <: Completion
2327 path:: String
2428end
99103
100104_completion_text (c:: TextCompletion ) = c. text
101105_completion_text (c:: KeywordCompletion ) = c. keyword
106+ _completion_text (c:: KeyvalCompletion ) = c. keyval
102107_completion_text (c:: PathCompletion ) = c. path
103108_completion_text (c:: ModuleCompletion ) = c. mod
104109_completion_text (c:: PackageCompletion ) = c. package
@@ -220,24 +225,30 @@ function add_field_completions!(suggestions::Vector{Completion}, name::String, @
220225 end
221226end
222227
228+ function complete_from_list (T:: Type , list:: Vector{String} , s:: Union{String,SubString{String}} )
229+ r = searchsorted (list, s)
230+ i = first (r)
231+ n = length (list)
232+ while i <= n && startswith (list[i],s)
233+ r = first (r): i
234+ i += 1
235+ end
236+ Completion[T (kw) for kw in list[r]]
237+ end
238+
223239const sorted_keywords = [
224240 " abstract type" , " baremodule" , " begin" , " break" , " catch" , " ccall" ,
225- " const" , " continue" , " do" , " else" , " elseif" , " end" , " export" , " false " ,
241+ " const" , " continue" , " do" , " else" , " elseif" , " end" , " export" ,
226242 " finally" , " for" , " function" , " global" , " if" , " import" ,
227243 " let" , " local" , " macro" , " module" , " mutable struct" ,
228244 " primitive type" , " quote" , " return" , " struct" ,
229- " true " , " try" , " using" , " while" ]
245+ " try" , " using" , " while" ]
230246
231- function complete_keyword (s:: Union{String,SubString{String}} )
232- r = searchsorted (sorted_keywords, s)
233- i = first (r)
234- n = length (sorted_keywords)
235- while i <= n && startswith (sorted_keywords[i],s)
236- r = first (r): i
237- i += 1
238- end
239- Completion[KeywordCompletion (kw) for kw in sorted_keywords[r]]
240- end
247+ complete_keyword (s:: Union{String,SubString{String}} ) = complete_from_list (KeywordCompletion, sorted_keywords, s)
248+
249+ const sorted_keyvals = [" false" , " true" ]
250+
251+ complete_keyval (s:: Union{String,SubString{String}} ) = complete_from_list (KeyvalCompletion, sorted_keyvals, s)
241252
242253function complete_path (path:: AbstractString , pos:: Int ;
243254 use_envpath= false , shell_escape= false ,
@@ -926,6 +937,7 @@ function complete_keyword_argument(partial, last_idx, context_module)
926937
927938 suggestions = Completion[KeywordArgumentCompletion (kwarg) for kwarg in kwargs]
928939 append! (suggestions, complete_symbol (nothing , last_word, Returns (true ), context_module))
940+ append! (suggestions, complete_keyval (last_word))
929941
930942 return sort! (suggestions, by= completion_text), wordrange
931943end
948960
949961function complete_identifiers! (suggestions:: Vector{Completion} , @nospecialize (ffunc:: Function ), context_module:: Module , string:: String , name:: String , pos:: Int , dotpos:: Int , startpos:: Int , comp_keywords= false )
950962 ex = nothing
951- comp_keywords && append! (suggestions, complete_keyword (name))
963+ if comp_keywords
964+ append! (suggestions, complete_keyword (name))
965+ append! (suggestions, complete_keyval (name))
966+ end
952967 if dotpos > 1 && string[dotpos] == ' .'
953968 s = string[1 : dotpos- 1 ]
954969 # First see if the whole string up to `pos` is a valid expression. If so, use it.
0 commit comments