@@ -939,13 +939,16 @@ const superscripts = Dict(k[3]=>v[1] for (k,v) in latex_symbols if startswith(k,
939
939
const superscript_regex = Regex (" ^\\\\\\ ^[" * join (isdigit (k) || isletter (k) ? " $k " : " \\ $k " for k in keys (superscripts)) * " ]+\\ z" )
940
940
941
941
# Aux function to detect whether we're right after a using or import keyword
942
- function get_import_mode (s:: String )
942
+ function get_import_mode (s:: String , pos :: Int )
943
943
# allow all of these to start with leading whitespace and macros like @eval and @eval(
944
944
# ^\s*(?:@\w+\s*(?:\(\s*)?)?
945
945
946
+ # Do not enter import mode unless cursor beyond import keyword
947
+ beyond_kw (m) = pos >= m. offsets[1 ] + length (m[1 ])
948
+
946
949
# match simple cases like `using |` and `import |`
947
950
mod_import_match_simple = match (r" ^\s *(?:@\w +\s *(?:\(\s *)?)?\b (using|import)\s *$" , s)
948
- if mod_import_match_simple != = nothing
951
+ if mod_import_match_simple != = nothing && beyond_kw (mod_import_match_simple)
949
952
if mod_import_match_simple[1 ] == " using"
950
953
return :using_module
951
954
else
@@ -954,7 +957,7 @@ function get_import_mode(s::String)
954
957
end
955
958
# match module import statements like `using Foo|`, `import Foo, Bar|` and `using Foo.Bar, Baz, |`
956
959
mod_import_match = match (r" ^\s *(?:@\w +\s *(?:\(\s *)?)?\b (using|import)\s +([\w\. ]+(?:\s *,\s *[\w\. ]+)*),?\s *$" , s)
957
- if mod_import_match != = nothing
960
+ if mod_import_match != = nothing && beyond_kw (mod_import_match)
958
961
if mod_import_match. captures[1 ] == " using"
959
962
return :using_module
960
963
else
@@ -963,7 +966,7 @@ function get_import_mode(s::String)
963
966
end
964
967
# now match explicit name import statements like `using Foo: |` and `import Foo: bar, baz|`
965
968
name_import_match = match (r" ^\s *(?:@\w +\s *(?:\(\s *)?)?\b (using|import)\s +([\w\. ]+)\s *:\s *([\w @!\s ,]+)$" , s)
966
- if name_import_match != = nothing
969
+ if name_import_match != = nothing && beyond_kw (name_import_match)
967
970
if name_import_match[1 ] == " using"
968
971
return :using_name
969
972
else
@@ -1462,7 +1465,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
1462
1465
separatorpos = something (findprev (isequal (' .' ), string, pos), 0 )
1463
1466
namepos = max (startpos, separatorpos+ 1 )
1464
1467
name = string[namepos: pos]
1465
- import_mode = get_import_mode (string)
1468
+ import_mode = get_import_mode (string, pos )
1466
1469
if import_mode === :using_module || import_mode === :import_module
1467
1470
# Given input lines like `using Foo|`, `import Foo, Bar|` and `using Foo.Bar, Baz, |`:
1468
1471
# Let's look only for packages and modules we can reach from here
0 commit comments