@@ -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
@@ -213,24 +218,30 @@ function complete_symbol(@nospecialize(ex), name::String, @nospecialize(ffunc),
213218 suggestions
214219end
215220
221+ function complete_from_list (T:: Type , list:: Vector{String} , s:: Union{String,SubString{String}} )
222+ r = searchsorted (list, s)
223+ i = first (r)
224+ n = length (list)
225+ while i <= n && startswith (list[i],s)
226+ r = first (r): i
227+ i += 1
228+ end
229+ Completion[T (kw) for kw in list[r]]
230+ end
231+
216232const sorted_keywords = [
217233 " abstract type" , " baremodule" , " begin" , " break" , " catch" , " ccall" ,
218- " const" , " continue" , " do" , " else" , " elseif" , " end" , " export" , " false " ,
234+ " const" , " continue" , " do" , " else" , " elseif" , " end" , " export" ,
219235 " finally" , " for" , " function" , " global" , " if" , " import" ,
220236 " let" , " local" , " macro" , " module" , " mutable struct" ,
221237 " primitive type" , " quote" , " return" , " struct" ,
222- " true " , " try" , " using" , " while" ]
238+ " try" , " using" , " while" ]
223239
224- function complete_keyword (s:: Union{String,SubString{String}} )
225- r = searchsorted (sorted_keywords, s)
226- i = first (r)
227- n = length (sorted_keywords)
228- while i <= n && startswith (sorted_keywords[i],s)
229- r = first (r): i
230- i += 1
231- end
232- Completion[KeywordCompletion (kw) for kw in sorted_keywords[r]]
233- end
240+ complete_keyword (s:: Union{String,SubString{String}} ) = complete_from_list (KeywordCompletion, sorted_keywords, s)
241+
242+ const sorted_keyvals = [" false" , " true" ]
243+
244+ complete_keyval (s:: Union{String,SubString{String}} ) = complete_from_list (KeyvalCompletion, sorted_keyvals, s)
234245
235246function complete_path (path:: AbstractString , pos:: Int ;
236247 use_envpath= false , shell_escape= false ,
@@ -919,6 +930,7 @@ function complete_keyword_argument(partial, last_idx, context_module)
919930
920931 suggestions = Completion[KeywordArgumentCompletion (kwarg) for kwarg in kwargs]
921932 append! (suggestions, complete_symbol (nothing , last_word, Returns (true ), context_module))
933+ append! (suggestions, complete_keyval (last_word))
922934
923935 return sort! (suggestions, by= completion_text), wordrange
924936end
941953
942954function complete_identifiers! (suggestions:: Vector{Completion} , @nospecialize (ffunc:: Function ), context_module:: Module , string:: String , name:: String , pos:: Int , dotpos:: Int , startpos:: Int , comp_keywords= false )
943955 ex = nothing
944- comp_keywords && append! (suggestions, complete_keyword (name))
956+ if comp_keywords
957+ append! (suggestions, complete_keyword (name))
958+ append! (suggestions, complete_keyval (name))
959+ end
945960 if dotpos > 1 && string[dotpos] == ' .'
946961 s = string[1 : prevind (string, dotpos)]
947962 # First see if the whole string up to `pos` is a valid expression. If so, use it.
0 commit comments