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);
}
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));
}
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());
}
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;
}
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();
}
}
Aggregations