<commit_before>package main

import (
	"io/ioutil"
	"strings"
	"strconv"
	"exec"
	"rpc"
	"flag"
	"time"
	"path"
	"fmt"
	"os"
	"json"
)

var (
	server = flag.Bool("s", false, "run a server instead of a client")
	format = flag.String("f", "nice", "output format (vim | emacs | nice)")
	input  = flag.String("in", "", "use this file instead of stdin input")
)

//-------------------------------------------------------------------------
// Formatter interface
//-------------------------------------------------------------------------

type Formatter interface {
	WriteEmpty()
	WriteCandidates(names, types, classes []string, num int)
	WriteSMap(decldescs []DeclDesc)
	WriteRename(renamedescs []RenameDesc, err string)
}

//-------------------------------------------------------------------------
// NiceFormatter (just for testing, simple textual output)
//-------------------------------------------------------------------------

type NiceFormatter struct{}

func (*NiceFormatter) WriteEmpty() {
	fmt.Printf("Nothing to complete.\n")
}

func (*NiceFormatter) WriteCandidates(names, types, classes []string, num int) {
	fmt.Printf("Found %d candidates:\n", len(names))
	for i := 0; i < len(names); i++ {
		abbr := fmt.Sprintf("%s %s %s", classes[i], names[i], types[i])
		if classes[i] == "func" {
			abbr = fmt.Sprintf("%s %s%s", classes[i], names[i], types[i][len("func"):])
		}
		fmt.Printf("  %s\n", abbr)
	}
}

func (*NiceFormatter) WriteSMap(decldescs []DeclDesc) {
	data, err := json.Marshal(decldescs)
	if err != nil {
		panic(err.String())
	}
	os.Stdout.Write(data)
}

func (*NiceFormatter) WriteRename(renamedescs []RenameDesc, err string) {
	if err != "" {
		panic(err)
	}
	data, error := json.Marshal(renamedescs)
	if error != nil {
		panic(error.String())
	}
	os.Stdout.Write(data)
}

//-------------------------------------------------------------------------
// VimFormatter
//-------------------------------------------------------------------------

type VimFormatter struct{}
<commit_msg>Fix issue with broken 'rename' tests.<commit_after>package main

import (
	"io/ioutil"
	"strings"
	"strconv"
	"exec"
	"rpc"
	"flag"
	"time"
	"path"
	"fmt"
	"os"
	"json"
)

var (
	server = flag.Bool("s", false, "run a server instead of a client")
	format = flag.String("f", "nice", "output format (vim | emacs | nice)")
	input  = flag.String("in", "", "use this file instead of stdin input")
)

//-------------------------------------------------------------------------
// Formatter interface
//-------------------------------------------------------------------------

type Formatter interface {
	WriteEmpty()
	WriteCandidates(names, types, classes []string, num int)
	WriteSMap(decldescs []DeclDesc)
	WriteRename(renamedescs []RenameDesc, err string)
}

//-------------------------------------------------------------------------
// NiceFormatter (just for testing, simple textual output)
//-------------------------------------------------------------------------

type NiceFormatter struct{}

func (*NiceFormatter) WriteEmpty() {
	fmt.Printf("Nothing to complete.\n")
}

func (*NiceFormatter) WriteCandidates(names, types, classes []string, num int) {
	fmt.Printf("Found %d candidates:\n", len(names))
	for i := 0; i < len(names); i++ {
		abbr := fmt.Sprintf("%s %s %s", classes[i], names[i], types[i])
		if classes[i] == "func" {
			abbr = fmt.Sprintf("%s %s%s", classes[i], names[i], types[i][len("func"):])
		}
		fmt.Printf("  %s\n", abbr)
	}
}

func (*NiceFormatter) WriteSMap(decldescs []DeclDesc) {
	data, err := json.Marshal(decldescs)
	if err != nil {
		panic(err.String())
	}
	os.Stdout.Write(data)
}

func (*NiceFormatter) WriteRename(renamedescs []RenameDesc, err string) {
	data, error := json.Marshal(renamedescs)
	if error != nil {
		panic(error.String())
	}
	os.Stdout.Write(data)
}

//-------------------------------------------------------------------------
// VimFormatter
//-------------------------------------------------------------------------

type VimFormatter struct{}

{'fraction_non_alphanumeric': 0.36020968547179233, 'fraction_numerical': 0.0004992511233150275, 'mean_word_length': 1.7295640326975477, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5947120', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1200, 'n_words': 294}