<commit_before>// Copyright 2016 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package commands

import (
	"time"

	"nvim-go/config"
	"nvim-go/nvim/profile"
	"nvim-go/nvim/terminal"

	"github.com/garyburd/neovim-go/vim"
	"github.com/garyburd/neovim-go/vim/plugin"
)

func init() {
	plugin.HandleCommand("Gorun",
		&plugin.CommandOptions{NArgs: "*", Eval: "expand('%:p')"},
		cmdRun)
}

// Run runs the go run command for current buffer's packages.
func Run(v *vim.Vim, cmd []string) error {
	defer profile.Start(time.Now(), "GoRun")
	term := terminal.NewTerminal(v, "__GO_RUN__", cmd, config.TerminalMode)

	if err := term.Run(cmd); err != nil {
		return err
	}

	return nil
}

func cmdRun(v *vim.Vim, args []string, file string) {
	cmd := []string{"go", "run", file}
	if len(args) != 0 {
		cmd = append(cmd, args...)
	}

	go Run(v, cmd)
}
<commit_msg>cmds/run: Fix open the new buffer bug<commit_after>// Copyright 2016 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package commands

import (
	"path/filepath"
	"time"

	"nvim-go/config"
	"nvim-go/nvim/profile"
	"nvim-go/nvim/terminal"
	"nvim-go/pathutil"

	"github.com/garyburd/neovim-go/vim"
	"github.com/garyburd/neovim-go/vim/plugin"
)

var runTerm *terminal.Terminal

func init() {
	plugin.HandleCommand("Gorun",
		&plugin.CommandOptions{NArgs: "*", Eval: "expand('%:p')"},
		cmdRun)
}

// Run runs the go run command for current buffer's packages.
func Run(v *vim.Vim, cmd []string, file string) error {
	defer profile.Start(time.Now(), "GoRun")

	if runTerm == nil {
		runTerm = terminal.NewTerminal(v, "__GO_TEST__", cmd, config.TerminalMode)
	}
	dir, _ := filepath.Split(file)
	rootDir := pathutil.FindVcsRoot(dir)
	runTerm.Dir = rootDir

	if err := runTerm.Run(cmd); err != nil {
		return err
	}

	return nil
}

func cmdRun(v *vim.Vim, args []string, file string) {
	cmd := []string{"go", "run", file}
	if len(args) != 0 {
		cmd = append(cmd, args...)
	}

	go Run(v, cmd, file)
}

{'fraction_non_alphanumeric': 0.16296646197449222, 'fraction_numerical': 0.004723665564478035, 'mean_word_length': 3.8246013667425967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1851949', 'n_tokens_mistral': 848, 'n_tokens_neox': 804, 'n_words': 213}