@@ -19,6 +19,10 @@ struct KeywordCompletion <: Completion
19
19
keyword:: String
20
20
end
21
21
22
+ struct KeyvalCompletion <: Completion
23
+ keyval:: String
24
+ end
25
+
22
26
struct PathCompletion <: Completion
23
27
path:: String
24
28
end
99
103
100
104
_completion_text (c:: TextCompletion ) = c. text
101
105
_completion_text (c:: KeywordCompletion ) = c. keyword
106
+ _completion_text (c:: KeyvalCompletion ) = c. keyval
102
107
_completion_text (c:: PathCompletion ) = c. path
103
108
_completion_text (c:: ModuleCompletion ) = c. mod
104
109
_completion_text (c:: PackageCompletion ) = c. package
@@ -213,24 +218,30 @@ function complete_symbol(@nospecialize(ex), name::String, @nospecialize(ffunc),
213
218
suggestions
214
219
end
215
220
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
+
216
232
const sorted_keywords = [
217
233
" abstract type" , " baremodule" , " begin" , " break" , " catch" , " ccall" ,
218
- " const" , " continue" , " do" , " else" , " elseif" , " end" , " export" , " false " ,
234
+ " const" , " continue" , " do" , " else" , " elseif" , " end" , " export" ,
219
235
" finally" , " for" , " function" , " global" , " if" , " import" ,
220
236
" let" , " local" , " macro" , " module" , " mutable struct" ,
221
237
" primitive type" , " quote" , " return" , " struct" ,
222
- " true " , " try" , " using" , " while" ]
238
+ " try" , " using" , " while" ]
223
239
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)
234
245
235
246
function complete_path (path:: AbstractString , pos:: Int ;
236
247
use_envpath= false , shell_escape= false ,
@@ -919,6 +930,7 @@ function complete_keyword_argument(partial, last_idx, context_module)
919
930
920
931
suggestions = Completion[KeywordArgumentCompletion (kwarg) for kwarg in kwargs]
921
932
append! (suggestions, complete_symbol (nothing , last_word, Returns (true ), context_module))
933
+ append! (suggestions, complete_keyval (last_word))
922
934
923
935
return sort! (suggestions, by= completion_text), wordrange
924
936
end
941
953
942
954
function complete_identifiers! (suggestions:: Vector{Completion} , @nospecialize (ffunc:: Function ), context_module:: Module , string:: String , name:: String , pos:: Int , dotpos:: Int , startpos:: Int , comp_keywords= false )
943
955
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
945
960
if dotpos > 1 && string[dotpos] == ' .'
946
961
s = string[1 : prevind (string, dotpos)]
947
962
# First see if the whole string up to `pos` is a valid expression. If so, use it.
0 commit comments