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