Skip to content

Commit

Permalink
make more regexes unicode aware
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 25, 2023
1 parent 46117cd commit 3cd4756
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/elixir_sense.ex
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ defmodule ElixirSense do

# Fix incomplete kw, e.g. cursor after `option1: 1,`
fix_incomplete_kw = fn text_before, text_after ->
if Regex.match?(~r/\,\s*$/, text_before) do
if Regex.match?(~r/\,\s*$/u, text_before) do
text_before <> "__fake_key__: :__fake_value__" <> text_after
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/elixir_sense/core/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ defmodule ElixirSense.Core.Parser do
when is_integer(cursor_line_number) and
message in ["unexpected token: ", "unexpected reserved word: "] do
terminator =
case Regex.run(~r/terminator\s\"([^\s\"]+)/, text) do
case Regex.run(~r/terminator\s\"([^\s\"]+)/u, text) do
[_, terminator] -> terminator
nil -> nil
end
Expand Down Expand Up @@ -201,7 +201,7 @@ defmodule ElixirSense.Core.Parser do
{:error, {line_number, "syntax" <> _, terminator_quoted}}
)
when is_integer(line_number) and terminator_quoted in ["'end'", "')'", "']'"] do
terminator = Regex.replace(~r/[\"\']/, terminator_quoted, "")
terminator = Regex.replace(~r/[\"\']/u, terminator_quoted, "")

source
|> Source.split_lines()
Expand All @@ -219,7 +219,7 @@ defmodule ElixirSense.Core.Parser do
{:error, {line_number, "unexpected expression after keyword list" <> _, token}}
)
when is_integer(line_number) do
token = Regex.replace(~r/[\"\']/, token, "")
token = Regex.replace(~r/[\"\']/u, token, "")

source
|> Source.split_lines()
Expand Down Expand Up @@ -274,12 +274,12 @@ defmodule ElixirSense.Core.Parser do
)
when is_integer(cursor_line_number) do
terminator =
case Regex.run(~r/terminator:\s([^\s]+)/, text) do
case Regex.run(~r/terminator:\s([^\s]+)/u, text) do
[_, terminator] -> terminator
end

line_start =
case Regex.run(~r/line\s(\d+)/, text) do
case Regex.run(~r/line\s(\d+)/u, text) do
[_, line] -> line |> String.to_integer()
end

Expand Down Expand Up @@ -358,7 +358,7 @@ defmodule ElixirSense.Core.Parser do
)
when is_integer(cursor_line_number) do
line_start =
case Regex.run(~r/line\s(\d+)/, text) do
case Regex.run(~r/line\s(\d+)/u, text) do
[_, line] -> line |> String.to_integer()
end

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_sense/core/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ defmodule ElixirSense.Core.Source do
def get_v12_module_prefix(text_before, current_module) do
with %{"module" => module_str} <-
Regex.named_captures(
~r/(alias|require|import|use)\s+(?<module>[^\s^\{^\}]+?)\.\{[^\}]*?$/,
~r/(alias|require|import|use)\s+(?<module>[^\s^\{^\}]+?)\.\{[^\}]*?$/u,
text_before
),
{:ok, ast} <- Code.string_to_quoted(module_str),
Expand Down
6 changes: 3 additions & 3 deletions lib/elixir_sense/location.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule ElixirSense.Location do
end

defp find_fun_position_in_erl_file(file, nil) do
case find_line_by_regex(file, ~r/^-module/) do
case find_line_by_regex(file, ~r/^-module/u) do
nil -> nil
position -> {position, :module}
end
Expand All @@ -143,7 +143,7 @@ defmodule ElixirSense.Location do
|> Atom.to_string()
|> Regex.escape()

case find_line_by_regex(file, ~r/^#{escaped}\b/) do
case find_line_by_regex(file, ~r/^#{escaped}\b/u) do
nil -> nil
position -> {position, :function}
end
Expand All @@ -155,7 +155,7 @@ defmodule ElixirSense.Location do
|> Atom.to_string()
|> Regex.escape()

find_line_by_regex(file, ~r/^-(typep?|opaque)\s#{escaped}\b/)
find_line_by_regex(file, ~r/^-(typep?|opaque)\s#{escaped}\b/u)
end

defp find_line_by_regex(file, regex) do
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_sense/plugins/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ defmodule ElixirSense.Plugins.Ecto do
end

defp after_in?(hint, text_before) do
Regex.match?(~r/\s+in\s+#{hint}$/, text_before)
Regex.match?(~r/\s+in\s+#{hint}$/u, text_before)
end
end
2 changes: 1 addition & 1 deletion lib/elixir_sense/plugins/ecto/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule ElixirSense.Plugins.Ecto.Types do
end

defp buitin_type_to_suggestion({type, elixir_type, literal_syntax, snippet}, hint, text_after) do
[_, hint_prefix] = Regex.run(~r/(.*?)[\w0-9\._!\?\->]*$/, hint)
[_, hint_prefix] = Regex.run(~r/(.*?)[\w0-9\._!\?\->]*$/u, hint)

insert_text = String.replace_prefix(type, hint_prefix, "")
snippet = snippet && String.replace_prefix(snippet, hint_prefix, "")
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_sense/plugins/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule ElixirSense.Plugins.Util do
end

def trim_leading_for_insertion(hint, value) do
[_, hint_prefix] = Regex.run(~r/(.*?)[\w0-9\._!\?\->]*$/, hint)
[_, hint_prefix] = Regex.run(~r/(.*?)[\w0-9\._!\?\->]*$/u, hint)
insert_text = String.replace_prefix(value, hint_prefix, "")

case String.split(hint, ".") do
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_sense/providers/signature.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule ElixirSense.Providers.Signature do
defaults =
params
|> Enum.with_index()
|> Enum.map(fn {param, index} -> {Regex.match?(~r/\\\\/, param), index} end)
|> Enum.map(fn {param, index} -> {Regex.match?(~r/\\\\/u, param), index} end)
|> Enum.sort()
|> Enum.at(npar)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule ElixirSense.Providers.Suggestion.Reducers.Callbacks do
Introspection.get_callbacks_with_docs(mod),
def_prefix?(hint, spec) or Matcher.match?("#{name}", hint) do
desc = Introspection.extract_summary_from_docs(doc)
[_, args_str] = Regex.run(~r/.\(([^\)]*)\)/, signature)
[_, args_str] = Regex.run(~r/.\(([^\)]*)\)/u, signature)

args_list =
args_str
Expand Down

0 comments on commit 3cd4756

Please sign in to comment.