<commit_before>package query

import "fmt"
import "os"
import "path"
import "strings"

import "core"
import "parse"

// Produces a set of labels that complete a given input.
func QueryCompletionLabels(config core.Configuration, args []string, repoRoot string) []core.BuildLabel {
	if len(args) == 0 {
		queryCompletionPackages(config, ".", repoRoot)
	} else if !strings.Contains(args[0], ":") {
		// Haven't picked a package yet so no parsing is necessary.
		if strings.HasPrefix(args[0], "//") {
			queryCompletionPackages(config, args[0][2:], repoRoot)
		} else {
			queryCompletionPackages(config, args[0], repoRoot)
		}
	}
	if strings.HasSuffix(args[0], ":") {
		args[0] += "all"
	}
	args[0] = strings.Replace(args[0], "\\:", ":", -1)
	labels := core.ParseBuildLabels([]string{args[0]})
	// Return this label without the trailing bit.
	return []core.BuildLabel{core.BuildLabel{PackageName: labels[0].PackageName, Name: "all"}}
}

func queryCompletionPackages(config core.Configuration, query, repoRoot string) {
	root := path.Join(repoRoot, query)
	origRoot := root
	if !core.PathExists(root) {
		root = path.Dir(root)
	}
	packages := []string{}
	for pkg := range parse.FindAllSubpackages(config, root, origRoot) {
		if strings.HasPrefix(pkg, origRoot) {<commit_msg>Add comment<commit_after>package query

import "fmt"
import "os"
import "path"
import "strings"

import "core"
import "parse"

// Produces a set of labels that complete a given input.
func QueryCompletionLabels(config core.Configuration, args []string, repoRoot string) []core.BuildLabel {
	if len(args) == 0 {
		queryCompletionPackages(config, ".", repoRoot)
	} else if !strings.Contains(args[0], ":") {
		// Haven't picked a package yet so no parsing is necessary.
		if strings.HasPrefix(args[0], "//") {
			queryCompletionPackages(config, args[0][2:], repoRoot)
		} else {
			queryCompletionPackages(config, args[0], repoRoot)
		}
	}
	if strings.HasSuffix(args[0], ":") {
		args[0] += "all"
	}
	// Bash completion sometimes produces \: instead of just : (see issue #18).
	// We silently fix that here since we've not yet worked out how to fix Bash itself :(
	args[0] = strings.Replace(args[0], "\\:", ":", -1)
	labels := core.ParseBuildLabels([]string{args[0]})
	// Return this label without the trailing bit.
	return []core.BuildLabel{core.BuildLabel{PackageName: labels[0].PackageName, Name: "all"}}
}

func queryCompletionPackages(config core.Configuration, query, repoRoot string) {
	root := path.Join(repoRoot, query)
	origRoot := root
	if !core.PathExists(root) {
		root = path.Dir(root)
	}
	packages := []string{}
	for pkg := range parse.FindAllSubpackages(config, root, origRoot) {
		if strings.HasPrefix(pkg, origRoot) {
{'fraction_non_alphanumeric': 0.15173945225758698, 'fraction_numerical': 0.010362694300518135, 'mean_word_length': 4.812903225806451, 'pattern_counts': {'":': 6, '<': 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': '2454016', 'n_tokens_mistral': 915, 'n_tokens_neox': 874, 'n_words': 239}