Search in sources :

Example 1 with CommandLineFile

use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.

the class CommandConsole method switchToCommandMode.

/**
   * Switches console to "command-mode" (see class doc for details)
   */
private void switchToCommandMode() {
    // "upper" and "bottom" parts of console both need padding in command mode
    myProcessHandler = null;
    setPrompt(getTitle() + " > ");
    ApplicationManager.getApplication().invokeAndWait(() -> {
        notifyStateChangeListeners();
        configureLeftBorder(true, getConsoleEditor(), getHistoryViewer());
        setLanguage(CommandLineLanguage.INSTANCE);
        final CommandLineFile file = PyUtil.as(getFile(), CommandLineFile.class);
        resetConsumer(null);
        if (file == null || myCommandsInfo == null) {
            return;
        }
        file.setCommands(myCommandsInfo.getCommands());
        final CommandConsole console = this;
        resetConsumer(new CommandModeConsumer(myCommandsInfo.getCommands(), myModule, console, myCommandsInfo.getUnknownCommandsExecutor()));
    }, ModalityState.NON_MODAL);
}
Also used : CommandLineFile(com.jetbrains.commandInterface.commandLine.psi.CommandLineFile)

Example 2 with CommandLineFile

use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.

the class ArgumentHintLayer method attach.

/**
   * Attaches argument displaying layer to console. Be sure your console has commands.
   * For now, <strong>only {@link CommandLineFile} is supported for now!</strong>
   *
   * @param console console to attach
   * @throws IllegalArgumentException is passed argument is not {@link CommandLineFile}
   */
static void attach(@NotNull final CommandConsole console) {
    final PsiFile consoleFile = console.getFile();
    if (!(consoleFile instanceof CommandLineFile)) {
        throw new IllegalArgumentException(String.format("Passed argument is %s, but has to be %s", consoleFile.getClass(), CommandLineFile.class));
    }
    final ArgumentHintLayer argumentHintLayer = new ArgumentHintLayer(console);
    console.addStateChangeListener(argumentHintLayer);
    final MessageBusConnection connection = console.getProject().getMessageBus().connect();
    connection.subscribe(PsiModificationTracker.TOPIC, argumentHintLayer);
    console.addLayerToPane(argumentHintLayer);
    // Registered to disconnect on disposal
    Disposer.register(console, new Disconnector(connection));
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) CommandLineFile(com.jetbrains.commandInterface.commandLine.psi.CommandLineFile) PsiFile(com.intellij.psi.PsiFile)

Example 3 with CommandLineFile

use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.

the class CommandLineArgsTest method validateNextArgument.

/**
   * Runs commands and checks argument is required after it
   * @param commandText command text to run
   * @param expectedArgumentText expected next argument help text
   */
private void validateNextArgument(@NotNull final String commandText, @NotNull final String expectedArgumentText) {
    final CommandLineFile file = CommandTestTools.createFileByText(myFixture, commandText);
    final ValidationResult validationResult = file.getValidationResult();
    assert validationResult != null : "validation failed";
    final Pair<Boolean, Argument> arg = validationResult.getNextArg();
    Assert.assertNotNull("No argument returned, but should", arg);
    Assert.assertTrue("Required argument is not marked as required", arg.first);
    Assert.assertEquals("Wrong argument text", expectedArgumentText, arg.second.getHelp().getHelpString());
}
Also used : Argument(com.jetbrains.commandInterface.command.Argument) CommandLineFile(com.jetbrains.commandInterface.commandLine.psi.CommandLineFile)

Example 4 with CommandLineFile

use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.

the class CommandLinePsiImplUtils method getValidationResult.

/**
   * Searches for validation result for command line
   *
   * @param commandLinePart command line part
   * @return validation result (if any)
   */
@Nullable
private static ValidationResult getValidationResult(@NotNull final CommandLinePart commandLinePart) {
    final CommandLineFile commandLineFile = commandLinePart.getCommandLineFile();
    if (commandLineFile == null) {
        return null;
    }
    final ValidationResult validationResult = commandLineFile.getValidationResult();
    if (validationResult == null) {
        return null;
    }
    return validationResult;
}
Also used : CommandLineFile(com.jetbrains.commandInterface.commandLine.psi.CommandLineFile) ValidationResult(com.jetbrains.commandInterface.commandLine.ValidationResult) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CommandLineFile

use of com.jetbrains.commandInterface.commandLine.psi.CommandLineFile in project intellij-community by JetBrains.

the class ArgumentHintLayer method modificationCountChanged.

@Override
public void modificationCountChanged() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final String newText = myConsole.getFile().getText();
    if (newText.equals(myLastText)) {
        // If text did not changed from last time, we do nothing
        return;
    }
    // Store text for next time check
    myLastText = newText;
    // Reset current argument
    myNextArg = null;
    final PsiFile consoleFile = myConsole.getFile();
    // Get next arg from file
    if (consoleFile instanceof CommandLineFile) {
        final ValidationResult result = ((CommandLineFile) consoleFile).getValidationResult();
        myNextArg = result != null ? result.getNextArg() : null;
        // We need to repaint us if argument changed
        repaint();
    }
}
Also used : CommandLineFile(com.jetbrains.commandInterface.commandLine.psi.CommandLineFile) PsiFile(com.intellij.psi.PsiFile) ValidationResult(com.jetbrains.commandInterface.commandLine.ValidationResult)

Aggregations

CommandLineFile (com.jetbrains.commandInterface.commandLine.psi.CommandLineFile)10 PsiFile (com.intellij.psi.PsiFile)3 Command (com.jetbrains.commandInterface.command.Command)2 ValidationResult (com.jetbrains.commandInterface.commandLine.ValidationResult)2 NotNull (org.jetbrains.annotations.NotNull)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 PsiFileFactory (com.intellij.psi.PsiFileFactory)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 Argument (com.jetbrains.commandInterface.command.Argument)1 Help (com.jetbrains.commandInterface.command.Help)1 CommandLineCommand (com.jetbrains.commandInterface.commandLine.psi.CommandLineCommand)1 Nullable (org.jetbrains.annotations.Nullable)1