Example #1
0
  def __init__( self, user_options ):
    super( FilenameCompleter, self ).__init__( user_options )

    # On Windows, backslashes are also valid path separators.
    self._triggers = [ '/', '\\' ] if OnWindows() else [ '/' ]

    self._path_regex = re.compile( """
      # Head part
      (?:
        # 'D:/'-like token
        [A-z]+:[%(sep)s]|

        # '/', './', '../', or '~'
        \.{0,2}[%(sep)s]|~|

        # '$var/'
        \$[A-Za-z0-9{}_]+[%(sep)s]
      )+

      # Tail part
      (?:
        # any alphanumeric, symbol or space literal
        [ %(sep)sa-zA-Z0-9(){}$+_~.\x80-\xff-\[\]]|

        # skip any special symbols
        [^\x20-\x7E]|

        # backslash and 1 char after it
        \\.
      )*$
      """ % { 'sep': '/\\\\' if OnWindows() else '/' }, re.X )
Example #2
0
def PrepareFlagsForClang( flags,
                          filename,
                          add_extra_clang_flags = True,
                          enable_windows_style_flags = False ):
  flags = _AddLanguageFlagWhenAppropriate( flags, enable_windows_style_flags )
  flags = _RemoveXclangFlags( flags )
  flags = RemoveUnusedFlags( flags, filename, enable_windows_style_flags )
  if add_extra_clang_flags:
    # This flag tells libclang where to find the builtin includes.
    flags.append( '-resource-dir=' + CLANG_RESOURCE_DIR )
    # On Windows, parsing of templates is delayed until instantiation time.
    # This makes GetType and GetParent commands fail to return the expected
    # result when the cursor is in a template.
    # Using the -fno-delayed-template-parsing flag disables this behavior. See
    # http://clang.llvm.org/extra/PassByValueTransform.html#note-about-delayed-template-parsing # noqa
    # for an explanation of the flag and
    # https://code.google.com/p/include-what-you-use/source/detail?r=566
    # for a similar issue.
    if OnWindows():
      flags.append( '-fno-delayed-template-parsing' )
    if OnMac():
      flags = AddMacIncludePaths( flags )
    flags = _EnableTypoCorrection( flags )

  vector = ycm_core.StringVector()
  for flag in flags:
    vector.append( flag )
  return vector
Example #3
0
def _ShouldAllowWinStyleFlags( flags ):
  enable_windows_style_flags = False
  if OnWindows():
    for flag in flags:
      if flag.startswith( '--driver-mode' ):
        enable_windows_style_flags = ( flag == '--driver-mode=cl' )

  return enable_windows_style_flags
Example #4
0
def ComparePaths(path1, path2):
    # Assume that the file system is case-insensitive on Windows and macOS and
    # case-sensitive on other platforms. While this is not necessarily true, being
    # completely correct here is not worth the trouble as this assumption
    # represents the overwhelming use case and detecting the case sensitivity of a
    # file system is tricky.
    if OnWindows() or OnMac():
        return path1.lower() == path2.lower()
    return path1 == path2
Example #5
0
def ShouldAllowWinStyleFlags( flags ):
  if OnWindows():
    # Iterate in reverse because we only care
    # about the last occurrence of --driver-mode flag.
    for flag in reversed( flags ):
      if flag.startswith( '--driver-mode' ):
        return flag == '--driver-mode=cl'
    # If there was no --driver-mode flag,
    # check if we are using a compiler like clang-cl.
    return bool( CL_COMPILER_REGEX.search( flags[ 0 ] ) )

  return False
Example #6
0
    def __init__(self, user_options):
        super(FilenameCompleter, self).__init__(user_options)

        if OnWindows():
            self._path_separators = r'/\\'
            self._head_path_pattern = HEAD_PATH_PATTERN_WINDOWS
        else:
            self._path_separators = '/'
            self._head_path_pattern = HEAD_PATH_PATTERN_UNIX
        self._path_separators_regex = re.compile(
            PATH_SEPARATORS_PATTERN.format(seps=self._path_separators))
        self._head_path_for_directory = {}
        self._candidates_for_directory = {}
Example #7
0
def _ExtraClangFlags():
  flags = _SpecialClangIncludes()
  # On Windows, parsing of templates is delayed until instantiation time.
  # This makes GetType and GetParent commands fail to return the expected
  # result when the cursor is in a template.
  # Using the -fno-delayed-template-parsing flag disables this behavior.
  # See
  # http://clang.llvm.org/extra/PassByValueTransform.html#note-about-delayed-template-parsing # noqa
  # for an explanation of the flag and
  # https://code.google.com/p/include-what-you-use/source/detail?r=566
  # for a similar issue.
  if OnWindows():
    flags.append( '-fno-delayed-template-parsing' )
  return flags
Example #8
0
                         OnMac,
                         OnWindows,
                         ToUnicode,
                         WaitUntilProcessIsTerminated )
ycm_core = ImportCore()

from unittest import skipIf

TESTS_DIR = os.path.abspath( os.path.dirname( __file__ ) )
TEST_OPTIONS = {
  # The 'client' represented by the tests supports on-demand resolve, but the
  # server default config doesn't for backward compatibility
  'max_num_candidates_to_detail': 10
}

WindowsOnly = skipIf( not OnWindows(), 'Windows only' )
ClangOnly = skipIf( not ycm_core.HasClangSupport(),
                    'Only when Clang support available' )
MacOnly = skipIf( not OnMac(), 'Mac only' )
UnixOnly = skipIf( OnWindows(), 'Unix only' )

EMPTY_SIGNATURE_HELP = has_entries( {
  'activeParameter': 0,
  'activeSignature': 0,
  'signatures': empty(),
} )


def BuildRequest( **kwargs ):
  filepath = kwargs[ 'filepath' ] if 'filepath' in kwargs else '/foo'
  contents = kwargs[ 'contents' ] if 'contents' in kwargs else ''
Example #9
0
from builtins import *  # noqa

from future.utils import PY2
from ycmd.completers.completer import Completer
from ycmd.responses import BuildCompletionData
from ycmd.utils import OnWindows
import os.path

try:
    from unittest import skipIf
except ImportError:
    from unittest2 import skipIf

Py2Only = skipIf(not PY2, 'Python 2 only')
Py3Only = skipIf(PY2, 'Python 3 only')
WindowsOnly = skipIf(not OnWindows(), 'Windows only')


def BuildRequest(**kwargs):
    filepath = kwargs['filepath'] if 'filepath' in kwargs else '/foo'
    contents = kwargs['contents'] if 'contents' in kwargs else ''
    filetype = kwargs['filetype'] if 'filetype' in kwargs else 'foo'

    request = {
        'line_num': 1,
        'column_num': 1,
        'filepath': filepath,
        'file_data': {
            filepath: {
                'contents': contents,
                'filetypes': [filetype]
# along with ycmd.  If not, see <http://www.gnu.org/licenses/>.

import os

from hamcrest import assert_that, equal_to

from ycmd.tests.test_utils import ClangOnly
from ycmd.utils import ToBytes, OnWindows, ImportCore
ycm_core = ImportCore()

# We don't use PathToTestFile from test_utils module because this module
# imports future modules that may change the path type.
PATH_TO_TESTDATA = os.path.abspath(
    os.path.join(os.path.dirname(__file__), 'testdata'))
PATH_TO_COMPILE_COMMANDS = (os.path.join(PATH_TO_TESTDATA, 'windows')
                            if OnWindows() else os.path.join(
                                PATH_TO_TESTDATA, 'unix'))
COMPILE_COMMANDS_WORKING_DIR = 'C:\\dir' if OnWindows() else '/dir'


def GetUtf8String_Str_test():
    assert_that(b'fo\xc3\xb8', equal_to(ycm_core.GetUtf8String('foø')))


def GetUtf8String_Bytes_test():
    assert_that(b'fo\xc3\xb8',
                equal_to(ycm_core.GetUtf8String(bytes('foø', 'utf8'))))


def GetUtf8String_Int_test():
    assert_that(b'123', equal_to(ycm_core.GetUtf8String(123)))
Example #11
0
Version = namedtuple('Version', ['major', 'minor', 'patch'])

# This variable must be patched with a Version object for tests depending on a
# recent Vim version. Example:
#
#   @patch( 'ycm.tests.test_utils.VIM_VERSION', Version( 8, 1, 614 ) )
#   def ThisTestDependsOnTheVimVersion_test():
#     ...
#
# Default is the oldest supported version.
VIM_VERSION = Version(7, 4, 1578)

REDIR = {'status': False, 'variable': '', 'output': ''}

WindowsAndMacOnly = skipIf(not OnWindows() or not OnMac(),
                           'Windows and macOS only')


@contextlib.contextmanager
def CurrentWorkingDirectory(path):
    old_cwd = GetCurrentDirectory()
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(old_cwd)


def _MockGetBufferNumber(buffer_filename):
    for vim_buffer in VIM_MOCK.buffers:
Example #12
0
from ycmd.completers.completer import Completer
from ycmd.responses import BuildCompletionData
from ycmd.utils import (GetCurrentDirectory, OnMac, OnWindows, ToUnicode,
                        WaitUntilProcessIsTerminated)
import ycm_core

try:
    from unittest import skipIf
except ImportError:
    from unittest2 import skipIf

TESTS_DIR = os.path.abspath(os.path.dirname(__file__))

Py2Only = skipIf(not PY2, 'Python 2 only')
Py3Only = skipIf(PY2, 'Python 3 only')
WindowsOnly = skipIf(not OnWindows(), 'Windows only')
ClangOnly = skipIf(not ycm_core.HasClangSupport(),
                   'Only when Clang support available')
MacOnly = skipIf(not OnMac(), 'Mac only')
UnixOnly = skipIf(OnWindows(), 'Unix only')
NoWinPy2 = skipIf(OnWindows() and PY2, 'Disabled on Windows with Python 2')


def BuildRequest(**kwargs):
    filepath = kwargs['filepath'] if 'filepath' in kwargs else '/foo'
    contents = kwargs['contents'] if 'contents' in kwargs else ''
    filetype = kwargs['filetype'] if 'filetype' in kwargs else 'foo'
    filetypes = kwargs['filetypes'] if 'filetypes' in kwargs else [filetype]

    request = {
        'line_num': 1,
Example #13
0
from nose.tools import eq_
from future.types.newbytes import newbytes
from future.types.newstr import newstr
from future.utils import native

import ycm_core
from ycmd.tests.test_utils import ClangOnly, Py2Only, Py3Only
from ycmd.utils import ToBytes, ToUnicode, OnWindows


# We don't use PathToTestFile from test_utils module because this module
# imports future modules that may change the path type.
PATH_TO_TESTDATA = os.path.abspath( os.path.join( os.path.dirname( __file__ ),
                                                  'testdata' ) )
PATH_TO_COMPILE_COMMANDS = (
  os.path.join( PATH_TO_TESTDATA, 'windows' ) if OnWindows() else
  os.path.join( PATH_TO_TESTDATA, 'unix' ) )
COMPILE_COMMANDS_WORKING_DIR = 'C:\\dir' if OnWindows() else '/dir'


def GetUtf8String_Str_test():
  eq_( b'fo\xc3\xb8', ycm_core.GetUtf8String( 'foø' ) )


# unicode literals are identical to regular string literals on Python 3.
@Py2Only
def GetUtf8String_Unicode_test():
  eq_( b'fo\xc3\xb8', ycm_core.GetUtf8String( u'foø' ) )


# newstr is an emulation of Python 3 str on Python 2.
Example #14
0
from future.utils import PY2

from ..handlers_test import Handlers_test
from ycmd.utils import OnTravis, OnWindows
import time
from contextlib import contextmanager

# If INSTANCE_PER_TEST is set, each test case will start up and shutdown an
# instance of Omnisharp server.  Otherwise - the default - it will reuse the
# Omnisharp instances between individual test cases. Non caching (false) is
# much faster, but test cases are not totally isolated from each other.
# For test case isolation, set to true.
# Reusing Omnisharp instances this way on Windows and Python 3 will randomly
# raise the error "OSError: [WinError 6] The handle is invalid" in tests so
# we set it to true in this case.
INSTANCE_PER_TEST = True if OnWindows() and not PY2 else False


class Cs_Handlers_test(Handlers_test):

    omnisharp_file_solution = {}
    omnisharp_solution_port = {}
    omnisharp_solution_file = {}

    def __init__(self):
        self._file = __file__

    def setUp(self):
        super(Cs_Handlers_test, self).setUp()
        self._app.post_json(
            '/ignore_extra_conf_file',