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

package server

import (
	"context"
	"os"

	"github.com/neovim/go-client/nvim"
	"github.com/pkg/errors"
	"github.com/zchee/nvim-go/src/logger"
	"go.uber.org/zap"
)

type Server struct {
	Nvim *nvim.Nvim
}

func NewServer(ctx context.Context) (*Server, error) {
	const envNvimListenAddress = "NVIM_LISTEN_ADDRESS"

	addr := os.Getenv(envNvimListenAddress)
	if addr == "" {
		return nil, errors.Errorf("%s not set", envNvimListenAddress)
	}

	zapLogf := func(format string, a ...interface{}) {
		logger.FromContext(ctx).Named("server").Info("", zap.Any(format, a))
	}
	n, err := nvim.Dial(addr, nvim.DialContext(ctx), nvim.DialLogf(zapLogf))
	if err != nil {
		return nil, err
	}

	return &Server{
		Nvim: n,
	}, nil
}

func (s *Server) Close() error {
	return s.Nvim.Close()
}<commit_msg>server: change nvim.Nvim to embeded struct and remove Close method<commit_after>// Copyright 2017 The nvim-go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package server

import (
	"context"
	"os"

	"github.com/neovim/go-client/nvim"
	"github.com/pkg/errors"
	"github.com/zchee/nvim-go/src/logger"
	"go.uber.org/zap"
)

type Server struct {
	*nvim.Nvim
}

func NewServer(ctx context.Context) (*Server, error) {
	const envNvimListenAddress = "NVIM_LISTEN_ADDRESS"

	addr := os.Getenv(envNvimListenAddress)
	if addr == "" {
		return nil, errors.Errorf("%s not set", envNvimListenAddress)
	}

	zapLogf := func(format string, a ...interface{}) {
		logger.FromContext(ctx).Named("server").Info("", zap.Any(format, a))
	}
	n, err := nvim.Dial(addr, nvim.DialContext(ctx), nvim.DialLogf(zapLogf))
	if err != nil {
		return nil, err
	}

	return &Server{
		Nvim: n,
	}, nil
}
{'fraction_non_alphanumeric': 0.14716588663546543, 'fraction_numerical': 0.004160166406656267, 'mean_word_length': 3.9974025974025973, 'pattern_counts': {'":': 0, '<': 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': '618682', 'n_tokens_mistral': 757, 'n_tokens_neox': 720, 'n_words': 183}