# typed: true
# selective-apply-code-action: refactor.extract
# enable-experimental-lsp-extract-to-variable: true

def while_1(x)
  while T.unsafe(nil)
    x + 1
#   ^^^^^ apply-code-action: [A] Extract Variable (this occurrence only)
#   ^^^^^ apply-code-action: [B] Extract Variable (all 2 occurrences)
    x + 1
  end
end

def while_2(x)
  puts "a dummy line"
  x + 1
  while T.unsafe(nil)
    x + 1
#   ^^^^^ apply-code-action: [C] Extract Variable (this occurrence only)
#   ^^^^^ apply-code-action: [D] Extract Variable (all 3 occurrences)
    x + 1
  end
end

def while_3(x)
  while x + 1
    x + 1
#   ^^^^^ apply-code-action: [E] Extract Variable (this occurrence only)
#   ^^^^^ apply-code-action: [F] Extract Variable (all 3 occurrences)
    x + 1
  end
end

def while_4(x)
  while x + x
#       ^ apply-code-action: [G] Extract Variable (this occurrence only)
#       ^ apply-code-action: [H] Extract Variable (all 2 occurrences)
    1 + 1
#       ^ apply-code-action: [I] Extract Variable (this occurrence only)
#       ^ apply-code-action: [J] Extract Variable (all 2 occurrences)
  end
end

def while_5(x)
  while T.unsafe(1)
    while x + x
#         ^ apply-code-action: [K] Extract Variable (this occurrence only)
#         ^ apply-code-action: [L] Extract Variable (all 2 occurrences)
      1
    end
  end
end
