<commit_before>package gore

import (
	"bytes"
	"errors"
	"fmt"
	"go/ast"
	"go/build"
	"go/parser"
	"go/printer"
	"go/scanner"
	"go/token"
	"go/types"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"syscall"
	"unicode"

	"golang.org/x/tools/go/packages"
	"golang.org/x/tools/imports"

	"github.com/motemen/go-quickfix"
)

// Session ...
type Session struct {
	tempDir         string
	tempFilePath    string
	file            *ast.File
	fset            *token.FileSet
	types           *types.Config
	typeInfo        types.Info
	extraFilePaths  []string
	extraFiles      []*ast.File
	autoImport      bool
	requiredModules []string
	mainBody        *ast.BlockStmt
	lastStmts       []ast.Stmt
	lastDecls       []ast.Decl
	stdout          io.Writer
	stderr          io.Writer
}

const printerName = "__gore_p"

const initialSourceTemplate = `
package main

import %q

func ` + printerName + `(xs ...interface{}) {
	for _, x := range xs {
		%s
	}
}

func main() {
}
`

// printerPkgs is a list of packages that provides pretty printing function
// when changing this, read listModuleDirectives carefully
var printerPkgs = []struct {
	path, version string
	requires      []pathVersion
	code          string
}{
	{path: "github.com/k0kubun/pp", version: "v3.0.1+incompatible", code: `pp.Println(x)`,
		requires: []pathVersion{{"github.com/mattn/go-colorable", "v0.1.4"}}},
	{path: "fmt", code: `fmt.Printf("%#v\n", x)`},
}

type pathVersion struct {
	path, version string
}

// NewSession creates a new Session.
func NewSession(stdout, stderr io.Writer) (*Session, error) {
	var err error

	s := &Session{stdout: stdout, stderr: stderr}

	s.tempDir, err = ioutil.TempDir("", "gore-")
	if err != nil {
		return s, err
	}
	s.tempFilePath = filepath.Join(s.tempDir, "gore_session.go")

	if err = s.init(); err != nil {
		return s, err
	}

	return s, nil
}

type pkgsImporter struct {
	dir string<commit_msg>update versions of pretty print library<commit_after>package gore

import (
	"bytes"
	"errors"
	"fmt"
	"go/ast"
	"go/build"
	"go/parser"
	"go/printer"
	"go/scanner"
	"go/token"
	"go/types"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"syscall"
	"unicode"

	"golang.org/x/tools/go/packages"
	"golang.org/x/tools/imports"

	"github.com/motemen/go-quickfix"
)

// Session ...
type Session struct {
	tempDir         string
	tempFilePath    string
	file            *ast.File
	fset            *token.FileSet
	types           *types.Config
	typeInfo        types.Info
	extraFilePaths  []string
	extraFiles      []*ast.File
	autoImport      bool
	requiredModules []string
	mainBody        *ast.BlockStmt
	lastStmts       []ast.Stmt
	lastDecls       []ast.Decl
	stdout          io.Writer
	stderr          io.Writer
}

const printerName = "__gore_p"

const initialSourceTemplate = `
package main

import %q

func ` + printerName + `(xs ...interface{}) {
	for _, x := range xs {
		%s
	}
}

func main() {
}
`

// printerPkgs is a list of packages that provides pretty printing function
// when changing this, read listModuleDirectives carefully
var printerPkgs = []struct {
	path, version string
	requires      []pathVersion
	code          string
}{
	{path: "github.com/k0kubun/pp/v3", version: "v3.0.7", code: `pp.Println(x)`,
		requires: []pathVersion{{"github.com/mattn/go-colorable", "v0.1.7"}}},
	{path: "fmt", code: `fmt.Printf("%#v\n", x)`},
}

type pathVersion struct {
	path, version string
}

// NewSession creates a new Session.
func NewSession(stdout, stderr io.Writer) (*Session, error) {
	var err error

	s := &Session{stdout: stdout, stderr: stderr}

	s.tempDir, err = ioutil.TempDir("", "gore-")
	if err != nil {
		return s, err
	}
	s.tempFilePath = filepath.Join(s.tempDir, "gore_session.go")

	if err = s.init(); err != nil {
		return s, err
	}

	return s, nil
}

type pkgsImporter struct {
	dir string
{'fraction_non_alphanumeric': 0.14114583333333333, 'fraction_numerical': 0.00390625, 'mean_word_length': 2.9968782518210197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3972433', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1437, 'n_words': 350}