Esempio n. 1
0
    def _StartServer(self):
        """ Start the OmniSharp server """
        self._omnisharp_port = self._FindFreePort()
        solutionfiles, folder = _FindSolutionFiles()

        if len(solutionfiles) == 0:
            vimsupport.PostVimMessage(
                'Error starting OmniSharp server: no solutionfile found')
            return
        elif len(solutionfiles) == 1:
            solutionfile = solutionfiles[0]
        else:
            choice = vimsupport.PresentDialog(
                'Which solutionfile should be loaded?', [
                    str(i) + " " + solution
                    for i, solution in enumerate(solutionfiles)
                ])
            if choice == -1:
                vimsupport.PostVimMessage('OmniSharp not started')
                return
            else:
                solutionfile = solutionfiles[choice]

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

        if not os.path.isfile(omnisharp):
            vimsupport.PostVimMessage(SERVER_NOT_FOUND_MSG.format(omnisharp))
            return

        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 = (tempfile.gettempdir() +
                           '/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)

        vimsupport.PostVimMessage('Starting OmniSharp server')
Esempio n. 2
0
    def _StartServer(self):
        """ Start the OmniSharp server """
        if self._ServerIsRunning():
            vimsupport.PostVimMessage(
                'Server already running, not starting it again.')
            return

        solutionfiles, folder = _FindSolutionFiles()

        if len(solutionfiles) == 0:
            vimsupport.PostVimMessage(
                'Error starting OmniSharp server: no solutionfile found')
            return
        elif len(solutionfiles) == 1:
            solutionfile = solutionfiles[0]
        else:
            choice = vimsupport.PresentDialog(
                "Which solutionfile should be loaded?", [
                    str(i) + " " + solution
                    for i, solution in enumerate(solutionfiles)
                ])
            if choice == -1:
                vimsupport.PostVimMessage('OmniSharp not started')
                return
            else:
                solutionfile = solutionfiles[choice]

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

        if not os.path.isfile(omnisharp):
            vimsupport.PostVimMessage(SERVER_NOT_FOUND_MSG.format(omnisharp))
            return

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

        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 ' +
            solutionfile
        ]

        with open(os.devnull, 'w') as fnull:
            subprocess.Popen(command, stdout=fnull, stderr=fnull, shell=True)

        vimsupport.PostVimMessage('Starting OmniSharp server')
Esempio n. 3
0
    def _OnCompleteDone_Csharp(self):
        extra_datas = self._GetExtraDataUserMayHaveCompleted()
        namespaces = [_GetRequiredNamespaceImport(c) for c in extra_datas]
        namespaces = [n for n in namespaces if n]
        if not namespaces:
            return

        if len(namespaces) > 1:
            choices = [f"{ i + 1 } { n }" for i, n in enumerate(namespaces)]
            choice = vimsupport.PresentDialog("Insert which namespace:",
                                              choices)
            if choice < 0:
                return
            namespace = namespaces[choice]
        else:
            namespace = namespaces[0]

        vimsupport.InsertNamespace(namespace)
Esempio n. 4
0
  def _OnCompleteDone_Csharp( self ):
    completions = self._GetCompletionsUserMayHaveCompleted()
    namespaces = [ _GetRequiredNamespaceImport( c ) for c in completions ]
    namespaces = [ n for n in namespaces if n ]
    if not namespaces:
      return

    if len( namespaces ) > 1:
      choices = [ "{0} {1}".format( i + 1, n )
                  for i, n in enumerate( namespaces ) ]
      choice = vimsupport.PresentDialog( "Insert which namespace:", choices )
      if choice < 0:
        return
      namespace = namespaces[ choice ]
    else:
      namespace = namespaces[ 0 ]

    vimsupport.InsertNamespace( namespace )