<commit_before>package main

import (
	"fmt"
	"bytes"
	"go/parser"
	"go/token"
	"go/ast"
	"io/ioutil"
	"strings"
	"path/filepath"
	"sort"
	"time"
	"runtime"
)

//-------------------------------------------------------------------------
// OutBuffers
//
// Temporary structure for writing autocomplete response.
//-------------------------------------------------------------------------

type OutBuffers struct {
	tmpbuf  *bytes.Buffer
	names   []string
	types   []string
	classes []string
	ctx     *AutoCompleteContext
	tmpns   map[string]bool
}

func NewOutBuffers(ctx *AutoCompleteContext) *OutBuffers {
	b := new(OutBuffers)
	b.tmpbuf = bytes.NewBuffer(make([]byte, 0, 1024))
	b.names = make([]string, 0, 1024)
	b.types = make([]string, 0, 1024)
	b.classes = make([]string, 0, 1024)
	b.ctx = ctx
	return b
}

func (b *OutBuffers) Len() int {
	return len(b.names)
}

func (b *OutBuffers) Less(i, j int) bool {
	if b.classes[i][0] == b.classes[j][0] {
		return b.names[i] < b.names[j]
	}
	return b.classes[i] < b.classes[j]
}

func (b *OutBuffers) Swap(i, j int) {
	b.names[i], b.names[j] = b.names[j], b.names[i]
	b.types[i], b.types[j] = b.types[j], b.types[i]
	b.classes[i], b.classes[j] = b.classes[j], b.classes[i]
}

func (b *OutBuffers) appendDecl(p, name string, decl *Decl, class int) {
	c1 := !Config.ProposeBuiltins && decl.Scope == universeScope
	c2 := class != -1 && !matchClass(int(decl.Class), class)
	c3 := class == -1 && !strings.HasPrefix(name, p)
	c4 := !decl.Matches()
	c5 := !checkTypeExpr(decl.Type)

	if c1 || c2 || c3 || c4 || c5 {
		return
	}

	b.names = append(b.names, name)

	decl.PrettyPrintType(b.tmpbuf)
	b.types = append(b.types, b.tmpbuf.String())
	b.tmpbuf.Reset()

	b.classes = append(b.classes, decl.ClassName())
}

func (b *OutBuffers) appendEmbedded(p string, decl *Decl, class int) {
	if decl.Embedded == nil {
		return
	}

	firstLevel := false
	if b.tmpns == nil {
		// first level, create tmp namespace
		b.tmpns = make(map[string]bool)
		firstLevel = true

		// add all children of the current decl to the namespace
		for _, c := range decl.Children {<commit_msg>Add ugly hack for built-in "error" interface.<commit_after>package main

import (
	"fmt"
	"bytes"
	"go/parser"
	"go/token"
	"go/ast"
	"io/ioutil"
	"strings"
	"path/filepath"
	"sort"
	"time"
	"runtime"
)

//-------------------------------------------------------------------------
// OutBuffers
//
// Temporary structure for writing autocomplete response.
//-------------------------------------------------------------------------

type OutBuffers struct {
	tmpbuf  *bytes.Buffer
	names   []string
	types   []string
	classes []string
	ctx     *AutoCompleteContext
	tmpns   map[string]bool
}

func NewOutBuffers(ctx *AutoCompleteContext) *OutBuffers {
	b := new(OutBuffers)
	b.tmpbuf = bytes.NewBuffer(make([]byte, 0, 1024))
	b.names = make([]string, 0, 1024)
	b.types = make([]string, 0, 1024)
	b.classes = make([]string, 0, 1024)
	b.ctx = ctx
	return b
}

func (b *OutBuffers) Len() int {
	return len(b.names)
}

func (b *OutBuffers) Less(i, j int) bool {
	if b.classes[i][0] == b.classes[j][0] {
		return b.names[i] < b.names[j]
	}
	return b.classes[i] < b.classes[j]
}

func (b *OutBuffers) Swap(i, j int) {
	b.names[i], b.names[j] = b.names[j], b.names[i]
	b.types[i], b.types[j] = b.types[j], b.types[i]
	b.classes[i], b.classes[j] = b.classes[j], b.classes[i]
}

func (b *OutBuffers) appendDecl(p, name string, decl *Decl, class int) {
	c1 := !Config.ProposeBuiltins && decl.Scope == universeScope && decl.Name != "Error"
	c2 := class != -1 && !matchClass(int(decl.Class), class)
	c3 := class == -1 && !strings.HasPrefix(name, p)
	c4 := !decl.Matches()
	c5 := !checkTypeExpr(decl.Type)

	if c1 || c2 || c3 || c4 || c5 {
		return
	}

	b.names = append(b.names, name)

	decl.PrettyPrintType(b.tmpbuf)
	b.types = append(b.types, b.tmpbuf.String())
	b.tmpbuf.Reset()

	b.classes = append(b.classes, decl.ClassName())
}

func (b *OutBuffers) appendEmbedded(p string, decl *Decl, class int) {
	if decl.Embedded == nil {
		return
	}

	firstLevel := false
	if b.tmpns == nil {
		// first level, create tmp namespace
		b.tmpns = make(map[string]bool)
		firstLevel = true

		// add all children of the current decl to the namespace
		for _, c := range decl.Children {
{'fraction_non_alphanumeric': 0.23021077283372365, 'fraction_numerical': 0.01592505854800937, 'mean_word_length': 2.7530755711775043, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4973399', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1600, 'n_words': 388}