Skip to content

Commit

Permalink
[dap] add option to configure cookie of the project node
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGeorge committed Feb 16, 2021
1 parent df50bd4 commit 16b2474
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
22 changes: 17 additions & 5 deletions apps/els_dap/src/els_dap_general_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,26 @@ handle_request({<<"launch">>, Params}, State) ->
#{<<"cwd">> := Cwd} = Params,
ok = file:set_cwd(Cwd),
Name = filename:basename(Cwd),

%% start distribution
LocalNode = els_distribution_server:node_name(<<"erlang_ls_dap">>, Name),
els_distribution_server:start_distribution(LocalNode),
?LOG_INFO("Distribution up on: [~p]", [LocalNode]),

%% get configuration for project node and cookie
ProjectNode =
case Params of
#{ <<"projectnode">> := Node } -> binary_to_atom(Node, utf8);
#{ <<"projectnode">> := ConfNode } -> binary_to_atom(ConfNode, utf8);
_ -> els_distribution_server:node_name(<<"erlang_ls_dap_project">>, Name)
end,
Cookie =
case Params of
#{ <<"cookie">> := ConfCookie } -> binary_to_atom(ConfCookie, utf8);
_ -> erlang:get_cookie()
end,
true = erlang:set_cookie(LocalNode, Cookie),


case Params of
#{ <<"runinterminal">> := Cmd
} ->
Expand All @@ -112,14 +127,11 @@ handle_request({<<"launch">>, Params}, State) ->
, "--sname"
, ProjectNode
, "--setcookie"
, erlang:atom_to_list(erlang:get_cookie())
, erlang:atom_to_list(Cookie)
]
)
end)
end,
LocalNode = els_distribution_server:node_name(<<"erlang_ls_dap">>, Name),
els_distribution_server:start_distribution(LocalNode),
?LOG_INFO("Distribution up on: [~p]", [LocalNode]),

els_dap_server:send_event(<<"initialized">>, #{}),

Expand Down
20 changes: 19 additions & 1 deletion apps/els_dap/test/els_dap_general_provider_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-export([
initialize/1,
launch_mfa/1,
launch_mfa_with_cookie/1,
configuration_done/1,
configuration_done_with_breakpoint/1,
frame_variables/1,
Expand Down Expand Up @@ -171,6 +172,19 @@ launch_mfa(Config) ->
els_dap_test_utils:wait_until_mock_called(els_dap_server, send_event),
ok.

-spec launch_mfa_with_cookie(config()) -> ok.
launch_mfa_with_cookie(Config) ->
Provider = ?config(provider, Config),
DataDir = ?config(data_dir, Config),
Node = ?config(node, Config),
els_provider:handle_request(Provider, request_initialize(#{})),
els_provider:handle_request(
Provider,
request_launch(DataDir, Node, <<"some_cookie">>, els_dap_test_module, entry, [])
),
els_dap_test_utils:wait_until_mock_called(els_dap_server, send_event),
ok.

-spec configuration_done(config()) -> ok.
configuration_done(Config) ->
Provider = ?config(provider, Config),
Expand Down Expand Up @@ -231,7 +245,7 @@ frame_variables(Config) ->
Provider,
request_variable(VariableRef)
),
%% at this point there should be only one variable present
%% at this point there should be only one variable present,
?assertMatch(
#{
<<"name">> := <<"N">>,
Expand Down Expand Up @@ -410,6 +424,10 @@ request_launch(AppDir, Node, M, F, A) ->
<<"args">> => unicode:characters_to_binary(io_lib:format("~w", [A]))
}).

request_launch(AppDir, Node, Cookie, M, F, A) ->
{<<"launch">>, Params} = request_launch(AppDir, Node, M, F, A),
{<<"launch">>, Params#{<<"cookie">> => Cookie}}.

request_configuration_done(Params) ->
{<<"configurationDone">>, Params}.

Expand Down

0 comments on commit 16b2474

Please sign in to comment.