
import json
import os.path
import re

from completor import Completor
from completor.compat import to_unicode

dirname = os.path.dirname(__file__)


class Tern(Completor):
    filetype = 'javascript'
    daemon = True
    ident = re.compile(r"""(\w+)|(('|").+)""", re.U)
    trigger = r"""\w+$|[\w\)\]\}\'\"]+\.\w*$|('|").*$"""

    def format_cmd(self):
        binary = self.get_option('node_binary') or 'node'
        tern_config = self.find_config_file('.tern-project')
        cmd = [binary, os.path.join(dirname, 'tern_wrapper.js')]
        if tern_config:
            cmd.append(os.path.dirname(tern_config))
        return cmd

    def parse(self, data):
        try:
            data = to_unicode(data[0], 'utf-8')
            return [i for i in json.loads(data)
                    if not self.input_data.endswith(i['word'])]
        except Exception:
            return []


import json
import os.path
import re

from completor import Completor
from completor.compat import to_unicode

dirname = os.path.dirname(__file__)


class Tern(Completor):
    filetype = 'javascript'
    daemon = True
    ident = re.compile(r"""(\w+)|(["'][^"']*)""", re.U)
    trigger = r"""\w+$|[\w\)\]\}\'\"]+\.\w*$|["']\w*$"""

    def format_cmd(self):
        binary = self.get_option('node_binary') or 'node'
        tern_config = self.find_config_file('.tern-project')
        cmd = [binary, os.path.join(dirname, 'tern_wrapper.js')]
        if tern_config:
            cmd.append(os.path.dirname(tern_config))
        return cmd

    def parse(self, data):
        try:
            data = to_unicode(data[0], 'utf-8')
            return [i for i in json.loads(data)
                    if not self.input_data.endswith(i['word'])]
        except Exception:
            return []

Fix regex for tern complete_strings plugin
Fix regex for tern complete_strings plugin

  
  import json
  import os.path
  import re
  
  from completor import Completor
  from completor.compat import to_unicode
  
  dirname = os.path.dirname(__file__)
  
  
  class Tern(Completor):
      filetype = 'javascript'
      daemon = True
-     ident = re.compile(r"""(\w+)|(('|").+)""", re.U)
+     ident = re.compile(r"""(\w+)|(["'][^"']*)""", re.U)
-     trigger = r"""\w+$|[\w\)\]\}\'\"]+\.\w*$|('|").*$"""
+     trigger = r"""\w+$|[\w\)\]\}\'\"]+\.\w*$|["']\w*$"""
  
      def format_cmd(self):
          binary = self.get_option('node_binary') or 'node'
          tern_config = self.find_config_file('.tern-project')
          cmd = [binary, os.path.join(dirname, 'tern_wrapper.js')]
          if tern_config:
              cmd.append(os.path.dirname(tern_config))
          return cmd
  
      def parse(self, data):
          try:
              data = to_unicode(data[0], 'utf-8')
              return [i for i in json.loads(data)
                      if not self.input_data.endswith(i['word'])]
          except Exception:
              return []
  
Fix regex for tern complete_strings plugin
## Code Before:

import json
import os.path
import re

from completor import Completor
from completor.compat import to_unicode

dirname = os.path.dirname(__file__)


class Tern(Completor):
    filetype = 'javascript'
    daemon = True
    ident = re.compile(r"""(\w+)|(('|").+)""", re.U)
    trigger = r"""\w+$|[\w\)\]\}\'\"]+\.\w*$|('|").*$"""

    def format_cmd(self):
        binary = self.get_option('node_binary') or 'node'
        tern_config = self.find_config_file('.tern-project')
        cmd = [binary, os.path.join(dirname, 'tern_wrapper.js')]
        if tern_config:
            cmd.append(os.path.dirname(tern_config))
        return cmd

    def parse(self, data):
        try:
            data = to_unicode(data[0], 'utf-8')
            return [i for i in json.loads(data)
                    if not self.input_data.endswith(i['word'])]
        except Exception:
            return []

## Instruction:
Fix regex for tern complete_strings plugin
## Code After:

import json
import os.path
import re

from completor import Completor
from completor.compat import to_unicode

dirname = os.path.dirname(__file__)


class Tern(Completor):
    filetype = 'javascript'
    daemon = True
    ident = re.compile(r"""(\w+)|(["'][^"']*)""", re.U)
    trigger = r"""\w+$|[\w\)\]\}\'\"]+\.\w*$|["']\w*$"""

    def format_cmd(self):
        binary = self.get_option('node_binary') or 'node'
        tern_config = self.find_config_file('.tern-project')
        cmd = [binary, os.path.join(dirname, 'tern_wrapper.js')]
        if tern_config:
            cmd.append(os.path.dirname(tern_config))
        return cmd

    def parse(self, data):
        try:
            data = to_unicode(data[0], 'utf-8')
            return [i for i in json.loads(data)
                    if not self.input_data.endswith(i['word'])]
        except Exception:
            return []
