Beispiel #1
0
  /** Do final stage of plugin start: activate services, listeners, etc. */
  protected void doCustomStart_finalStage() {
    operationsListener = createOperationsConsoleListener();
    if (operationsListener != null) {
      LangCore.getToolManager().addListener(operationsListener);
    }

    LangCore.getInstance().initializeAfterUIStart();

    new InitializeAfterLoadJob(this).schedule();
  }
Beispiel #2
0
  protected IStatus validatePositiveNumber(String number) {
    if (number.length() == 0) {
      return LangCore.createErrorStatus(FieldMessages.NumberField_empty_input);
    }

    try {
      int value = Integer.parseInt(number);
      if (value >= 0) {
        return LangCore.createOkStatus(null);
      }
    } catch (NumberFormatException e) {
    }
    return LangCore.createErrorStatus(
        MessageFormat.format(FieldMessages.NumberField_invalid_input, number));
  }
  @Override
  protected GocodeServerInstance doCreateServerInstance(IOperationMonitor om)
      throws CommonException, OperationCancellation {
    Path gocodePath = getServerPath();

    ArrayList2<String> commandLine = new ArrayList2<String>();
    commandLine.add(gocodePath.toString());
    commandLine.add("-s");
    if (GocodeCompletionOperation.USE_TCP) {
      commandLine.add("-sock=tcp");
    }

    LangCore.logInfo(
        "Starting gocode server: "
            + DebugPlugin.renderArguments(commandLine.toArray(String.class), null));

    ProcessBuilder pb = new ProcessBuilder(commandLine);

    IToolOperationMonitor opMonitor =
        toolMgr.startNewOperation(ProcessStartKind.ENGINE_SERVER, true, false);
    String prefixText = "==== Starting gocode server ====\n";

    gocodeSetEnableBuiltins(gocodePath, om, opMonitor, prefixText);

    ExternalProcessNotifyingHelper process =
        toolMgr.new RunToolTask(opMonitor, prefixText, null, pb, om).startProcess();

    return new GocodeServerInstance(gocodePath, process);
  }
 @Override
 protected void prepareOperation() throws CoreException, CommonException {
   if (inputLoc == null) {
     throw LangCore.createCoreException(
         "Could not determine filesystem path from editor input", null);
   }
 }
  public static boolean runAndHandle(
      IRunnableContext runnableContext,
      IRunnableWithProgress op,
      boolean isCancellable,
      String errorTitle) {

    try {
      runnableContext.run(true, isCancellable, op);
      return true;
    } catch (InvocationTargetException e) {
      Throwable targetException = e.getTargetException();
      if (targetException instanceof OperationCanceledException) {
        return false;
      }

      CoreException ce;
      if (targetException instanceof CoreException) {
        ce = (CoreException) e.getTargetException();
      } else {
        ce = LangCore.createCoreException("Internal error: ", targetException);
      }
      UIOperationExceptionHandler.handleOperationStatus(errorTitle, ce);
      return false;
    } catch (InterruptedException e) {
      return false;
    }
  }
 protected IStatus getValidationStatus() {
   try {
     nameGroup.validate();
     locationGroup.validate();
     return Status.OK_STATUS;
   } catch (CommonException e) {
     return LangCore.createErrorStatus(e.getMessage(), e.getCause());
   }
 }
 public ExternalProcessResult runEngineTool(
     ProcessBuilder pb, String clientInput, ICancelMonitor cm)
     throws CoreException, OperationCancellation {
   try {
     return new RunEngineClientOperation(pb, cm).runProcess(clientInput);
   } catch (CommonException ce) {
     throw LangCore.createCoreException(ce);
   }
 }
Beispiel #8
0
  @Override
  public void stop(BundleContext context) throws Exception {
    if (operationsListener != null) {
      LangCore.getToolManager().removeListener(operationsListener);
    }

    doCustomStop(context);
    super.stop(context);
    pluginInstance = null;
  }
  @Override
  protected Indexable<ICompletionProposal> computeProposals(
      SourceOperationContext context, int offset, TimeoutProgressMonitor pm)
      throws CoreException, CommonException, OperationCancellation, OperationSoftFailure {

    IEditorPart editor = context.getEditor_nonNull();
    Location fileLoc = context.getEditorInputLocation();
    IDocument document = context.getDocument();

    String prefix = lastWord(document, offset);

    GoUIPlugin.prepareGocodeManager_inUI();
    IPath gocodePath = GocodeServerManager.getGocodePath();
    if (gocodePath == null) {
      throw LangCore.createCoreException("Error: gocode path not provided.", null);
    }
    IProject project = getProjectFor(editor);

    GoEnvironment goEnvironment = GoProjectEnvironment.getGoEnvironment(project);

    // TODO: we should run this operation outside the UI thread.
    GocodeCompletionOperation client =
        new GocodeCompletionOperation(
            getEngineToolRunner(pm), goEnvironment, gocodePath.toOSString());

    ExternalProcessResult processResult =
        client.execute(fileLoc.toPathString(), document.get(), offset);
    String stdout = processResult.getStdOutBytes().toString(StringUtil.UTF8);
    List<String> completions =
        new ArrayList2<>(GocodeCompletionOperation.LINE_SPLITTER.split(stdout));

    ArrayList2<ICompletionProposal> results = new ArrayList2<>();

    for (String completionEntry : completions) {
      handleResult(offset, /*codeContext,*/ results, prefix, completionEntry);
    }

    return results;
  }
 @Override
 public void logStatus(StatusException statusException) {
   LangCore.logStatusException(statusException);
 }
Beispiel #11
0
 /** Creates a Status with given status code and message. */
 public static StatusExt createStatus(int statusCode, String message, Throwable throwable) {
   return new StatusExt(statusCode, LangCore.getInstance(), message, throwable);
 }