
-- a.go --
package a

import (
	"fmt"
	"encoding/json"
)

func F() error {
	a, err := json.Marshal(0) //@codeaction("a", "refactor.extract.function", end=endF, result=F)
	if err != nil {
		return fmt.Errorf("1: %w", err)
	}
	b, err := json.Marshal(0)
	if err != nil {
		return fmt.Errorf("2: %w", err)
	} //@loc(endF, "}")
	fmt.Printf("%s %s", a, b)
	return nil
}

-- @F/a.go --
package a

import (
	"fmt"
	"encoding/json"
)

func F() error {
	a, b, err := newFunction()
	if err != nil {
		return err
	} //@loc(endF, "}")
	fmt.Printf("%s %s", a, b)
	return nil
}

func newFunction() ([]byte, []byte, error) {
	a, err := json.Marshal(0) //@codeaction("a", "refactor.extract.function", end=endF, result=F)
	if err != nil {
		return nil, nil, fmt.Errorf("1: %w", err)
	}
	b, err := json.Marshal(0)
	if err != nil {
		return nil, nil, fmt.Errorf("2: %w", err)
	}
	return a, b, nil
}

-- b.go --
package a

import (
	"fmt"
	"math/rand"
)

func G() (x, y int) {
	v := rand.Int() //@codeaction("v", "refactor.extract.function", end=endG, result=G)
	if v < 0 {
		return 1, 2
	}
	if v > 0 {
		return 3, 4
	} //@loc(endG, "}")
	fmt.Println(v)
	return 5, 6
}
-- @G/b.go --
package a

import (
	"fmt"
	"math/rand"
)

func G() (x, y int) {
	v, x1, y1, shouldReturn := newFunction()
	if shouldReturn {
		return x1, y1
	} //@loc(endG, "}")
	fmt.Println(v)
	return 5, 6
}

func newFunction() (int, int, int, bool) {
	v := rand.Int() //@codeaction("v", "refactor.extract.function", end=endG, result=G)
	if v < 0 {
		return 0, true, 1, 2
	}
	if v > 0 {
		return 0, true, 3, 4
	}
	return v, 0, 0, false
}
