Example #1
0
    def _SetupServer(self):
        server_port = utils.GetUnusedLocalhostPort()
        with tempfile.NamedTemporaryFile(delete=False) as options_file:
            self._temp_options_filename = options_file.name
            json.dump(dict(self._user_options), options_file)
            args = [
                utils.PathToPythonInterpreter(),
                _PathToServerScript(), '--port={0}'.format(server_port),
                '--options_file={0}'.format(options_file.name),
                '--log={0}'.format(self._user_options['server_log_level']),
                '--idle_suicide_seconds={0}'.format(
                    self._user_options['server_idle_suicide_seconds'])
            ]

            BaseRequest.server_location = 'http://localhost:' + str(
                server_port)

            if self._user_options['server_use_vim_stdout']:
                self._server_popen = subprocess.Popen(args)
            else:
                filename_format = os.path.join(utils.PathToTempDir(),
                                               'server_{port}_{std}.log')

                self._server_stdout = filename_format.format(port=server_port,
                                                             std='stdout')
                self._server_stderr = filename_format.format(port=server_port,
                                                             std='stderr')

                with open(self._server_stderr, 'w') as fstderr:
                    with open(self._server_stdout, 'w') as fstdout:
                        self._server_popen = subprocess.Popen(args,
                                                              stdout=fstdout,
                                                              stderr=fstderr)
        self._NotifyUserIfServerCrashed()
Example #2
0
  def _SetupServer( self ):
    server_port = utils.GetUnusedLocalhostPort()
    with tempfile.NamedTemporaryFile( delete = False ) as options_file:
      self._temp_options_filename = options_file.name
      json.dump( dict( self._user_options ), options_file )
      options_file.flush()

      args = [ utils.PathToPythonInterpreter(),
               _PathToServerScript(),
               '--port={0}'.format( server_port ),
               '--options_file={0}'.format( options_file.name ),
               '--log={0}'.format( self._user_options[ 'server_log_level' ] ),
               '--idle_suicide_seconds={0}'.format(
                  SERVER_IDLE_SUICIDE_SECONDS )]

      if not self._user_options[ 'server_use_vim_stdout' ]:
        filename_format = os.path.join( utils.PathToTempDir(),
                                        'server_{port}_{std}.log' )

        self._server_stdout = filename_format.format( port = server_port,
                                                      std = 'stdout' )
        self._server_stderr = filename_format.format( port = server_port,
                                                      std = 'stderr' )
        args.append('--stdout={0}'.format( self._server_stdout ))
        args.append('--stderr={0}'.format( self._server_stderr ))

        if self._user_options[ 'server_keep_logfiles' ]:
          args.append('--keep_logfiles')

      self._server_popen = utils.SafePopen( args, stdout = PIPE, stderr = PIPE)
      BaseRequest.server_location = 'http://localhost:' + str( server_port )

    self._NotifyUserIfServerCrashed()
Example #3
0
    def _StartServer(self, request_data):
        """ Start the OmniSharp server """
        self._logger.info('startup')

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

        if len(solutionfiles) == 0:
            raise RuntimeError(
                'Error starting OmniSharp server: no solutionfile found')
        elif len(solutionfiles) == 1:
            solutionfile = solutionfiles[0]
        else:
            raise RuntimeError(
                'Found multiple solution files instead of one!\n{0}'.format(
                    solutionfiles))

        omnisharp = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe')

        if not os.path.isfile(omnisharp):
            raise RuntimeError(SERVER_NOT_FOUND_MSG.format(omnisharp))

        if not platform.startswith('win'):
            omnisharp = 'mono ' + omnisharp

        path_to_solutionfile = os.path.join(folder, solutionfile)
        # command has to be provided as one string for some reason
        command = [
            omnisharp + ' -p ' + str(self._omnisharp_port) + ' -s ' +
            path_to_solutionfile
        ]

        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:
                subprocess.Popen(command,
                                 stdout=fstdout,
                                 stderr=fstderr,
                                 shell=True)

        self._logger.info('Starting OmniSharp server')
Example #4
0
    def _SetupServer(self):
        server_port = utils.GetUnusedLocalhostPort()
        # The temp options file is deleted by ycmd during startup
        with tempfile.NamedTemporaryFile(delete=False) as options_file:
            hmac_secret = os.urandom(HMAC_SECRET_LENGTH)
            options_dict = dict(self._user_options)
            options_dict['hmac_secret'] = base64.b64encode(hmac_secret)
            json.dump(options_dict, options_file)
            options_file.flush()

            args = [
                utils.PathToPythonInterpreter(),
                _PathToServerScript(), '--port={0}'.format(server_port),
                '--options_file={0}'.format(options_file.name),
                '--log={0}'.format(self._user_options['server_log_level']),
                '--idle_suicide_seconds={0}'.format(
                    SERVER_IDLE_SUICIDE_SECONDS)
            ]

            if not self._user_options['server_use_vim_stdout']:
                filename_format = os.path.join(utils.PathToTempDir(),
                                               'server_{port}_{std}.log')

                self._server_stdout = filename_format.format(port=server_port,
                                                             std='stdout')
                self._server_stderr = filename_format.format(port=server_port,
                                                             std='stderr')
                args.append('--stdout={0}'.format(self._server_stdout))
                args.append('--stderr={0}'.format(self._server_stderr))

                if self._user_options['server_keep_logfiles']:
                    args.append('--keep_logfiles')

            self._server_popen = utils.SafePopen(args,
                                                 stdout=PIPE,
                                                 stderr=PIPE)
            BaseRequest.server_location = 'http://localhost:' + str(
                server_port)
            BaseRequest.hmac_secret = hmac_secret

        self._NotifyUserIfServerCrashed()
Example #5
0
    def _SetupServer(self):
        server_port = utils.GetUnusedLocalhostPort()
        with tempfile.NamedTemporaryFile(delete=False) as options_file:
            self._temp_options_filename = options_file.name
            json.dump(dict(self._user_options), options_file)
            args = [
                utils.PathToPythonInterpreter(),
                _PathToServerScript(), '--port={0}'.format(server_port),
                '--options_file={0}'.format(options_file.name),
                '--log={0}'.format(self._user_options['server_log_level']),
                '--idle_suicide_seconds={0}'.format(
                    SERVER_IDLE_SUICIDE_SECONDS)
            ]

            BaseRequest.server_location = 'http://localhost:' + str(
                server_port)

            if self._user_options['server_use_vim_stdout']:
                self._server_popen = subprocess.Popen(args)
            else:
                filename_format = os.path.join(utils.PathToTempDir(),
                                               'server_{port}_{std}.log')

                self._server_stdout = filename_format.format(port=server_port,
                                                             std='stdout')
                self._server_stderr = filename_format.format(port=server_port,
                                                             std='stderr')
                # We need this on Windows otherwise bad things happen. See issue #637.
                stdin = subprocess.PIPE if utils.OnWindows() else None

                with open(self._server_stderr, 'w') as fstderr:
                    with open(self._server_stdout, 'w') as fstdout:
                        self._server_popen = subprocess.Popen(args,
                                                              stdin=stdin,
                                                              stdout=fstdout,
                                                              stderr=fstderr)
        self._NotifyUserIfServerCrashed()
Example #6
0
  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 = [ solutionfile for solutionfile in solution_files
        if _GetFilenameWithoutExtension( solutionfile ) == 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 ) )

    omnisharp = os.path.join(
      os.path.abspath( os.path.dirname( __file__ ) ),
      'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe' )

    if not os.path.isfile( omnisharp ):
      raise RuntimeError( SERVER_NOT_FOUND_MSG.format( omnisharp ) )

    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 = ( omnisharp + ' -p ' + str( self._omnisharp_port ) + ' -s ' +
                path_to_solutionfile )

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

    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' )
Example #7
0
    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 = [
                solutionfile for solutionfile in solution_files
                if _GetFilenameWithoutExtension(solutionfile) == 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))

        omnisharp = os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'OmniSharpServer/OmniSharp/bin/Debug/OmniSharp.exe')

        if not os.path.isfile(omnisharp):
            raise RuntimeError(SERVER_NOT_FOUND_MSG.format(omnisharp))

        if not platform.startswith('win'):
            omnisharp = 'mono ' + omnisharp

        path_to_solutionfile = os.path.join(folder, solutionfile)
        # command has to be provided as one string for some reason
        command = [
            omnisharp + ' -p ' + str(self._omnisharp_port) + ' -s ' +
            path_to_solutionfile
        ]

        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:
                subprocess.Popen(command,
                                 stdout=fstdout,
                                 stderr=fstderr,
                                 shell=True)

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