<commit_before>// Copyright 2018 ThoughtWorks, Inc.

// This file is part of Gauge.

// Gauge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Gauge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Gauge.  If not, see <http://www.gnu.org/licenses/>.

package lang

import (
	"strings"

	"sync"

	"github.com/getgauge/gauge/util"
	"github.com/sourcegraph/go-langserver/pkg/lsp"
)

type files struct {
	cache map[lsp.DocumentURI][]string
	sync.Mutex
}

func (file *files) add(uri lsp.DocumentURI, text string) {
	file.Lock()
	defer file.Unlock()
	file.cache[uri] = util.GetLinesFromText(text)
}

func (file *files) remove(uri lsp.DocumentURI) {
	file.Lock()
	defer file.Unlock()
	delete(file.cache, uri)
}

func (file *files) line(uri lsp.DocumentURI, lineNo int) string {
	file.Lock()
	defer file.Unlock()
	if len(file.cache[uri]) <= lineNo {
		return ""
	}
	return file.cache[uri][lineNo]
}

func (file *files) content(uri lsp.DocumentURI) []string {
	file.Lock()
	defer file.Unlock()
	return file.cache[uri]
}

func (file *files) contentRange(uri lsp.DocumentURI, start, end int) []string {
	file.Lock()
	defer file.Unlock()
	return file.cache[uri][start-1 : end]
}

func (file *files) exists(uri lsp.DocumentURI) bool {
	file.Lock()
	defer file.Unlock()
	_, ok := file.cache[uri]
	return ok<commit_msg>Using existing function to get line count, #994<commit_after>// Copyright 2018 ThoughtWorks, Inc.

// This file is part of Gauge.

// Gauge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Gauge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Gauge.  If not, see <http://www.gnu.org/licenses/>.

package lang

import (
	"strings"

	"sync"

	"github.com/getgauge/gauge/util"
	"github.com/sourcegraph/go-langserver/pkg/lsp"
)

type files struct {
	cache map[lsp.DocumentURI][]string
	sync.Mutex
}

func (file *files) add(uri lsp.DocumentURI, text string) {
	file.Lock()
	defer file.Unlock()
	file.cache[uri] = util.GetLinesFromText(text)
}

func (file *files) remove(uri lsp.DocumentURI) {
	file.Lock()
	defer file.Unlock()
	delete(file.cache, uri)
}

func (file *files) line(uri lsp.DocumentURI, lineNo int) string {
	if !file.exists(uri) || (getLineCount(uri) <= lineNo) {
		return ""
	}
	file.Lock()
	defer file.Unlock()
	return file.cache[uri][lineNo]
}

func (file *files) content(uri lsp.DocumentURI) []string {
	file.Lock()
	defer file.Unlock()
	return file.cache[uri]
}

func (file *files) contentRange(uri lsp.DocumentURI, start, end int) []string {
	file.Lock()
	defer file.Unlock()
	return file.cache[uri][start-1 : end]
}

func (file *files) exists(uri lsp.DocumentURI) bool {
	file.Lock()
	defer file.Unlock()
	_, ok := file.cache[uri]
	return ok
{'fraction_non_alphanumeric': 0.12227196418578623, 'fraction_numerical': 0.004196978175713486, 'mean_word_length': 3.979108635097493, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5347631', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1161, 'n_words': 403}