@@ -940,40 +940,22 @@ const superscript_regex = Regex("^\\\\\\^[" * join(isdigit(k) || isletter(k) ? "
940
940
941
941
# Aux function to detect whether we're right after a using or import keyword
942
942
function get_import_mode (s:: String , pos:: Int )
943
- # allow all of these to start with leading whitespace and macros like @eval and @eval(
944
- # ^\s*(?:@\w+\s*(?:\(\s*)?)?
945
-
946
- # Do not enter import mode unless cursor beyond import keyword
947
- beyond_kw (m) = pos >= m. offsets[1 ] + sizeof (m[1 ])
948
-
949
- # match simple cases like `using |` and `import |`
950
- mod_import_match_simple = match (r" ^\s *(?:@\w +\s *(?:\(\s *)?)?\b (using|import)\s *$" , s)
951
- if mod_import_match_simple != = nothing && beyond_kw (mod_import_match_simple)
952
- if mod_import_match_simple[1 ] == " using"
953
- return :using_module
954
- else
955
- return :import_module
956
- end
957
- end
958
- # match module import statements like `using Foo|`, `import Foo, Bar|` and `using Foo.Bar, Baz, |`
959
- mod_import_match = match (r" ^\s *(?:@\w +\s *(?:\(\s *)?)?\b (using|import)\s +([\w\. ]+(?:\s *,\s *[\w\. ]+)*),?\s *$" , s)
960
- if mod_import_match != = nothing && beyond_kw (mod_import_match)
961
- if mod_import_match. captures[1 ] == " using"
962
- return :using_module
963
- else
964
- return :import_module
943
+ # Capture group 1 will be returned, group 2 is where the cursor should be.
944
+ function match_pos (re)
945
+ for m in eachmatch (re, s, overlap= true )
946
+ m != = nothing || continue
947
+ pos in range (m. offsets[2 ], length= sizeof (m[2 ])) || continue
948
+ return m[1 ]
965
949
end
966
950
end
951
+
952
+ # match module import statements like `using |`, `import |`, `using Foo|`, `import Foo, Bar|` and `using Foo.Bar, Baz, |`
953
+ m = match_pos (r" \b (using|import)(\s +(?:[\w\. ]+(?:\s *,\s *[\w\. ]+)*(:?\s *,)?\s *)?)" )
954
+ m != = nothing && return m == " using" ? :using_module : :import_module
955
+
967
956
# now match explicit name import statements like `using Foo: |` and `import Foo: bar, baz|`
968
- name_import_match = match (r" ^\s *(?:@\w +\s *(?:\(\s *)?)?\b (using|import)\s +([\w\. ]+)\s *:\s *([\w @!\s ,]+)$" , s)
969
- if name_import_match != = nothing && beyond_kw (name_import_match)
970
- if name_import_match[1 ] == " using"
971
- return :using_name
972
- else
973
- return :import_name
974
- end
975
- end
976
- return nothing
957
+ m = match_pos (r" \b (using|import)\s +(?:[\w\. ]+(?:\s *,\s *[\w\. ]+)*)\s *(:\s *(?:[\w @!\s ,]+)*)" )
958
+ m != = nothing && return m == " using" ? :using_name : :import_name
977
959
end
978
960
979
961
function close_path_completion (dir, path, str, pos)
0 commit comments