Search in sources :

Example 1 with PerlSharedSettings

use of com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings in project Perl5-IDEA by Camelcade.

the class PerlParserTestBase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    registerApplicationService(TemplateDataLanguageMappings.class, new TemplateDataLanguageMappings(getProject()));
    registerApplicationService(TemplateDataLanguagePatterns.class, new TemplateDataLanguagePatterns());
    addExplicitExtension(LanguageParserDefinitions.INSTANCE, PerlLanguage.INSTANCE, new PerlParserDefinition());
    addExplicitExtension(LanguageParserDefinitions.INSTANCE, PodLanguage.INSTANCE, new PodParserDefinition());
    registerComponentInstance(myProject, PerlNamesCache.class, new PerlNamesCache(myProject));
    registerExtensionPoint(PerlParserExtension.EP_NAME, PerlParserExtension.class);
    registerExtension(PerlParserExtension.EP_NAME, new MooseParserExtension());
    registerExtension(PerlParserExtension.EP_NAME, new PerlSwitchParserExtensionImpl());
    registerExtension(PerlParserExtension.EP_NAME, new ClassAccessorParserExtension());
    registerExtension(PerlParserExtension.EP_NAME, new MojoParserExtension());
    PerlParserExtensions parserExtensions = new PerlParserExtensions();
    registerComponentInstance(ApplicationManager.getApplication(), PerlParserExtensions.class, parserExtensions);
    parserExtensions.initComponent();
    PerlPackageProcessorEP.EP.addExplicitExtension("constant", new ConstantProcessor());
    PerlPackageProcessorEP.EP.addExplicitExtension("vars", new VarsProcessor());
    PerlPackageProcessorEP.EP.addExplicitExtension("Exception::Class", new ExceptionClassProcessor());
    myProject.registerService(PerlSharedSettings.class, new PerlSharedSettings(getProject()));
}
Also used : TemplateDataLanguagePatterns(com.intellij.psi.templateLanguages.TemplateDataLanguagePatterns) PerlSwitchParserExtensionImpl(com.perl5.lang.perl.parser.PerlSwitchParserExtensionImpl) ClassAccessorParserExtension(com.perl5.lang.perl.parser.ClassAccessorParserExtension) ConstantProcessor(com.perl5.lang.perl.extensions.packageprocessor.impl.ConstantProcessor) MooseParserExtension(com.perl5.lang.perl.parser.MooseParserExtension) PerlParserExtensions(com.perl5.lang.perl.idea.application.PerlParserExtensions) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) PerlParserDefinition(com.perl5.lang.perl.PerlParserDefinition) PodParserDefinition(com.perl5.lang.pod.PodParserDefinition) MojoParserExtension(com.perl5.lang.perl.parser.MojoParserExtension) TemplateDataLanguageMappings(com.intellij.psi.templateLanguages.TemplateDataLanguageMappings) VarsProcessor(com.perl5.lang.perl.extensions.packageprocessor.impl.VarsProcessor) ExceptionClassProcessor(com.perl5.lang.perl.extensions.packageprocessor.impl.ExceptionClassProcessor) PerlNamesCache(com.perl5.lang.perl.idea.project.PerlNamesCache)

Example 2 with PerlSharedSettings

use of com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings in project Perl5-IDEA by Camelcade.

the class PerlCriticAnnotator method getPerlCriticExecutable.

protected GeneralCommandLine getPerlCriticExecutable(Project project) throws ExecutionException {
    PerlSharedSettings sharedSettings = PerlSharedSettings.getInstance(project);
    PerlLocalSettings localSettings = PerlLocalSettings.getInstance(project);
    String executable = localSettings.PERL_CRITIC_PATH;
    if (StringUtil.isEmpty(executable)) {
        throw new ExecutionException("Path to Perl::Critic executable must be configured in perl settings");
    }
    GeneralCommandLine commandLine = new GeneralCommandLine(executable).withWorkDirectory(project.getBasePath());
    if (StringUtil.isNotEmpty(sharedSettings.PERL_CRITIC_ARGS)) {
        commandLine.addParameters(StringUtil.split(sharedSettings.PERL_CRITIC_ARGS, " "));
    }
    return commandLine;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) PerlLocalSettings(com.perl5.lang.perl.idea.configuration.settings.PerlLocalSettings) ExecutionException(com.intellij.execution.ExecutionException)

Example 3 with PerlSharedSettings

use of com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings in project Perl5-IDEA by Camelcade.

the class PerlDeparseFileAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    PsiFile file = PerlActionUtil.getPsiFileFromEvent(event);
    if (file == null) {
        return;
    }
    final Document document = file.getViewProvider().getDocument();
    if (document == null) {
        return;
    }
    final Project project = file.getProject();
    String deparseArgument = "-MO=Deparse";
    PerlSharedSettings perl5Settings = PerlSharedSettings.getInstance(project);
    if (StringUtil.isNotEmpty(perl5Settings.PERL_DEPARSE_ARGUMENTS)) {
        deparseArgument += "," + perl5Settings.PERL_DEPARSE_ARGUMENTS;
    }
    GeneralCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, file.getVirtualFile(), deparseArgument);
    if (commandLine == null) {
        return;
    }
    commandLine.withWorkDirectory(project.getBasePath());
    FileDocumentManager.getInstance().saveDocument(document);
    try {
        ProcessOutput processOutput = ExecUtil.execAndGetOutput(commandLine);
        String deparsed = processOutput.getStdout();
        String error = processOutput.getStderr();
        if (StringUtil.isNotEmpty(error) && !StringUtil.contains(error, "syntax OK")) {
            if (StringUtil.isEmpty(deparsed)) {
                Notifications.Bus.notify(new Notification(PERL_DEPARSE_GROUP, PerlBundle.message("perl.action.error.notification.title"), error.replaceAll("\\n", "<br/>"), NotificationType.ERROR));
            } else {
                Notifications.Bus.notify(new Notification(PERL_DEPARSE_GROUP, PerlBundle.message("perl.action.success.notification.title"), PerlBundle.message("perl.action.success.notification.message", error.replaceAll("\\n", "<br/>")), NotificationType.INFORMATION));
            }
        }
        if (StringUtil.isNotEmpty(deparsed)) {
            VirtualFile newFile = new LightVirtualFile("Deparsed " + file.getName(), file.getFileType(), deparsed);
            OpenFileAction.openFile(newFile, project);
        }
    } catch (ExecutionException e) {
        Notifications.Bus.notify(new Notification(PERL_DEPARSE_GROUP, PerlBundle.message("perl.execution.error.notification.title"), e.getMessage().replaceAll("\\n", "<br/>"), NotificationType.ERROR));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) Document(com.intellij.openapi.editor.Document) ExecutionException(com.intellij.execution.ExecutionException) Notification(com.intellij.notification.Notification)

Example 4 with PerlSharedSettings

use of com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings in project Perl5-IDEA by Camelcade.

the class PerlFormatWithPerlTidyAction method getPerlTidyCommandLine.

protected GeneralCommandLine getPerlTidyCommandLine(Project project) throws ExecutionException {
    PerlSharedSettings sharedSettings = PerlSharedSettings.getInstance(project);
    PerlLocalSettings localSettings = PerlLocalSettings.getInstance(project);
    String executable = localSettings.PERL_TIDY_PATH;
    if (StringUtil.isEmpty(executable)) {
        throw new ExecutionException(PerlBundle.message("perl.action.perl.tidy.execution.exception"));
    }
    GeneralCommandLine commandLine = new GeneralCommandLine(executable, "-st", "-se").withWorkDirectory(project.getBasePath());
    if (StringUtil.isNotEmpty(sharedSettings.PERL_TIDY_ARGS)) {
        commandLine.addParameters(StringUtil.split(sharedSettings.PERL_TIDY_ARGS, " "));
    }
    return commandLine;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) PerlLocalSettings(com.perl5.lang.perl.idea.configuration.settings.PerlLocalSettings) ExecutionException(com.intellij.execution.ExecutionException)

Example 5 with PerlSharedSettings

use of com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings in project Perl5-IDEA by Camelcade.

the class PerlSwitchLiveTemplatesTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    PerlSharedSettings settings = PerlSharedSettings.getInstance(getProject());
    boolean value = settings.PERL_SWITCH_ENABLED;
    addTearDownListener(() -> settings.PERL_SWITCH_ENABLED = value);
    settings.PERL_SWITCH_ENABLED = true;
}
Also used : PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings)

Aggregations

PerlSharedSettings (com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings)5 ExecutionException (com.intellij.execution.ExecutionException)3 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 PerlLocalSettings (com.perl5.lang.perl.idea.configuration.settings.PerlLocalSettings)2 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 Notification (com.intellij.notification.Notification)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 TemplateDataLanguageMappings (com.intellij.psi.templateLanguages.TemplateDataLanguageMappings)1 TemplateDataLanguagePatterns (com.intellij.psi.templateLanguages.TemplateDataLanguagePatterns)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 PerlParserDefinition (com.perl5.lang.perl.PerlParserDefinition)1 ConstantProcessor (com.perl5.lang.perl.extensions.packageprocessor.impl.ConstantProcessor)1 ExceptionClassProcessor (com.perl5.lang.perl.extensions.packageprocessor.impl.ExceptionClassProcessor)1 VarsProcessor (com.perl5.lang.perl.extensions.packageprocessor.impl.VarsProcessor)1 PerlParserExtensions (com.perl5.lang.perl.idea.application.PerlParserExtensions)1 PerlNamesCache (com.perl5.lang.perl.idea.project.PerlNamesCache)1 ClassAccessorParserExtension (com.perl5.lang.perl.parser.ClassAccessorParserExtension)1