<commit_before>// Copyright 2016 Palantir Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package idea

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"text/template"

	"github.com/pkg/errors"
)

const (
	defaultGoSDK       = "Go"
	imlTemplateContent = `<?xml version="1.0" encoding="UTF-8"?>
<module type="GO_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="jdk" jdkName="{{.GoSDK}}" jdkType="Go SDK" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>
`
	iprTemplateContent = `<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/{{.ProjectName}}.iml" filepath="$PROJECT_DIR$/{{.ProjectName}}.iml" />
    </modules>
  </component>
  <component name="ProjectRootManager" version="2" default="false" assert-keyword="false" jdk-15="false" project-jdk-name="{{.GoSDK}}" project-jdk-type="Go SDK" />
  <component name="ProjectTasksOptions">
    <TaskOptions isEnabled="true">
      <option name="arguments" value="format runAll $FilePathRelativeToProjectRoot$" />
      <option name="checkSyntaxErrors" value="true" />
      <option name="description" value="" />
      <option name="exitCodeBehavior" value="ERROR" />
      <option name="fileExtension" value="go" />
      <option name="immediateSync" value="false" />
      <option name="name" value="godel" />
      <option name="output" value="" />
      <option name="outputFilters">
        <array />
      </option>
      <option name="outputFromStdout" value="false" />
      <option name="program" value="$ProjectFileDir$/godelw" />
      <option name="scopeName" value="Changed Files" />
      <option name="trackOnlyRoot" value="false" />
      <option name="workingDir" value="$ProjectFileDir$" />
      <envs />
    </TaskOptions>
  </component>
</project>
`
)

func CreateIdeaFiles(rootDir string) error {
	projectName := path.Base(rootDir)

	buffer := bytes.Buffer{}
	templateValues := map[string]string{
		"GoSDK":       defaultGoSDK,
		"ProjectName": projectName,<commit_msg>Fix program argument for FileWatchers plugin (#47)<commit_after>// Copyright 2016 Palantir Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package idea

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"path"
	"text/template"

	"github.com/pkg/errors"
)

const (
	defaultGoSDK       = "Go"
	imlTemplateContent = `<?xml version="1.0" encoding="UTF-8"?>
<module type="GO_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="jdk" jdkName="{{.GoSDK}}" jdkType="Go SDK" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>
`
	iprTemplateContent = `<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/{{.ProjectName}}.iml" filepath="$PROJECT_DIR$/{{.ProjectName}}.iml" />
    </modules>
  </component>
  <component name="ProjectRootManager" version="2" default="false" assert-keyword="false" jdk-15="false" project-jdk-name="{{.GoSDK}}" project-jdk-type="Go SDK" />
  <component name="ProjectTasksOptions">
    <TaskOptions isEnabled="true">
      <option name="arguments" value="format runAll $FilePathRelativeToProjectRoot$" />
      <option name="checkSyntaxErrors" value="true" />
      <option name="description" value="" />
      <option name="exitCodeBehavior" value="ERROR" />
      <option name="fileExtension" value="go" />
      <option name="immediateSync" value="false" />
      <option name="name" value="godel" />
      <option name="output" value="" />
      <option name="outputFilters">
        <array />
      </option>
      <option name="outputFromStdout" value="false" />
      <option name="program" value="$PROJECT_DIR$/godelw" />
      <option name="scopeName" value="Changed Files" />
      <option name="trackOnlyRoot" value="false" />
      <option name="workingDir" value="$ProjectFileDir$" />
      <envs />
    </TaskOptions>
  </component>
</project>
`
)

func CreateIdeaFiles(rootDir string) error {
	projectName := path.Base(rootDir)

	buffer := bytes.Buffer{}
	templateValues := map[string]string{
		"GoSDK":       defaultGoSDK,
		"ProjectName": projectName,
{'fraction_non_alphanumeric': 0.16045586107091173, 'fraction_numerical': 0.00723589001447178, 'mean_word_length': 3.9765976597659765, 'pattern_counts': {'":': 4, '<': 81, '<?xml version=': 4, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '458265', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1664, 'n_words': 427}