class RubyLsp::Requests::CodeActionResolve
def switch_block_body(body, indentation)
def switch_block_body(body, indentation) # Check if there are any nested blocks inside of the current block body_loc = body.location nested_block = @document.locate_first_within_range( { start: { line: body_loc.start_line - 1, character: body_loc.start_column }, end: { line: body_loc.end_line - 1, character: body_loc.end_column }, }, node_types: [Prism::BlockNode], ) body_content = body.slice.dup # If there are nested blocks, then we change their style too and we have to mutate the string using the # relative position in respect to the beginning of the body if nested_block.is_a?(Prism::BlockNode) location = nested_block.location correction_start = location.start_offset - body_loc.start_offset correction_end = location.end_offset - body_loc.start_offset next_indentation = indentation ? "#{indentation} " : nil body_content[correction_start...correction_end] = recursively_switch_nested_block_styles(nested_block, next_indentation) end indentation ? body_content.gsub(";", "\n") : "#{body_content.gsub("\n", ";")} " end