@@ -601,60 +601,74 @@ end
601
601
602
602
end # @static if isdefined(Base, :TOML)
603
603
604
- function completions (string:: String , pos:: Int , context_module:: Module = Main, shift:: Bool = true )
604
+ function completions (string:: String , pos:: Int , context_module:: Module = Main, shift:: Bool = true ;
605
+ enable_questionmark_methods:: Bool = true ,
606
+ enable_dict_keys:: Bool = true ,
607
+ enable_expanduser:: Bool = true ,
608
+ enable_path:: Bool = true ,
609
+ enable_bslash:: Bool = true ,
610
+ enable_methods:: Bool = true ,
611
+ enable_keyword_argument:: Bool = true ,
612
+ enable_packages:: Bool = true ,
613
+ )
605
614
# First parse everything up to the current position
606
615
partial = string[1 : pos]
607
616
inc_tag = Base. incomplete_tag (Meta. parse (partial, raise= false , depwarn= false ))
608
617
609
- # ?(x, y)TAB lists methods you can call with these objects
610
- # ?(x, y TAB lists methods that take these objects as the first two arguments
611
- # MyModule.?(x, y)TAB restricts the search to names in MyModule
612
- rexm = match (r" (\w +\. |)\?\( (.*)$" , partial)
613
- if rexm != = nothing
614
- # Get the module scope
615
- if isempty (rexm. captures[1 ])
616
- callee_module = context_module
617
- else
618
- modname = Symbol (rexm. captures[1 ][1 : end - 1 ])
619
- if isdefined (context_module, modname)
620
- callee_module = getfield (context_module, modname)
621
- if ! isa (callee_module, Module)
618
+ if enable_questionmark_methods
619
+ # ?(x, y)TAB lists methods you can call with these objects
620
+ # ?(x, y TAB lists methods that take these objects as the first two arguments
621
+ # MyModule.?(x, y)TAB restricts the search to names in MyModule
622
+ rexm = match (r" (\w +\. |)\?\( (.*)$" , partial)
623
+ if rexm != = nothing
624
+ # Get the module scope
625
+ if isempty (rexm. captures[1 ])
626
+ callee_module = context_module
627
+ else
628
+ modname = Symbol (rexm. captures[1 ][1 : end - 1 ])
629
+ if isdefined (context_module, modname)
630
+ callee_module = getfield (context_module, modname)
631
+ if ! isa (callee_module, Module)
632
+ callee_module = context_module
633
+ end
634
+ else
622
635
callee_module = context_module
623
636
end
624
- else
625
- callee_module = context_module
626
637
end
627
- end
628
- moreargs = ! endswith ( rexm. captures[2 ], ' ) ' )
629
- callstr = " _( " * rexm . captures[ 2 ]
630
- if moreargs
631
- callstr *= ' ) '
632
- end
633
- ex_org = Meta . parse (callstr, raise = false , depwarn = false )
634
- if isa (ex_org, Expr)
635
- return complete_any_methods (ex_org, callee_module :: Module , context_module, moreargs, shift), ( 0 : length (rexm . captures[ 1 ]) + 1 ) .+ rexm . offset, false
638
+ moreargs = ! endswith (rexm . captures[ 2 ], ' ) ' )
639
+ callstr = " _( " * rexm. captures[2 ]
640
+ if moreargs
641
+ callstr *= ' ) '
642
+ end
643
+ ex_org = Meta . parse (callstr, raise = false , depwarn = false )
644
+ if isa (ex_org, Expr )
645
+ return complete_any_methods (ex_org, callee_module :: Module , context_module, moreargs, shift), ( 0 : length (rexm . captures[ 1 ]) + 1 ) .+ rexm . offset, false
646
+ end
636
647
end
637
648
end
638
649
639
- # if completing a key in a Dict
640
- identifier, partial_key, loc = dict_identifier_key (partial,inc_tag, context_module)
641
- if identifier != = nothing
642
- matches = find_dict_matches (identifier):: Vector{String}
643
- length (matches)== 1 && (lastindex (string) <= pos || string[nextind (string,pos)] != ' ]' ) && (matches[1 ]*= ' ]' )
644
- if length (matches)> 0
645
- suggestions = Completion[DictCompletion (identifier, match, partial_key) for match in matches]
646
- return sort_suggestions! (suggestions), loc: pos, false
650
+ if enable_dict_keys
651
+ identifier, partial_key, loc = dict_identifier_key (partial,inc_tag, context_module)
652
+ if identifier != = nothing
653
+ matches = find_dict_matches (identifier):: Vector{String}
654
+ length (matches)== 1 && (lastindex (string) <= pos || string[nextind (string,pos)] != ' ]' ) && (matches[1 ]*= ' ]' )
655
+ if length (matches)> 0
656
+ suggestions = Completion[DictCompletion (identifier, match, partial_key) for match in matches]
657
+ return sort_suggestions! (suggestions), loc: pos, false
658
+ end
647
659
end
648
660
end
649
661
650
662
# otherwise...
651
- if inc_tag in [:cmd , :string ]
663
+ if enable_path && inc_tag in [:cmd , :string ]
652
664
m = match (r" [\t\n\r\" `><=*?|]| (?!\\ )" , reverse (partial))
653
665
startpos = nextind (partial, reverseind (partial, m. offset))
654
666
r = startpos: pos
655
667
656
- expanded = complete_expanduser (replace (string[r], r" \\ " => " " ), r)
657
- expanded[3 ] && return expanded # If user expansion available, return it
668
+ if enable_expanduser
669
+ expanded = complete_expanduser (replace (string[r], r" \\ " => " " ), r)
670
+ expanded[3 ] && return expanded # If user expansion available, return it
671
+ end
658
672
659
673
paths, r, success = complete_path (replace (string[r], r" \\ " => " " ), pos)
660
674
@@ -674,12 +688,15 @@ function completions(string::String, pos::Int, context_module::Module = Main, sh
674
688
(success || inc_tag === :cmd ) && return paths, r, success
675
689
end
676
690
677
- ok, ret = bslash_completions (string, pos)
678
- ok && return ret
691
+ if enable_bslash
692
+ ok, ret = bslash_completions (string, pos)
693
+ ok && return ret
694
+ end
679
695
680
696
# Make sure that only bslash_completions is working on strings
681
- inc_tag== :string && return Completion[], 0 : - 1 , false
682
- if @static VERSION ≥ v " 1.9.0-DEV.1034" && inc_tag === :other
697
+ inc_tag === :string && return Completion[], 0 : - 1 , false
698
+
699
+ if @static VERSION ≥ v " 1.9.0-DEV.1034" && enable_methods && inc_tag === :other
683
700
frange, ex, wordrange, method_name_end = identify_possible_method_completion (partial, pos)
684
701
if last (frange) != - 1 && all (isspace, @view partial[wordrange]) # no last argument to complete
685
702
if ex. head === :call
@@ -688,7 +705,7 @@ function completions(string::String, pos::Int, context_module::Module = Main, sh
688
705
return complete_methods (ex, context_module, shift), first (frange): (method_name_end - 1 ), false
689
706
end
690
707
end
691
- elseif @static VERSION < v " 1.9.0-DEV.1034" && inc_tag === :other && should_method_complete (partial)
708
+ elseif @static VERSION < v " 1.9.0-DEV.1034" && enable_methods && inc_tag === :other && should_method_complete (partial)
692
709
frange, method_name_end = find_start_brace (partial)
693
710
# strip preceding ! operator
694
711
s = replace (partial[frange], r" \! +([^=\( ]+)" => s "\1 " )
@@ -708,10 +725,10 @@ function completions(string::String, pos::Int, context_module::Module = Main, sh
708
725
return Completion[], 0 : - 1 , false
709
726
end
710
727
711
- @static if VERSION ≥ v " 1.9.0-DEV.1034"
712
- # Check whether we can complete a keyword argument in a function call
713
- kwarg_completion, wordrange = complete_keyword_argument (partial, pos, context_module)
714
- isempty (wordrange) || return kwarg_completion, wordrange, ! isempty (kwarg_completion)
728
+ enable_keyword_argument && @static if VERSION ≥ v " 1.9.0-DEV.1034"
729
+ # Check whether we can complete a keyword argument in a function call
730
+ kwarg_completion, wordrange = complete_keyword_argument (partial, pos, context_module)
731
+ isempty (wordrange) || return kwarg_completion, wordrange, ! isempty (kwarg_completion)
715
732
end
716
733
717
734
dotpos = something (findprev (isequal (' .' ), string, pos), 0 )
@@ -724,7 +741,7 @@ function completions(string::String, pos::Int, context_module::Module = Main, sh
724
741
ffunc = (mod,x)-> true
725
742
suggestions = Completion[]
726
743
comp_keywords = true
727
- if afterusing (string, startpos)
744
+ if enable_packages && afterusing (string, startpos)
728
745
# We're right after using or import. Let's look only for packages
729
746
# and modules we can reach from here
730
747
0 commit comments