Skip to content

Commit 2376e3f

Browse files
committed
make all regex matching identifiers unicode aware
elixir supports unicode identifiers since 1.5 Fixes #274
1 parent 1dc748b commit 2376e3f

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

lib/elixir_sense.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ defmodule ElixirSense do
515515
# without parens.
516516
#
517517
# Note: This will be removed after refactoring the parser to
518-
# allow unparseable nodes in the AST.
518+
# allow unparsable nodes in the AST.
519519
defp maybe_fix_autocomple_on_cursor(%Metadata{error: nil} = meta, _, _, _) do
520520
meta
521521
end
@@ -537,11 +537,13 @@ defmodule ElixirSense do
537537

538538
# Fix incomplete kw key, e.g. cursor after `option1: 1, opt`
539539
fix_incomplete_kw_key = fn text_before, text_after ->
540-
if Regex.match?(~r/\,\s*[a-z][a-zA-Z0-9_]*$/, text_before) do
540+
if Regex.match?(~r/\,\s*([\p{L}_][\p{L}\p{N}_@]*[?!]?)?$/, text_before) do
541541
text_before <> ": :__fake_value__" <> text_after
542542
end
543543
end
544544

545+
# TODO this may no longer be needed
546+
# only fix_incomplete_call has some tests depending on it
545547
fixers = [
546548
fix_incomplete_call,
547549
fix_incomplete_kw,

lib/elixir_sense/core/metadata_builder.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,10 @@ defmodule ElixirSense.Core.MetadataBuilder do
776776
end
777777

778778
defp pre({:@, meta_attr, [{name, meta, params}]}, state) when is_atom(name) do
779-
if String.match?(Atom.to_string(name), ~r/^[a-zA-Z_].*/) do
779+
name_string = Atom.to_string(name)
780+
781+
if String.match?(name_string, ~r/^[_\p{Ll}\p{Lo}][\p{L}\p{N}_]*[?!]?$/) and
782+
not String.starts_with?(name_string, "__atom_elixir_marker_") do
780783
line = Keyword.fetch!(meta_attr, :line)
781784
column = Keyword.fetch!(meta_attr, :column)
782785

lib/elixir_sense/core/parser.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ defmodule ElixirSense.Core.Parser do
246246
|> Enum.join("\n")
247247

248248
_ ->
249-
if Regex.match?(~r/^[a-zA-Z_][a-zA-Z0-9_]*$/, token) do
249+
if Regex.match?(~r/^[\p{L}_][\p{L}\p{N}_@]*[?!]?$/, token) do
250250
remove_line(source, line)
251251
else
252252
replace_line_with_marker(source, line)

lib/elixir_sense/plugins/ecto.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ defmodule ElixirSense.Plugins.Ecto do
7979
_ -> nil
8080
end),
8181
assoc_code <- Source.text_after(text_before, line, col),
82-
[_, var] <- Regex.run(~r/^assoc\(\s*([a-z][a-zA-Z0-9_]*)\s*,/, assoc_code),
82+
[_, var] <-
83+
Regex.run(~r/^assoc\(\s*([_\p{Ll}\p{Lo}][\p{L}\p{N}_]*[?!]?)\s*,/, assoc_code),
8384
%{^var => %{type: type}} <- Query.extract_bindings(text_before, from_info, env, meta),
8485
true <- function_exported?(type, :__schema__, 1) do
8586
{:override, Query.find_assoc_suggestions(type, hint)}

lib/elixir_sense/plugins/ecto/query.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule ElixirSense.Plugins.Ecto.Query do
2929

3030
@join_opts [on: "A query expression or keyword list to filter the join."]
3131

32-
@var_r "[a-z][a-zA-Z0-9_]*"
32+
@var_r "[_\p{Ll}\p{Lo}][\p{L}\p{N}_]*[?!]?"
3333
@mod_r "[A-Z][a-zA-Z0-9_\.]*"
3434
@binding_r "(#{@var_r}) in (#{@mod_r}|assoc\\(\\s*#{@var_r},\\s*\\:#{@var_r}\\s*\\))"
3535

lib/elixir_sense/providers/suggestion/reducers/callbacks.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.Callbacks do
7575
list = Enum.sort(list)
7676

7777
cond do
78-
Regex.match?(~r/\s(def|defmacro)\s+[a-z|_]*$/, text_before) ->
78+
Regex.match?(~r/\s(def|defmacro)\s+([_\p{Ll}\p{Lo}][\p{L}\p{N}_]*[?!]?)?$/, text_before) ->
7979
{:halt, %{acc | result: list}}
8080

8181
match?({_f, _a}, scope) ->

test/elixir_sense/suggestions_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ defmodule ElixirSense.SuggestionsTest do
824824
825825
defmodule MyLocalModule do
826826
@behaviour MyBehaviour
827-
827+
828828
@impl true
829829
def flatten(list) do
830830
[]
@@ -911,7 +911,7 @@ defmodule ElixirSense.SuggestionsTest do
911911
912912
defmodule MyLocalModule do
913913
@behaviour MyBehaviour
914-
914+
915915
@impl true
916916
defmacro flatten(list) do
917917
[]
@@ -951,7 +951,7 @@ defmodule ElixirSense.SuggestionsTest do
951951
buffer = """
952952
defmodule MyLocalModule do
953953
@behaviour ElixirSenseExample.BehaviourWithMeta
954-
954+
955955
@impl true
956956
def flatten(list) do
957957
[]
@@ -989,7 +989,7 @@ defmodule ElixirSense.SuggestionsTest do
989989
buffer = """
990990
defmodule MyLocalModule do
991991
@behaviour :gen_statem
992-
992+
993993
@impl true
994994
def init(list) do
995995
[]
@@ -1029,7 +1029,7 @@ defmodule ElixirSense.SuggestionsTest do
10291029
buffer = """
10301030
defmodule MyLocalModule do
10311031
@behaviour ElixirSenseExample.BehaviourWithMeta
1032-
1032+
10331033
@impl true
10341034
defmacro bar(list) do
10351035
[]

0 commit comments

Comments
 (0)