From 2bf013e4d55b85f922e6c034464f4a71268c5966 Mon Sep 17 00:00:00 2001 From: Roberto Aloi Date: Fri, 18 Oct 2024 16:17:09 +0200 Subject: [PATCH 1/3] Add optional StripSourcePrefix option to launch config --- src/els_dap_general_provider.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/els_dap_general_provider.erl b/src/els_dap_general_provider.erl index 90ada7f..2099f69 100644 --- a/src/els_dap_general_provider.erl +++ b/src/els_dap_general_provider.erl @@ -89,7 +89,9 @@ handle_request({<<"initialize">>, _Params}, State) -> Capabilities = capabilities(), ok = els_dap_config:initialize(RootUri, Capabilities, InitOptions), {Capabilities, State}; -handle_request({<<"launch">>, #{<<"cwd">> := Cwd} = Params}, State) -> +handle_request({<<"launch">>, #{<<"cwd">> := Cwd0} = Params}, State) -> + StripSourcePrefix = maps:get(<<"stripSourcePrefix">>, Params, <<>>), + Cwd = strip_suffix(Cwd0, StripSourcePrefix), case start_distribution(Params) of {ok, #{ <<"projectnode">> := ProjectNode, @@ -103,7 +105,7 @@ handle_request({<<"launch">>, #{<<"cwd">> := Cwd} = Params}, State) -> #{ <<"kind">> => <<"integrated">>, <<"title">> => ProjectNode, - <<"cwd">> => Cwd, + <<"cwd">> => Cwd0, <<"args">> => Cmd }, ?LOG_INFO("Sending runinterminal request: [~p]", [ParamsR]), @@ -1145,3 +1147,7 @@ force_delete_breakpoints(ProjectNode, Module, Breakpoints) -> _ -> ok end. + +-spec strip_suffix(binary(), binary()) -> binary(). +strip_suffix(Path, Suffix) -> + binary:part(Path, 0, byte_size(Path) - binary:longest_common_suffix([Path, Suffix])). From 8038cc8cb0b9f32a2cd1a44b862ef8da002cf482 Mon Sep 17 00:00:00 2001 From: Roberto Aloi Date: Fri, 18 Oct 2024 16:22:46 +0200 Subject: [PATCH 2/3] Bump upload-artifact version --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51c5194..1e9010f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: - name: Escriptize Debugger run: rebar3 escriptize - name: Store Debugger Escript - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: els_dap path: _build/default/bin/els_dap @@ -53,7 +53,7 @@ jobs: - name: Run CT Tests run: rebar3 ct - name: Store CT Logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ct-logs path: _build/test/logs @@ -65,7 +65,7 @@ jobs: run: rebar3 edoc if: ${{ matrix.otp-version == '24' }} - name: Publish Documentation - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: edoc path: | @@ -90,7 +90,7 @@ jobs: - name: Run CT Tests run: rebar3 ct - name: Store CT Logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ct-logs path: _build/test/logs From 3601e0c2e7a3b17b21b5d2a7645ce40f97f0903b Mon Sep 17 00:00:00 2001 From: Roberto Aloi Date: Fri, 18 Oct 2024 17:57:18 +0200 Subject: [PATCH 3/3] Only strip suffix in case of a match --- src/els_dap_general_provider.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/els_dap_general_provider.erl b/src/els_dap_general_provider.erl index 2099f69..4be73bf 100644 --- a/src/els_dap_general_provider.erl +++ b/src/els_dap_general_provider.erl @@ -1150,4 +1150,9 @@ force_delete_breakpoints(ProjectNode, Module, Breakpoints) -> -spec strip_suffix(binary(), binary()) -> binary(). strip_suffix(Path, Suffix) -> - binary:part(Path, 0, byte_size(Path) - binary:longest_common_suffix([Path, Suffix])). + SuffixSize = byte_size(Suffix), + PathSize = byte_size(Path), + case binary:part(Path, {PathSize, -SuffixSize}) of + Suffix -> binary:part(Path, {0, PathSize - SuffixSize}); + _ -> Path + end.