コード例 #1
0
ファイル: cs_completer.py プロジェクト: zhaopuming/ycmd
    def _StartServer(self, request_data):
        """ Start the OmniSharp server """
        self._logger.info('startup')

        # NOTE: detection could throw an exception if an extra_conf_store needs to
        # be confirmed
        path_to_solutionfile = solutiondetection.FindSolutionPath(
            request_data['filepath'])

        if not path_to_solutionfile:
            raise RuntimeError('Autodetection of solution file failed.\n')
        self._logger.info(
            u'Loading solution file {0}'.format(path_to_solutionfile))

        self._ChooseOmnisharpPort()

        # we need to pass the command to Popen as a string since we're passing
        # shell=True (as recommended by Python's doc)
        command = ' '.join([
            PATH_TO_OMNISHARP_BINARY, '-p',
            str(self._omnisharp_port), '-s',
            u'"{0}"'.format(path_to_solutionfile)
        ])

        if not utils.OnWindows() and not utils.OnCygwin():
            command = u'mono ' + command

        if utils.OnCygwin():
            command = command + ' --client-path-mode Cygwin'

        filename_format = os.path.join(utils.PathToTempDir(),
                                       u'omnisharp_{port}_{sln}_{std}.log')

        solutionfile = os.path.basename(path_to_solutionfile)
        self._filename_stdout = filename_format.format(
            port=self._omnisharp_port, sln=solutionfile, std='stdout')
        self._filename_stderr = filename_format.format(
            port=self._omnisharp_port, sln=solutionfile, std='stderr')

        with open(self._filename_stderr, 'w') as fstderr:
            with open(self._filename_stdout, 'w') as fstdout:
                # shell=True is needed for Windows so OmniSharp does not spawn
                # in a new visible window
                self._omnisharp_phandle = utils.SafePopen(command,
                                                          stdout=fstdout,
                                                          stderr=fstderr,
                                                          shell=True)

        self._solution_path = path_to_solutionfile

        self._logger.info('Starting OmniSharp server')
コード例 #2
0
    def _StartServer(self):
        """ Start the OmniSharp server if not already running. Use a lock to avoid
    starting the server multiple times for the same solution. """
        with self._server_state_lock:
            if self.ServerIsRunning():
                return

            self._logger.info('Starting OmniSharp server')

            path_to_solutionfile = self._solution_path
            self._logger.info(
                u'Loading solution file {0}'.format(path_to_solutionfile))

            self._ChooseOmnisharpPort()

            command = [
                PATH_TO_OMNISHARP_BINARY, '-p',
                str(self._omnisharp_port), '-s',
                u'{0}'.format(path_to_solutionfile)
            ]

            if not utils.OnWindows() and not utils.OnCygwin():
                command.insert(0, 'mono')

            if utils.OnCygwin():
                command.extend(['--client-path-mode', 'Cygwin'])

            filename_format = os.path.join(
                utils.PathToCreatedTempDir(),
                u'omnisharp_{port}_{sln}_{std}.log')

            solutionfile = os.path.basename(path_to_solutionfile)
            self._filename_stdout = filename_format.format(
                port=self._omnisharp_port, sln=solutionfile, std='stdout')
            self._filename_stderr = filename_format.format(
                port=self._omnisharp_port, sln=solutionfile, std='stderr')

            with open(self._filename_stderr, 'w') as fstderr:
                with open(self._filename_stdout, 'w') as fstdout:
                    self._omnisharp_phandle = utils.SafePopen(command,
                                                              stdout=fstdout,
                                                              stderr=fstderr)
                    self._external_omnisharp = False

            self._solution_path = path_to_solutionfile
コード例 #3
0
    def _StartServer(self):
        """ Start the OmniSharp server if not already running. Use a lock to avoid
    starting the server multiple times for the same solution. """
        with self._server_state_lock:
            if self._ServerIsRunning():
                return

            self._logger.info('Starting OmniSharp server')

            path_to_solutionfile = self._solution_path
            self._logger.info(
                u'Loading solution file {0}'.format(path_to_solutionfile))

            self._ChooseOmnisharpPort()

            command = [
                PATH_TO_OMNISHARP_BINARY, '-p',
                str(self._omnisharp_port), '-s',
                u'{0}'.format(path_to_solutionfile)
            ]

            if not utils.OnWindows() and not utils.OnCygwin():
                command.insert(0, 'mono')

            if utils.OnCygwin():
                command.extend(['--client-path-mode', 'Cygwin'])

            solutionfile = os.path.basename(path_to_solutionfile)
            self._filename_stdout = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stdout'))
            self._filename_stderr = utils.CreateLogfile(
                LOGFILE_FORMAT.format(port=self._omnisharp_port,
                                      sln=solutionfile,
                                      std='stderr'))

            with utils.OpenForStdHandle(self._filename_stderr) as fstderr:
                with utils.OpenForStdHandle(self._filename_stdout) as fstdout:
                    self._omnisharp_phandle = utils.SafePopen(command,
                                                              stdout=fstdout,
                                                              stderr=fstderr)

            self._solution_path = path_to_solutionfile
コード例 #4
0
ファイル: cs_completer.py プロジェクト: darmstrong-mw/ycmd
    def _StartServer(self):
        """ Start the OmniSharp server """
        self._logger.info('startup')

        path_to_solutionfile = self._solution_path
        self._logger.info(
            u'Loading solution file {0}'.format(path_to_solutionfile))

        self._ChooseOmnisharpPort()

        command = [
            PATH_TO_OMNISHARP_BINARY, '-p',
            str(self._omnisharp_port), '-s',
            u'{0}'.format(path_to_solutionfile)
        ]

        if not utils.OnWindows() and not utils.OnCygwin():
            command.insert(0, 'mono')

        if utils.OnCygwin():
            command.extend(['--client-path-mode', 'Cygwin'])

        filename_format = os.path.join(utils.PathToTempDir(),
                                       u'omnisharp_{port}_{sln}_{std}.log')

        solutionfile = os.path.basename(path_to_solutionfile)
        self._filename_stdout = filename_format.format(
            port=self._omnisharp_port, sln=solutionfile, std='stdout')
        self._filename_stderr = filename_format.format(
            port=self._omnisharp_port, sln=solutionfile, std='stderr')

        with open(self._filename_stderr, 'w') as fstderr:
            with open(self._filename_stdout, 'w') as fstdout:
                self._omnisharp_phandle = utils.SafePopen(command,
                                                          stdout=fstdout,
                                                          stderr=fstderr)

        self._solution_path = path_to_solutionfile

        self._logger.info('Starting OmniSharp server')
コード例 #5
0
ファイル: cs_completer.py プロジェクト: symbolix/ycmd
  def _StartServer( self, request_data ):
    """ Start the OmniSharp server """
    self._logger.info( 'startup' )

    self._omnisharp_port = utils.GetUnusedLocalhostPort()
    solution_files, folder = _FindSolutionFiles( request_data[ 'filepath' ] )

    if len( solution_files ) == 0:
      raise RuntimeError(
        'Error starting OmniSharp server: no solutionfile found' )
    elif len( solution_files ) == 1:
      solutionfile = solution_files[ 0 ]
    else:
      # multiple solutions found : if there is one whose name is the same
      # as the folder containing the file we edit, use this one
      # (e.g. if we have bla/Project.sln and we are editing
      # bla/Project/Folder/File.cs, use bla/Project.sln)
      filepath_components = _PathComponents( request_data[ 'filepath' ] )
      solutionpath = _PathComponents( folder )
      foldername = ''
      if len( filepath_components ) > len( solutionpath ):
          foldername = filepath_components[ len( solutionpath ) ]
      solution_file_candidates = [ sfile for sfile in solution_files
        if _GetFilenameWithoutExtension( sfile ) == foldername ]
      if len( solution_file_candidates ) == 1:
        solutionfile = solution_file_candidates[ 0 ]
      else:
        raise RuntimeError(
          'Found multiple solution files instead of one!\n{0}'.format(
            solution_files ) )

    path_to_solutionfile = os.path.join( folder, solutionfile )
    # we need to pass the command to Popen as a string since we're passing
    # shell=True (as recommended by Python's doc)
    command = ' '.join( [ PATH_TO_OMNISHARP_BINARY,
                         '-p',
                         str( self._omnisharp_port ),
                         '-s',
                         path_to_solutionfile ] )

    if not utils.OnWindows() and not utils.OnCygwin():
      command = 'mono ' + command

    if utils.OnCygwin():
      command = command + ' --client-path-mode Cygwin'

    filename_format = os.path.join( utils.PathToTempDir(),
                                   'omnisharp_{port}_{sln}_{std}.log' )

    self._filename_stdout = filename_format.format(
        port=self._omnisharp_port, sln=solutionfile, std='stdout' )
    self._filename_stderr = filename_format.format(
        port=self._omnisharp_port, sln=solutionfile, std='stderr' )

    with open( self._filename_stderr, 'w' ) as fstderr:
      with open( self._filename_stdout, 'w' ) as fstdout:
        # shell=True is needed for Windows so OmniSharp does not spawn
        # in a new visible window
        utils.SafePopen( command, stdout=fstdout, stderr=fstderr, shell=True )

    self._logger.info( 'Starting OmniSharp server' )