Skip to content

Commit

Permalink
a few missing renames
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Nov 2, 2023
1 parent c9a5162 commit 867399f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/elixir_sense.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ start(_Type, _Args) ->

Tokenizer = case code:ensure_loaded('Elixir.String.Tokenizer') of
{module, Mod} -> Mod;
_ -> elixir_tokenizer
_ -> elixir_sense_tokenizer
end,

URIConfig = [
Expand Down
107 changes: 107 additions & 0 deletions src/elixir_sense_config.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
% This file includes modified code extracted from the elixir project. Namely:
%
% https://github.com/elixir-lang/elixir/blob/v1.13.4/lib/elixir/src/elixir_config.erl
%
% The original code is licensed as follows:
%
% Copyright 2012 Plataformatec
% Copyright 2021 The Elixir Team
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% https://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

% The only changes here are module renames

-module(elixir_sense_config).
-compile({no_auto_import, [get/1]}).
-export([new/1, warn/2, serial/1]).
-export([static/1, is_bootstrap/0, identifier_tokenizer/0]).
-export([delete/1, put/2, get/1, get/2, update/2, get_and_put/2]).
-export([start_link/0, init/1, handle_call/3, handle_cast/2]).
-behaviour(gen_server).

static(Map) when is_map(Map) ->
persistent_term:put(?MODULE, maps:merge(persistent_term:get(?MODULE, #{}), Map)).
is_bootstrap() ->
maps:get(bootstrap, persistent_term:get(?MODULE, #{}), false).
identifier_tokenizer() ->
maps:get(identifier_tokenizer, persistent_term:get(?MODULE, #{}), 'Elixir.String.Tokenizer').

get(Key) ->
[{_, Value}] = ets:lookup(?MODULE, Key),
Value.

get(Key, Default) ->
try ets:lookup(?MODULE, Key) of
[{_, Value}] -> Value;
[] -> Default
catch
_:_ -> Default
end.

put(Key, Value) ->
gen_server:call(?MODULE, {put, Key, Value}).

get_and_put(Key, Value) ->
gen_server:call(?MODULE, {get_and_put, Key, Value}).

update(Key, Fun) ->
gen_server:call(?MODULE, {update, Key, Fun}).

serial(Fun) ->
gen_server:call(?MODULE, {serial, Fun}).

%% Used to guarantee warnings are emitted only once per caller.
warn(Key, [{Mod, Fun, ArgsOrArity, _} | _]) ->
EtsKey = {warn, Key, Mod, Fun, to_arity(ArgsOrArity)},
ets:update_counter(?MODULE, EtsKey, {2, 1, 1, 1}, {EtsKey, -1}) =:= 0;

warn(_, _) ->
true.

to_arity(Args) when is_list(Args) -> length(Args);
to_arity(Arity) -> Arity.

%% ets life-cycle api

new(Opts) ->
Tab = ets:new(?MODULE, [named_table, public, {read_concurrency, true}]),
true = ets:insert_new(?MODULE, Opts),
Tab.

delete(?MODULE) ->
ets:delete(?MODULE).

%% gen_server api

start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, ?MODULE, []).

init(Tab) ->
{ok, Tab}.

handle_call({serial, Fun}, _From, Tab) ->
{reply, Fun(), Tab};
handle_call({put, Key, Value}, _From, Tab) ->
ets:insert(Tab, {Key, Value}),
{reply, ok, Tab};
handle_call({update, Key, Fun}, _From, Tab) ->
Value = Fun(get(Key)),
ets:insert(Tab, {Key, Value}),
{reply, Value, Tab};
handle_call({get_and_put, Key, Value}, _From, Tab) ->
OldValue = get(Key),
ets:insert(Tab, {Key, Value}),
{reply, OldValue, Tab}.

handle_cast(Cast, Tab) ->
{stop, {bad_cast, Cast}, Tab}.
2 changes: 1 addition & 1 deletion src/elixir_sense_parser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ error_no_parens_container_strict(Node) ->
"Elixir cannot compile otherwise. Syntax error before: ", "','").

error_invalid_kw_identifier({_, Location, do}) ->
return_error(Location, elixir_tokenizer:invalid_do_error("unexpected keyword: "), "do:");
return_error(Location, elixir_sense_tokenizer:invalid_do_error("unexpected keyword: "), "do:");
error_invalid_kw_identifier({_, Location, KW}) ->
return_error(Location, "syntax error before: ", "'" ++ atom_to_list(KW) ++ ":'").

Expand Down
16 changes: 8 additions & 8 deletions src/elixir_sense_tokenizer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ tokenize(String, Line, Column, #elixir_tokenizer{} = Scope) ->
tokenize(String, Line, Column, Scope, []);

tokenize(String, Line, Column, Opts) ->
IdentifierTokenizer = elixir_config:identifier_tokenizer(),
IdentifierTokenizer = elixir_sense_config:identifier_tokenizer(),

Scope =
lists:foldl(fun
Expand Down Expand Up @@ -225,7 +225,7 @@ tokenize([$~, S, H, H, H | T] = Original, Line, Column, Scope, Tokens) when ?is_
end;

tokenize([$~, S, H | T] = Original, Line, Column, Scope, Tokens) when ?is_sigil(H), ?is_upcase(S) orelse ?is_downcase(S) ->
case elixir_interpolation:extract(Line, Column + 3, Scope, ?is_downcase(S), T, sigil_terminator(H)) of
case elixir_sense_interpolation:extract(Line, Column + 3, Scope, ?is_downcase(S), T, sigil_terminator(H)) of
{NewLine, NewColumn, Parts, Rest, NewScope} ->
{Final, Modifiers} = collect_modifiers(Rest, []),
Indentation = nil,
Expand Down Expand Up @@ -255,7 +255,7 @@ tokenize([$~, S, H | _] = Original, Line, Column, Scope, Tokens) when ?is_upcase
% and printed with Erlang syntax ($a) in the parser's error messages.

tokenize([$?, $\\, H | T], Line, Column, Scope, Tokens) ->
Char = elixir_interpolation:unescape_map(H),
Char = elixir_sense_interpolation:unescape_map(H),

NewScope = if
H =:= Char, H =/= $\\ ->
Expand Down Expand Up @@ -508,7 +508,7 @@ tokenize([T | Rest], Line, Column, Scope, Tokens) when ?pipe_op(T) ->
% Non-operator Atoms

tokenize([$:, H | T] = Original, Line, Column, Scope, Tokens) when ?is_quote(H) ->
case elixir_interpolation:extract(Line, Column + 2, Scope, true, T, H) of
case elixir_sense_interpolation:extract(Line, Column + 2, Scope, true, T, H) of
{NewLine, NewColumn, Parts, Rest, InterScope} ->
NewScope = case is_unnecessary_quote(Parts, InterScope) of
true ->
Expand Down Expand Up @@ -775,7 +775,7 @@ handle_heredocs(T, Line, Column, H, Scope, Tokens) ->
end.

handle_strings(T, Line, Column, H, Scope, Tokens) ->
case elixir_interpolation:extract(Line, Column, Scope, true, T, H) of
case elixir_sense_interpolation:extract(Line, Column, Scope, true, T, H) of
{error, Reason} ->
interpolation_error(Reason, [H | T], Scope, Tokens, " (for string starting at line ~B)", [Line]);

Expand Down Expand Up @@ -891,7 +891,7 @@ handle_dot([$., $( | Rest], Line, Column, DotInfo, Scope, Tokens) ->
tokenize([$( | Rest], Line, Column, Scope, TokensSoFar);

handle_dot([$., H | T] = Original, Line, Column, DotInfo, Scope, Tokens) when ?is_quote(H) ->
case elixir_interpolation:extract(Line, Column + 1, Scope, true, T, H) of
case elixir_sense_interpolation:extract(Line, Column + 1, Scope, true, T, H) of
{NewLine, NewColumn, [Part], Rest, InterScope} when is_list(Part) ->
NewScope = case is_unnecessary_quote([Part], InterScope) of
true ->
Expand Down Expand Up @@ -1017,7 +1017,7 @@ extract_heredoc_with_interpolation(Line, Column, Scope, Interpol, T, H) ->
%% We prepend a new line so we can transparently remove
%% spaces later. This new line is removed by calling "tl"
%% in the final heredoc body three lines below.
case elixir_interpolation:extract(Line, Column, Scope, Interpol, [$\n|Headerless], [H,H,H]) of
case elixir_sense_interpolation:extract(Line, Column, Scope, Interpol, [$\n|Headerless], [H,H,H]) of
{NewLine, NewColumn, Parts0, Rest, InterScope} ->
Indent = NewColumn - 4,
Fun = fun(Part, Acc) -> extract_heredoc_indent(Part, Acc, Indent) end,
Expand Down Expand Up @@ -1088,7 +1088,7 @@ maybe_heredoc_warn(Line, Column, Scope, Marker) ->
extract_heredoc_head([[$\n|H]|T]) -> [H|T].

unescape_tokens(Tokens, Line, Column, #elixir_tokenizer{unescape=true}) ->
case elixir_interpolation:unescape_tokens(Tokens) of
case elixir_sense_interpolation:unescape_tokens(Tokens) of
{ok, Result} ->
{ok, Result};

Expand Down

0 comments on commit 867399f

Please sign in to comment.