def __init__( self, user_options, server_settings ):
   self._name = server_settings[ 'name' ]
   self._supported_filetypes = server_settings[ 'filetypes' ]
   self._project_root_files = server_settings.get( 'project_root_files', [] )
   super().__init__( user_options )
   self._command_line = server_settings[ 'cmdline' ]
   self._command_line[ 0 ] = utils.FindExecutable( self._command_line[ 0 ] )
示例#2
0
def PathToPythonInterpreter():
    # Not calling the Python interpreter to check its version as it significantly
    # impacts startup time.
    from ycmd import utils

    python_interpreter = vim.eval('g:ycm_server_python_interpreter')
    if python_interpreter:
        python_interpreter = utils.FindExecutable(python_interpreter)
        if python_interpreter:
            return python_interpreter

        raise RuntimeError("Path in 'g:ycm_server_python_interpreter' option "
                           "does not point to a valid Python 3.5+.")

    python_interpreter = _PathToPythonUsedDuringBuild()
    if python_interpreter and utils.GetExecutable(python_interpreter):
        return python_interpreter

    # On UNIX platforms, we use sys.executable as the Python interpreter path.
    # We cannot use sys.executable on Windows because for unknown reasons, it
    # returns the Vim executable. Instead, we use sys.exec_prefix to deduce the
    # interpreter path.
    python_interpreter = (WIN_PYTHON_PATH
                          if utils.OnWindows() else sys.executable)
    if _EndsWithPython(python_interpreter):
        return python_interpreter

    python_interpreter = utils.PathToFirstExistingExecutable(
        ['python3', 'python'])
    if python_interpreter:
        return python_interpreter

    raise RuntimeError("Cannot find Python 3.5+. "
                       "Set the 'g:ycm_server_python_interpreter' option "
                       "to a Python interpreter path.")
示例#3
0
def FindExecutable_RelativePath_test():
    with TemporaryExecutable() as executable:
        dirname, exename = os.path.split(executable)
        relative_executable = os.path.join('.', exename)
        with CurrentWorkingDirectory(dirname):
            assert_that(relative_executable,
                        equal_to(utils.FindExecutable(relative_executable)))
示例#4
0
    def __init__(self, user_options, server_settings):
        self._name = server_settings['name']
        self._supported_filetypes = server_settings['filetypes']
        self._project_root_files = server_settings.get('project_root_files',
                                                       [])
        self._capabilities = server_settings.get('capabilities', {})

        self._command_line = server_settings.get('cmdline')
        self._port = server_settings.get('port')
        if self._port:
            connection_type = 'tcp'
            if self._port == '*':
                self._port = utils.GetUnusedLocalhostPort()
        else:
            connection_type = 'stdio'

        if self._command_line:
            self._command_line[0] = utils.FindExecutable(self._command_line[0])

            for idx in range(len(self._command_line)):
                self._command_line[idx] = string.Template(
                    self._command_line[idx]).safe_substitute(
                        {'port': self._port})

        super().__init__(user_options, connection_type)
示例#5
0
 def __init__(self, user_options):
     super().__init__(user_options)
     if user_options['rust_toolchain_root']:
         self._rust_root = user_options['rust_toolchain_root']
     else:
         self._rust_root = os.path.dirname(os.path.dirname(RA_EXECUTABLE))
     self._ra_path = utils.FindExecutable(
         os.path.join(self._rust_root, 'bin', 'rust-analyzer'))
示例#6
0
 def _UpdatePythonBinary(self, binary):
     if binary:
         resolved_binary = utils.FindExecutable(binary)
         if not resolved_binary:
             msg = BINARY_NOT_FOUND_MESSAGE.format(binary)
             self._logger.error(msg)
             raise RuntimeError(msg)
         self._python_binary_path = resolved_binary
示例#7
0
def ShouldEnableRustCompleter( user_options ):
  if ( 'rls_binary_path' in user_options and
       not user_options[ 'rust_toolchain_root' ] ):
    LOGGER.warning( 'rls_binary_path detected. '
                    'Did you mean rust_toolchain_root?' )

  if user_options[ 'rust_toolchain_root' ]:
    # Listen to what the user wanted to use
    ra = os.path.join( user_options[ 'rust_toolchain_root' ],
                       'bin', 'rust-analyzer' )
    if not utils.FindExecutable( ra ):
      LOGGER.error( 'Not using Rust completer: no rust-analyzer '
                    'executable found at %s', ra )
      return False
    else:
      return True
  else:
    return bool( utils.FindExecutable( RA_EXECUTABLE ) )
def FindTSServer():
  # The TSServer executable is installed at the root directory on Windows while
  # it's installed in the bin folder on other platforms.
  for executable in [ os.path.join( TSSERVER_DIR, 'bin', 'tsserver' ),
                      os.path.join( TSSERVER_DIR, 'tsserver' ),
                      'tsserver' ]:
    tsserver = utils.FindExecutable( executable )
    if tsserver:
      return tsserver
  return None
示例#9
0
def FindTsserverBinary():
    tsserver = utils.FindExecutable('tsserver')
    if not tsserver:
        return None

    if not utils.OnWindows():
        return tsserver

    # On Windows, tsserver is a batch script that calls the tsserver binary with
    # node.
    return os.path.abspath(
        os.path.join(os.path.dirname(tsserver), 'node_modules', 'typescript',
                     'bin', 'tsserver'))
示例#10
0
def FindTSServer( user_options_path ):
  tsserver = utils.FindExecutableWithFallback( user_options_path , None )
  if tsserver and os.path.isfile( tsserver ):
    return tsserver
  # The TSServer executable is installed at the root directory on Windows while
  # it's installed in the bin folder on other platforms.
  for executable in [ os.path.join( TSSERVER_DIR, 'bin', 'tsserver' ),
                      os.path.join( TSSERVER_DIR, 'tsserver' ),
                      'tsserver' ]:
    tsserver = utils.FindExecutable( executable )
    if tsserver:
      return tsserver
  return None
示例#11
0
  def __init__( self, user_options, server_settings ):
    self._name = server_settings[ 'name' ]
    self._supported_filetypes = server_settings[ 'filetypes' ]
    self._project_root_files = server_settings.get( 'project_root_files', [] )
    self._capabilities = server_settings.get( 'capabilities', {} )

    self._command_line = server_settings.get( 'cmdline' )
    self._port = server_settings.get( 'port' )
    if self._port:
      connection_type = 'tcp'
    else:
      connection_type = 'stdio'

    if self._command_line:
      self._command_line[ 0 ] = utils.FindExecutable(
        self._command_line[ 0 ] )

    super().__init__( user_options, connection_type )
示例#12
0
def ShouldEnableJavaCompleter(user_options):
    LOGGER.info('Looking for jdt.ls')

    global PATH_TO_JAVA
    PATH_TO_JAVA = utils.FindExecutableWithFallback(
        user_options['java_binary_path'], utils.FindExecutable('java'))

    if not PATH_TO_JAVA:
        LOGGER.warning("Not enabling java completion: Couldn't find java 11")
        return False

    if not os.path.exists(LANGUAGE_SERVER_HOME):
        LOGGER.warning('Not using java completion: jdt.ls is not installed')
        return False

    if not _PathToLauncherJar():
        LOGGER.warning('Not using java completion: jdt.ls is not built')
        return False

    return True
示例#13
0
def PathToPythonInterpreter():
  # Not calling the Python interpreter to check its version as it significantly
  # impacts startup time.
  from ycmd import utils

  python_interpreter = vim.eval( 'g:ycm_server_python_interpreter' )
  if python_interpreter:
    python_interpreter = utils.FindExecutable( python_interpreter )
    if python_interpreter:
      return python_interpreter

    raise RuntimeError( "Path in 'g:ycm_server_python_interpreter' option "
                        "does not point to a valid Python 2.6+ or 3.3+." )

  python_interpreter = _PathToPythonUsedDuringBuild()
  if python_interpreter and utils.GetExecutable( python_interpreter ):
    return python_interpreter

  # On UNIX platforms, we use sys.executable as the Python interpreter path.
  # We cannot use sys.executable on Windows because for unknown reasons, it
  # returns the Vim executable. Instead, we use sys.exec_prefix to deduce the
  # interpreter path.
  python_interpreter = ( WIN_PYTHON_PATH if utils.OnWindows() else
                         sys.executable )
  if _EndsWithPython( python_interpreter ):
    return python_interpreter

  # As a last resort, we search python in the PATH. We prefer Python 2 over 3
  # for the sake of backwards compatibility with ycm_extra_conf.py files out
  # there; few people wrote theirs to work on py3.
  # So we check 'python2' before 'python' because on some distributions (Arch
  # Linux for example), python refers to python3.
  python_interpreter = utils.PathToFirstExistingExecutable( [ 'python2',
                                                              'python',
                                                              'python3' ] )
  if python_interpreter:
    return python_interpreter

  raise RuntimeError( "Cannot find Python 2.6+ or 3.3+. "
                      "Set the 'g:ycm_server_python_interpreter' option "
                      "to a Python interpreter path." )
示例#14
0
文件: utils_test.py 项目: rust20/ycmd
def FindExecutable_CurrentDirectory_test():
    with TemporaryExecutable() as executable:
        dirname, exename = os.path.split(executable)
        with CurrentWorkingDirectory(dirname):
            eq_(executable, utils.FindExecutable(exename))
示例#15
0
文件: utils_test.py 项目: rust20/ycmd
def FindExecutable_AdditionalPathExt_test():
    with TemporaryExecutable(extension='.xyz') as executable:
        eq_(executable, utils.FindExecutable(executable))
示例#16
0
文件: utils_test.py 项目: rust20/ycmd
def FindExecutable_ExecutableNameInPath_test():
    with TemporaryExecutable() as executable:
        dirname, exename = os.path.split(executable)
        eq_(executable, utils.FindExecutable(exename))
示例#17
0
文件: utils_test.py 项目: rust20/ycmd
def FindExecutable_ReturnNoneIfFileIsNotExecutable_test():
    with tempfile.NamedTemporaryFile() as non_executable:
        eq_(None, utils.FindExecutable(non_executable.name))
示例#18
0
 def test_FindExecutable_AdditionalPathExt(self):
     with TemporaryExecutable(extension='.xyz') as executable:
         assert_that(executable, equal_to(utils.FindExecutable(executable)))
示例#19
0
文件: utils_test.py 项目: rust20/ycmd
def FindExecutable_AbsolutePath_test():
    with TemporaryExecutable() as executable:
        eq_(executable, utils.FindExecutable(executable))
示例#20
0
 def test_FindExecutable_ReturnNoneIfFileIsNotExecutable(self):
     with tempfile.NamedTemporaryFile() as non_executable:
         assert_that(None,
                     equal_to(utils.FindExecutable(non_executable.name)))
示例#21
0
 def test_FindExecutable_CurrentDirectory(self):
     with TemporaryExecutable() as executable:
         dirname, exename = os.path.split(executable)
         with CurrentWorkingDirectory(dirname):
             assert_that(executable,
                         equal_to(utils.FindExecutable(exename)))
示例#22
0
 def test_FindExecutable_AbsolutePath(self):
     with TemporaryExecutable() as executable:
         assert_that(executable, equal_to(utils.FindExecutable(executable)))
示例#23
0
 def test_FindExecutable_ExecutableNameInPath(self):
     with TemporaryExecutable() as executable:
         dirname, exename = os.path.split(executable)
         assert_that(executable, equal_to(utils.FindExecutable(exename)))
示例#24
0
from tempfile import NamedTemporaryFile

from ycmd import responses
from ycmd import utils
from ycmd.completers.completer import Completer
from ycmd.completers.completer_utils import GetFileContents

BINARY_NOT_FOUND_MESSAGE = ('TSServer not found. '
                            'TypeScript 1.5 or higher is required.')
SERVER_NOT_RUNNING_MESSAGE = 'TSServer is not running.'

MAX_DETAILED_COMPLETIONS = 100
RESPONSE_TIMEOUT_SECONDS = 10

PATH_TO_TSSERVER = utils.FindExecutable('tsserver')

_logger = logging.getLogger(__name__)


class DeferredResponse(object):
    """
  A deferred that resolves to a response from TSServer.
  """
    def __init__(self, timeout=RESPONSE_TIMEOUT_SECONDS):
        self._event = threading.Event()
        self._message = None
        self._timeout = timeout

    def resolve(self, message):
        self._message = message
 def __init__( self, user_options, server_settings ):
   self._name = server_settings[ 'name' ]
   self._supported_filetypes = server_settings[ 'filetypes' ]
   super( GenericLSPCompleter, self ).__init__( user_options )
   self._command_line = server_settings[ 'cmdline' ]
   self._command_line[ 0 ] = utils.FindExecutable( self._command_line[ 0 ] )
示例#26
0
# along with ycmd.  If not, see <http://www.gnu.org/licenses/>.

import logging
import os
from subprocess import PIPE

from ycmd import responses, utils
from ycmd.completers.language_server import language_server_completer
from ycmd.utils import LOGGER, re

LOGFILE_FORMAT = 'ra_'
RUST_ROOT = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '..', '..', '..', 'third_party',
                 'rust-analyzer'))
RA_BIN_DIR = os.path.join(RUST_ROOT, 'bin')
RUSTC_EXECUTABLE = utils.FindExecutable(os.path.join(RA_BIN_DIR, 'rustc'))
RA_EXECUTABLE = utils.FindExecutable(os.path.join(RA_BIN_DIR, 'rust-analyzer'))
RA_VERSION_REGEX = re.compile(r'^rust-analyzer (?P<version>.*)$')


def _GetCommandOutput(command):
    return utils.ToUnicode(
        utils.SafePopen(command, stdin_windows=PIPE, stdout=PIPE,
                        stderr=PIPE).communicate()[0].rstrip())


def _GetRAVersion(ra_path):
    ra_version = _GetCommandOutput([ra_path, '--version'])
    match = RA_VERSION_REGEX.match(ra_version)
    if not match:
        LOGGER.error('Cannot parse Rust Language Server version: %s',
示例#27
0
import logging
import os
from future.utils import itervalues
from subprocess import PIPE

from ycmd import responses, utils
from ycmd.completers.language_server import (simple_language_server_completer,
                                             language_server_completer)
from ycmd.utils import LOGGER, re

LOGFILE_FORMAT = 'rls_'
RLS_BIN_DIR = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '..', '..', '..', 'third_party',
                 'rls', 'bin'))
RUSTC_EXECUTABLE = utils.FindExecutable(os.path.join(RLS_BIN_DIR, 'rustc'))
RLS_EXECUTABLE = utils.FindExecutable(os.path.join(RLS_BIN_DIR, 'rls'))
RLS_VERSION_REGEX = re.compile(r'^rls (?P<version>.*)$')


def _GetCommandOutput(command):
    return utils.ToUnicode(
        utils.SafePopen(command, stdin_windows=PIPE, stdout=PIPE,
                        stderr=PIPE).communicate()[0].rstrip())


def _GetRlsVersion():
    rls_version = _GetCommandOutput([RLS_EXECUTABLE, '--version'])
    match = RLS_VERSION_REGEX.match(rls_version)
    if not match:
        LOGGER.error('Cannot parse Rust Language Server version: %s',
示例#28
0
import json
import threading

from subprocess import PIPE
from ycmd import utils, responses
from ycmd.completers.completer import Completer
from ycmd.completers.completer_utils import GetFileLines
from ycmd.utils import LOGGER, ToBytes, ToUnicode

HTTP_OK = 200

PATH_TO_TERN_BINARY = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '..', '..', '..', 'third_party',
                 'tern_runtime', 'node_modules', 'tern', 'bin', 'tern'))

PATH_TO_NODE = utils.FindExecutable('node')

# host name/address on which the tern server should listen
# note: we use 127.0.0.1 rather than localhost because on some platforms
# localhost might not be correctly configured as an alias for the loopback
# address. (ahem: Windows)
SERVER_HOST = '127.0.0.1'

LOGFILE_FORMAT = 'tern_{port}_{std}_'


def ShouldEnableTernCompleter():
    """Returns whether or not the tern completer is 'installed'. That is whether
  or not the tern submodule has a 'node_modules' directory. This is pretty much
  the only way we can know if the user added '--js-completer' on
  install or manually ran 'npm install' in the tern submodule directory."""