<commit_before>import os
import re
import sys

current_dir = os.path.dirname(os.path.abspath(__file__))
jedi_dir = os.path.join(os.path.dirname(current_dir), 'jedi')
sys.path.insert(0, jedi_dir)
import jedi

from .base import Base


class Source(Base):

    def __init__(self, vim):
        Base.__init__(self, vim)

        self.name = 'jedi'
        self.mark = '[jedi]'
        self.rank = 500
        self.filetypes = ['python']
        self.input_pattern = (r'[^. \t0-9]\.\w*$|'
                              r'^\s*@\w*$|'
                              r'^\s*from\s.+import \w*|'
                              r'^\s*from \w*|'
                              r'^\s*import \w*')

    def get_complete_position(self, context):
        m = re.search(r'\w*$', context['input'])
        return m.start() if m else -1

    def gather_candidates(self, context):
        buf = self.vim.current.buffer
        source = '\n'.join(buf)

        try:
            completions = self.get_script(
                source, context['complete_position'], buf).completions()
        except Exception:
            return []

        is_import = re.match(r'^\s*from\s.+import \w*|'
                             r'^\s*from \w*|'
                             r'^\s*import \w*',
                             self.vim.current.line)

        out = []
        for c in completions:
            word = c.name

            # TODO(zchee): configurable and refactoring
            # Add '(' bracket
            if not is_import and c.type == 'function':<commit_msg>Add debug and fix import code block<commit_after>import os
import re
import sys

from deoplete.sources.base import Base

current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, current_dir)
from helper import get_var
from helper import load_external_module
from helper import set_debug

load_external_module('jedi')
import jedi

from logging import getLogger
logger = getLogger(__name__)


class Source(Base):

    def __init__(self, vim):
        Base.__init__(self, vim)

        self.name = 'jedi'
        self.mark = '[jedi]'
        self.rank = 500
        self.filetypes = ['python']
        self.input_pattern = (r'[^. \t0-9]\.\w*$|'
                              r'^\s*@\w*$|'
                              r'^\s*from\s.+import \w*|'
                              r'^\s*from \w*|'
                              r'^\s*import \w*')

        if get_var(self.vim, 'deoplete#enable_debug'):
            log_file = get_var(
                self.vim, 'deoplete#sources#jedi#debug#log_file')
            set_debug(logger, os.path.expanduser(log_file))

    def get_complete_position(self, context):
        m = re.search(r'\w*$', context['input'])
        return m.start() if m else -1

    def gather_candidates(self, context):
        buf = self.vim.current.buffer
        source = '\n'.join(buf)

        try:
            completions = self.get_script(
                source, context['complete_position'], buf).completions()
        except Exception:
            return []

        is_import = re.match(r'^\s*from\s.+import \w*|'
                             r'^\s*from \w*|'
                             r'^\s*import \w*',
                             self.vim.current.line)

        out = []
        for c in completions:
            word = c.name

            # TODO(zchee): configurable and refactoring
            # Add '(' bracket
            if not is_import and c.type == 'function':
{'fraction_non_alphanumeric': 0.13445378151260504, 'fraction_numerical': 0.004056795131845842, 'mean_word_length': 1.6250950570342206, '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': '819552', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1058, 'n_words': 228}