Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

LS: desugar the hovered one call in the `Convert to function call` code action

author
Andrey
committer
Louis Pilfold
date (Jun 22, 2026, 2:53 PM +0100) commit da72ce44 parent 8a38532a change-id wlvvnzsv
+45 -16
+38 -9
language-server/src/code_action.rs
··· 7833 7833 ) { 7834 7834 let pipeline_range = self.edits.src_span_to_lsp_range(*location); 7835 7835 if within(self.params.range, pipeline_range) { 7836 - // We will always desugar the pipeline's first step. If there's no 7837 - // intermediate assignment it means we're dealing with a single step 7838 - // pipeline and the call is `finally`. 7839 - let (call, call_kind) = assignments 7840 - .first() 7836 + // Add final assignment to the list 7837 + let all_assignments = assignments 7838 + .iter() 7841 7839 .map(|(call, kind)| (call.location, *kind)) 7842 - .unwrap_or_else(|| (finally.location(), *finally_kind)); 7840 + .chain(iter::once((finally.location(), *finally_kind))); 7841 + let mut call_information = None; 7842 + // Span, containing content that will be extracted as call argument 7843 + let mut accumulated_span = first_value.location; 7844 + 7845 + for (current_location, current_kind) in all_assignments { 7846 + if within( 7847 + self.params.range, 7848 + self.edits.src_span_to_lsp_range(current_location), 7849 + ) { 7850 + call_information = Some((accumulated_span, current_location, current_kind)); 7851 + break; 7852 + } 7853 + accumulated_span = accumulated_span.merge(&current_location); 7854 + } 7855 + 7856 + let (final_prev, final_call, final_kind) = match call_information { 7857 + Some(triple) => triple, 7858 + 7859 + // Here two situations are possible: 7860 + // - If the cursor is not on any of the assignments (for example, it is on first value), then we need 7861 + // to use that first value as accumulated location, and the first call location and kind 7862 + // - If there are no assignments, then we are dealing with a single 7863 + // step pipeline and the call is `finally` 7864 + None => { 7865 + let (call, call_kind) = &assignments 7866 + .first() 7867 + .map(|(call, call_kind)| (call.location, *call_kind)) 7868 + .unwrap_or_else(|| (finally.location(), *finally_kind)); 7869 + (first_value.location, *call, *call_kind) 7870 + } 7871 + }; 7843 7872 7844 7873 self.locations = Some(ConvertToFunctionCallLocations { 7845 - first_value: first_value.location, 7846 - call, 7847 - call_kind, 7874 + first_value: final_prev, 7875 + call: final_call, 7876 + call_kind: final_kind, 7848 7877 }); 7849 7878 7850 7879 ast::visit::visit_typed_expr_pipeline(
+3 -3
language-server/src/tests/snapshots/gleam_language_server__tests__action__convert_to_function_call_on_last_step.snap
··· 14 14 15 15 ----- AFTER ACTION 16 16 fn go() { 17 - echo [1, 2, 3] 18 - |> wibble 19 - |> wobble 17 + wobble([1, 2, 3] 18 + |> echo 19 + |> wibble) 20 20 }
+1 -1
language-server/src/tests/snapshots/gleam_language_server__tests__action__convert_to_function_call_on_last_step_single_line.snap
··· 11 11 12 12 ----- AFTER ACTION 13 13 fn go() { 14 - echo [1, 2, 3] |> wibble |> wobble 14 + wobble([1, 2, 3] |> echo |> wibble) 15 15 }
+2 -2
language-server/src/tests/snapshots/gleam_language_server__tests__action__convert_to_function_call_on_second_step.snap
··· 14 14 15 15 ----- AFTER ACTION 16 16 fn go() { 17 - echo [1, 2, 3] 18 - |> wibble 17 + wibble([1, 2, 3] 18 + |> echo) 19 19 |> wobble 20 20 }
+1 -1
language-server/src/tests/snapshots/gleam_language_server__tests__action__convert_to_function_call_on_second_step_single_line.snap
··· 11 11 12 12 ----- AFTER ACTION 13 13 fn go() { 14 - echo [1, 2, 3] |> wibble |> wobble 14 + wibble([1, 2, 3] |> echo) |> wobble 15 15 }