mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved rest dependent code from python to python-rest
This commit is contained in:
@@ -43,7 +43,8 @@ setProperty("pluginFilter", [
|
||||
"python-remote-interpreter",
|
||||
"diagram-api", "uml",
|
||||
"python-uml", "localization",
|
||||
"python-localization", "rest"
|
||||
"python-localization",
|
||||
"rest", "python-rest"
|
||||
])
|
||||
|
||||
private List<String> pycharmPlatformApiModules() {
|
||||
@@ -373,6 +374,13 @@ private layoutFull(Map args, String target, Set usedJars) {
|
||||
}
|
||||
}
|
||||
}
|
||||
dir("python-rest") {
|
||||
dir("lib") {
|
||||
jar("python-rest.jar") {
|
||||
module("python-rest")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def layouts = includeFile("$home/build/scripts/layouts.gant")
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<orderEntry type="module" module-name="localization" />
|
||||
<orderEntry type="module" module-name="rest" />
|
||||
<orderEntry type="module" module-name="python-localization" />
|
||||
<orderEntry type="module" module-name="python-rest" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="module" module-name="rest" />
|
||||
<orderEntry type="module" module-name="python" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
<orderEntry type="module" module-name="testFramework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="python-tests" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<idea-plugin version="2" xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<name>Python ReStructureText Integration</name>
|
||||
<id>org.jetbrains.plugins.python-rest</id>
|
||||
<version>VERSION</version>
|
||||
<vendor logo="/general/ijLogo.png">JetBrains</vendor>
|
||||
|
||||
<depends>com.intellij.modules.ultimate</depends>
|
||||
<depends>com.intellij.modules.python</depends>
|
||||
<depends>org.jetbrains.plugins.rest</depends>
|
||||
|
||||
<xi:include href="/META-INF/python-rest.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,25 @@
|
||||
<idea-plugin version="2">
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
<lang.fileViewProviderFactory language="ReST"
|
||||
implementationClass="com.jetbrains.rest.RestFileProviderFactory"/>
|
||||
<editorHighlighterProvider filetype="ReST" implementationClass="com.jetbrains.rest.RestEditorHighlighterProvider"/>
|
||||
|
||||
<localInspection language="ReST" shortName="RestRoleInspection" bundle="com.jetbrains.rest.RestBundle" key="INSP.role.not.defined"
|
||||
groupKey="INSP.GROUP.rest" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.jetbrains.rest.inspections.RestRoleInspection"/>
|
||||
|
||||
<configurationType implementation="com.jetbrains.rest.run.RestRunConfigurationType"/>
|
||||
<configurationProducer implementation="com.jetbrains.rest.run.docutils.DocutilsConfigurationProducer"/>
|
||||
<configurationProducer implementation="com.jetbrains.rest.run.sphinx.SphinxConfigurationProducer"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<action id="com.jetbrains.rest.sphinx.RunSphinxQuickStartAction"
|
||||
class="com.jetbrains.rest.sphinx.RunSphinxQuickStartAction"
|
||||
text="Sphinx quickstart" description="Allows to run sphinx quick-start action">
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.ex.util.LayerDescriptor;
|
||||
import com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
|
||||
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.django.lang.template.DjangoTemplateFileType;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Enables python highlighting for Rest files
|
||||
*
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestEditorHighlighter extends LayeredLexerEditorHighlighter {
|
||||
|
||||
public RestEditorHighlighter(@NotNull EditorColorsScheme scheme, @Nullable Project project, @Nullable VirtualFile file) {
|
||||
super(SyntaxHighlighterFactory.getSyntaxHighlighter(RestLanguage.INSTANCE, project, file), scheme);
|
||||
|
||||
registerLayer(RestTokenTypes.PYTHON_LINE, new LayerDescriptor(
|
||||
SyntaxHighlighter.PROVIDER.create(PythonFileType.INSTANCE, project, file), "", EditorColors.INJECTED_LANGUAGE_FRAGMENT));
|
||||
|
||||
registerLayer(RestTokenTypes.DJANGO_LINE, new LayerDescriptor(
|
||||
SyntaxHighlighter.PROVIDER.create(DjangoTemplateFileType.INSTANCE, project, file), "", EditorColors.INJECTED_LANGUAGE_FRAGMENT));
|
||||
|
||||
|
||||
registerLayer(RestTokenTypes.JAVASCRIPT_LINE, new LayerDescriptor(
|
||||
SyntaxHighlighter.PROVIDER.create(StdFileTypes.JS, project, file), "", EditorColors.INJECTED_LANGUAGE_FRAGMENT));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
|
||||
import com.intellij.openapi.fileTypes.EditorHighlighterProvider;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestEditorHighlighterProvider implements EditorHighlighterProvider {
|
||||
@Override
|
||||
public EditorHighlighter getEditorHighlighter(@Nullable Project project,
|
||||
@NotNull FileType fileType,
|
||||
@Nullable VirtualFile virtualFile,
|
||||
@NotNull EditorColorsScheme colors) {
|
||||
return new RestEditorHighlighter(colors, project, virtualFile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.FileViewProviderFactory;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestFileProviderFactory implements FileViewProviderFactory {
|
||||
|
||||
public FileViewProvider createFileViewProvider(@NotNull VirtualFile virtualFile, Language language, @NotNull PsiManager psiManager, boolean physical) {
|
||||
return new RestFileViewProvider(psiManager, virtualFile, physical);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageParserDefinitions;
|
||||
import com.intellij.lang.ParserDefinition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
|
||||
import com.jetbrains.django.lang.template.DjangoTemplateLanguage;
|
||||
import com.jetbrains.python.PythonLanguage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestFileViewProvider extends MultiplePsiFilesPerDocumentFileViewProvider
|
||||
implements TemplateLanguageFileViewProvider {
|
||||
|
||||
private Set<Language> myLanguages;
|
||||
|
||||
public RestFileViewProvider(PsiManager manager, VirtualFile virtualFile, boolean physical) {
|
||||
super(manager, virtualFile, physical);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Language getBaseLanguage() {
|
||||
return RestLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Language getTemplateDataLanguage() {
|
||||
return PythonLanguage.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MultiplePsiFilesPerDocumentFileViewProvider cloneInner(VirtualFile virtualFile) {
|
||||
return new RestFileViewProvider(getManager(), virtualFile, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<Language> getLanguages() {
|
||||
if (myLanguages == null) {
|
||||
myLanguages = Sets.newLinkedHashSet();
|
||||
myLanguages.add(getBaseLanguage());
|
||||
myLanguages.add(DjangoTemplateLanguage.INSTANCE);
|
||||
myLanguages.add(getTemplateDataLanguage());
|
||||
}
|
||||
return myLanguages;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiFile createFile(@NotNull final Language lang) {
|
||||
ParserDefinition def = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
|
||||
if (def == null) return null;
|
||||
if (lang == getTemplateDataLanguage()) {
|
||||
PsiFileImpl file = (PsiFileImpl)def.createFile(this);
|
||||
file.setContentElementType(RestPythonElementTypes.PYTHON_BLOCK_DATA);
|
||||
return file;
|
||||
}
|
||||
else if (lang == DjangoTemplateLanguage.INSTANCE) {
|
||||
PsiFileImpl file = (PsiFileImpl)def.createFile(this);
|
||||
file.setContentElementType(RestPythonElementTypes.DJANGO_BLOCK_DATA);
|
||||
return file;
|
||||
}
|
||||
else if (lang == RestLanguage.INSTANCE) {
|
||||
return def.createFile(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.psi.templateLanguages.TemplateDataElementType;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public interface RestPythonElementTypes {
|
||||
TemplateDataElementType PYTHON_BLOCK_DATA = new RestPythonTemplateType("PYTHON_BLOCK_DATA", RestLanguage.INSTANCE,
|
||||
RestTokenTypes.PYTHON_LINE, RestTokenTypes.REST_INJECTION);
|
||||
|
||||
TemplateDataElementType DJANGO_BLOCK_DATA = new RestPythonTemplateType("DJANGO_BLOCK_DATA", RestLanguage.INSTANCE,
|
||||
RestTokenTypes.DJANGO_LINE, RestTokenTypes.REST_DJANGO_INJECTION);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
|
||||
*/
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.psi.templateLanguages.TemplateDataElementType;
|
||||
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
|
||||
import com.jetbrains.python.lexer.PythonHighlightingLexer;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestPythonTemplateType extends TemplateDataElementType {
|
||||
|
||||
public RestPythonTemplateType(String python_block_data, RestLanguage instance, RestElementType line, RestElementType restInjection) {
|
||||
super(python_block_data, instance, line, restInjection);
|
||||
}
|
||||
|
||||
protected Lexer createBaseLexer(final TemplateLanguageFileViewProvider viewProvider) {
|
||||
final Lexer baseLexer = new PythonHighlightingLexer(LanguageLevel.getDefault());
|
||||
return baseLexer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestPythonUtil {
|
||||
private RestPythonUtil() {}
|
||||
|
||||
public static Presentation updateDocutilRequiredAction(final AnActionEvent e) {
|
||||
return updateRequirements(e, "rst2html.py");
|
||||
}
|
||||
|
||||
public static Presentation updateRequirements(final AnActionEvent e, String runner) {
|
||||
final Presentation presentation = e.getPresentation();
|
||||
presentation.setVisible(false);
|
||||
presentation.setEnabled(false);
|
||||
final Project project = e.getData(PlatformDataKeys.PROJECT);
|
||||
if (project != null) {
|
||||
Module module = e.getData(LangDataKeys.MODULE);
|
||||
if (module == null) {
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
module = modules.length == 0 ? null : modules [0];
|
||||
}
|
||||
if (module != null) {
|
||||
Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk != null) {
|
||||
String htmlRunner = RestUtil.findRunner(sdk.getHomePath(), runner);
|
||||
if (htmlRunner != null) {
|
||||
presentation.setVisible(true);
|
||||
presentation.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return presentation;
|
||||
}
|
||||
|
||||
public static Presentation updateSphinxBuildRequiredAction(final AnActionEvent e) {
|
||||
return updateRequirements(e, "sphinx-build"+ (SystemInfo.isWindows ? ".exe" : ""));
|
||||
}
|
||||
|
||||
public static Presentation updateSphinxQuickStartRequiredAction(final AnActionEvent e) {
|
||||
return updateRequirements(e, "sphinx-quickstart"+ (SystemInfo.isWindows ? ".exe" : ""));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.jetbrains.rest.inspections;
|
||||
|
||||
import com.intellij.codeInspection.CustomSuppressableInspectionTool;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.SuppressIntentionAction;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.rest.RestBundle;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public abstract class RestInspection extends LocalInspectionTool implements CustomSuppressableInspectionTool {
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupDisplayName() {
|
||||
return RestBundle.message("INSP.GROUP.rest");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressedFor(PsiElement element) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.jetbrains.rest.inspections;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.ProblemDescriptorImpl;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.rest.validation.RestElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public abstract class RestInspectionVisitor extends RestElementVisitor {
|
||||
@Nullable private final ProblemsHolder myHolder;
|
||||
public RestInspectionVisitor(@Nullable final ProblemsHolder holder) {
|
||||
myHolder = holder;
|
||||
}
|
||||
|
||||
public RestInspectionVisitor(@Nullable ProblemsHolder problemsHolder,
|
||||
@NotNull LocalInspectionToolSession session) {
|
||||
myHolder = problemsHolder;
|
||||
}
|
||||
|
||||
@Nullable protected ProblemsHolder getHolder() {
|
||||
return myHolder;
|
||||
}
|
||||
|
||||
protected final void registerProblem(final PsiElement element,
|
||||
final String message){
|
||||
if (element == null || element.getTextLength() == 0){
|
||||
return;
|
||||
}
|
||||
if (myHolder != null) {
|
||||
myHolder.registerProblem(element, message);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerProblem(@Nullable final PsiElement element,
|
||||
@NotNull final String message,
|
||||
@NotNull final LocalQuickFix quickFix){
|
||||
if (element == null || element.getTextLength() == 0){
|
||||
return;
|
||||
}
|
||||
if (myHolder != null) {
|
||||
myHolder.registerProblem(element, message, quickFix);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerProblem(final PsiElement element,
|
||||
final String message,
|
||||
final ProblemHighlightType type,
|
||||
final HintAction action) {
|
||||
if (element == null || element.getTextLength() == 0){
|
||||
return;
|
||||
}
|
||||
if (myHolder != null) {
|
||||
myHolder.registerProblem(myHolder.getManager().createProblemDescriptor(element, message, type, action, myHolder.isOnTheFly()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The most full-blown version.
|
||||
* @see com.intellij.codeInspection.ProblemDescriptor
|
||||
*/
|
||||
protected final void registerProblem(
|
||||
@NotNull final PsiElement psiElement,
|
||||
@NotNull final String descriptionTemplate,
|
||||
final ProblemHighlightType highlightType,
|
||||
@Nullable final HintAction hintAction,
|
||||
final LocalQuickFix... fixes) {
|
||||
registerProblem(psiElement, descriptionTemplate, highlightType, hintAction, null, fixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The most full-blown version.
|
||||
* @see com.intellij.codeInspection.ProblemDescriptor
|
||||
*/
|
||||
protected final void registerProblem(
|
||||
@NotNull final PsiElement psiElement,
|
||||
@NotNull final String descriptionTemplate,
|
||||
final ProblemHighlightType highlightType,
|
||||
@Nullable final HintAction hintAction,
|
||||
@Nullable final TextRange rangeInElement,
|
||||
final LocalQuickFix... fixes)
|
||||
{
|
||||
if (myHolder != null) {
|
||||
myHolder.registerProblem(new ProblemDescriptorImpl(psiElement, psiElement, descriptionTemplate, fixes, highlightType, false,
|
||||
rangeInElement, hintAction, myHolder.isOnTheFly()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.jetbrains.rest.inspections;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ui.ListEditForm;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.JDOMExternalizableStringList;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.rest.*;
|
||||
import com.jetbrains.rest.psi.RestDirectiveBlock;
|
||||
import com.jetbrains.rest.psi.RestRole;
|
||||
import com.jetbrains.rest.quickfixes.AddIgnoredRoleFix;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User: catherine
|
||||
*
|
||||
* Looks for using not defined roles
|
||||
*/
|
||||
public class RestRoleInspection extends RestInspection {
|
||||
public JDOMExternalizableStringList ignoredRoles = new JDOMExternalizableStringList();
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return RestBundle.message("INSP.role.not.defined");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
return new Visitor(holder, ignoredRoles);
|
||||
}
|
||||
|
||||
private class Visitor extends RestInspectionVisitor {
|
||||
private final ImmutableSet<String> myIgnoredRoles;
|
||||
Set<String> mySphinxRoles = new HashSet<String>();
|
||||
|
||||
public Visitor(final ProblemsHolder holder, List<String> ignoredRoles) {
|
||||
super(holder);
|
||||
myIgnoredRoles = ImmutableSet.copyOf(ignoredRoles);
|
||||
Project project = holder.getProject();
|
||||
String dir = ReSTService.getInstance(project).getWorkdir();
|
||||
if (!dir.isEmpty())
|
||||
fillSphinxRoles(dir, project);
|
||||
}
|
||||
|
||||
private void fillSphinxRoles(String dir, Project project) {
|
||||
VirtualFile config = LocalFileSystem.getInstance().findFileByPath((dir.endsWith("/")?dir:dir+"/")+"conf.py");
|
||||
if (config == null) return;
|
||||
|
||||
PsiFile configFile = PsiManager.getInstance(project).findFile(config);
|
||||
if (configFile instanceof PyFile) {
|
||||
PyFile file = (PyFile)configFile;
|
||||
List<PyFunction> functions = file.getTopLevelFunctions();
|
||||
for (PyFunction function : functions) {
|
||||
if (!"setup".equals(function.getName())) continue;
|
||||
PyStatementList stList = function.getStatementList();
|
||||
if (stList != null) {
|
||||
PyStatement[] statements = stList.getStatements();
|
||||
for (PyElement statement : statements) {
|
||||
if (statement instanceof PyExpressionStatement)
|
||||
statement = ((PyExpressionStatement)statement).getExpression();
|
||||
if (statement instanceof PyCallExpression) {
|
||||
if (((PyCallExpression)statement).isCalleeText("add_role")) {
|
||||
PyExpression arg = ((PyCallExpression)statement).getArguments()[0];
|
||||
if (arg instanceof PyStringLiteralExpression)
|
||||
mySphinxRoles.add(((PyStringLiteralExpression)arg).getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitRole(final RestRole node) {
|
||||
RestFile file = (RestFile)node.getContainingFile();
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(node, RestDirectiveBlock.class) != null) return;
|
||||
if (node.getNextSibling() == null || node.getNextSibling().getNode().getElementType() != RestTokenTypes.INTERPRETED) return;
|
||||
if (RestUtil.PREDEFINED_ROLES.contains(node.getText()) || myIgnoredRoles.contains(node.getRoleName()))
|
||||
return;
|
||||
|
||||
Sdk sdk = ProjectRootManager.getInstance(node.getProject()).getProjectSdk();
|
||||
if (sdk != null) {
|
||||
String sphinx = RestUtil.findRunner(sdk.getHomePath(), "sphinx-quickstart" + (SystemInfo.isWindows ? ".exe" : ""));
|
||||
if (sphinx != null && !sphinx.isEmpty()) {
|
||||
if (RestUtil.SPHINX_ROLES.contains(node.getText()) || RestUtil.SPHINX_ROLES.contains(":py"+node.getText())
|
||||
|| mySphinxRoles.contains(node.getRoleName())) return;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> definedRoles = new HashSet<String>();
|
||||
|
||||
RestDirectiveBlock[] directives = PsiTreeUtil.getChildrenOfType(file, RestDirectiveBlock.class);
|
||||
if (directives != null) {
|
||||
for (RestDirectiveBlock block : directives) {
|
||||
if (block.getDirectiveName().equals("role::")) {
|
||||
PsiElement role = block.getFirstChild().getNextSibling();
|
||||
if (role != null) {
|
||||
String roleName = role.getText().trim();
|
||||
int index = roleName.indexOf('(');
|
||||
if (index != -1)
|
||||
roleName = roleName.substring(0, index);
|
||||
definedRoles.add(roleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (definedRoles.contains(node.getRoleName())) return;
|
||||
registerProblem(node, "Not defined role '" + node.getRoleName() + "'", new AddIgnoredRoleFix(node.getRoleName(), RestRoleInspection.this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
ListEditForm form = new ListEditForm("Ignore roles", ignoredRoles);
|
||||
return form.getContentPanel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jetbrains.rest.quickfixes;
|
||||
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.jetbrains.rest.RestBundle;
|
||||
import com.jetbrains.rest.inspections.RestRoleInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class AddIgnoredRoleFix implements LocalQuickFix, LowPriorityAction {
|
||||
private final String myRole;
|
||||
private RestRoleInspection myInspection;
|
||||
|
||||
public AddIgnoredRoleFix(String role, RestRoleInspection visitor) {
|
||||
myRole = role;
|
||||
myInspection = visitor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return RestBundle.message("QFIX.ignore.role", myRole);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return "Ignore undefined role";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
if (!myInspection.ignoredRoles.contains(myRole)) {
|
||||
myInspection.ignoredRoles.add(myRole);
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
InspectionProfileManager.getInstance().fireProfileChanged(profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.jetbrains.rest.run;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.execution.configurations.ParamsGroup;
|
||||
import com.intellij.execution.filters.Filter;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.jetbrains.python.run.PythonCommandLineState;
|
||||
import com.jetbrains.python.run.PythonProcessRunner;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public abstract class RestCommandLineState extends PythonCommandLineState {
|
||||
protected final RestRunConfiguration myConfiguration;
|
||||
|
||||
public RestCommandLineState(RestRunConfiguration configuration,
|
||||
ExecutionEnvironment env) {
|
||||
super(configuration, env, Collections.<Filter>emptyList());
|
||||
myConfiguration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildCommandLineParameters(GeneralCommandLine commandLine) {
|
||||
ParametersList parametersList = commandLine.getParametersList();
|
||||
ParamsGroup exe_options = parametersList.getParamsGroup(GROUP_EXE_OPTIONS);
|
||||
assert exe_options != null;
|
||||
exe_options.addParametersString(myConfiguration.getInterpreterOptions());
|
||||
|
||||
ParamsGroup script_parameters = parametersList.getParamsGroup(GROUP_SCRIPT);
|
||||
assert script_parameters != null;
|
||||
String runner = PythonHelpersLocator.getHelperPath(getRunnerPath());
|
||||
if (runner != null )
|
||||
script_parameters.addParameter(runner);
|
||||
final String key = getKey();
|
||||
if (key != null)
|
||||
script_parameters.addParameter(key);
|
||||
script_parameters.addParameter(getTask());
|
||||
|
||||
final String params = myConfiguration.getParams();
|
||||
if (params != null) script_parameters.addParametersString(params);
|
||||
|
||||
if (!StringUtil.isEmptyOrSpaces(myConfiguration.getInputFile()))
|
||||
script_parameters.addParameter(myConfiguration.getInputFile());
|
||||
|
||||
if (!StringUtil.isEmptyOrSpaces(myConfiguration.getOutputFile()))
|
||||
script_parameters.addParameter(myConfiguration.getOutputFile());
|
||||
|
||||
if (!StringUtil.isEmptyOrSpaces(myConfiguration.getWorkingDirectory()))
|
||||
commandLine.setWorkDirectory(myConfiguration.getWorkingDirectory());
|
||||
}
|
||||
|
||||
protected ProcessHandler doCreateProcess(GeneralCommandLine commandLine) throws ExecutionException {
|
||||
final Runnable afterTask = getAfterTask();
|
||||
ProcessHandler processHandler = PythonProcessRunner.createProcess(commandLine);
|
||||
if (afterTask != null) {
|
||||
processHandler.addProcessListener(new ProcessAdapter() {
|
||||
public void processTerminated(ProcessEvent event) {
|
||||
SwingUtilities.invokeLater(afterTask);
|
||||
}});
|
||||
}
|
||||
return processHandler;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Runnable getAfterTask() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected VirtualFile findOutput() {
|
||||
if (!StringUtil.isEmptyOrSpaces(myConfiguration.getOutputFile())) {
|
||||
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(
|
||||
myConfiguration.getOutputFile());
|
||||
if (virtualFile == null) {
|
||||
virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(
|
||||
myConfiguration.getWorkingDirectory() + myConfiguration.getOutputFile());
|
||||
}
|
||||
return virtualFile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract String getRunnerPath();
|
||||
|
||||
protected abstract String getTask();
|
||||
|
||||
@Nullable
|
||||
protected abstract String getKey();
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.rest.run.RestConfigurationEditor">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="214" width="495" height="228"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="f4532" binding="myCommonOptionsPlaceholder" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="f43db" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="com/jetbrains/rest/RestBundle" key="runcfg.docutils.input"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a5967" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myInputFileField">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="e950" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value=""/>
|
||||
<text resource-bundle="com/jetbrains/rest/RestBundle" key="runcfg.docutils.options"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="32bc2" class="javax.swing.JTextField" binding="myParamsTextField">
|
||||
<constraints>
|
||||
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="1830d" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="com/jetbrains/rest/RestBundle" key="runcfg.docutils.output"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="277a" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myOutputFileField">
|
||||
<constraints>
|
||||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="bfbc2" class="javax.swing.JCheckBox" binding="myOpenInBrowser" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Open output file in browser"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="eee9" class="javax.swing.JComboBox" binding="myTasks">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="996f1" class="com.intellij.ui.components.JBLabel" binding="myCommandLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="com/jetbrains/rest/RestBundle" key="runcfg.docutils.command"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="693f8" class="javax.swing.JSeparator">
|
||||
<constraints>
|
||||
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="7" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<hspacer id="93e6">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="20" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="d213c" class="javax.swing.JLabel" binding="myConfigurationName">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font style="1"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.jetbrains.rest.run;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.ui.CollectionComboBoxModel;
|
||||
import com.intellij.ui.PanelWithAnchor;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.jetbrains.python.run.AbstractPyCommonOptionsForm;
|
||||
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
|
||||
import com.jetbrains.python.run.PyCommonOptionsFormFactory;
|
||||
import com.jetbrains.rest.RestBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* Users : catherine
|
||||
*/
|
||||
public class RestConfigurationEditor extends SettingsEditor<RestRunConfiguration> implements PanelWithAnchor {
|
||||
private JPanel myMainPanel;
|
||||
private JPanel myCommonOptionsPlaceholder;
|
||||
private TextFieldWithBrowseButton myInputFileField;
|
||||
private JTextField myParamsTextField;
|
||||
private JCheckBox myOpenInBrowser;
|
||||
private TextFieldWithBrowseButton myOutputFileField;
|
||||
private JComboBox myTasks;
|
||||
private JBLabel myCommandLabel;
|
||||
private JLabel myConfigurationName;
|
||||
private final AbstractPyCommonOptionsForm myCommonOptionsForm;
|
||||
private Project myProject;
|
||||
private JComponent anchor;
|
||||
|
||||
public RestConfigurationEditor(final Project project,
|
||||
AbstractPythonRunConfiguration configuration,
|
||||
CollectionComboBoxModel model) {
|
||||
myCommonOptionsForm = PyCommonOptionsFormFactory.getInstance().createForm(configuration.getCommonOptionsFormData());
|
||||
myCommonOptionsPlaceholder.add(myCommonOptionsForm.getMainPanel());
|
||||
myProject = project;
|
||||
myTasks.setModel(model);
|
||||
myTasks.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
Object task = myTasks.getSelectedItem();
|
||||
if (task != null &&
|
||||
(task.toString().equals("rst2latex") ||
|
||||
task.toString().equals("rst2odt")))
|
||||
myOpenInBrowser.setEnabled(false);
|
||||
else
|
||||
myOpenInBrowser.setEnabled(true);
|
||||
}
|
||||
});
|
||||
myOpenInBrowser.setSelected(false);
|
||||
|
||||
setAnchor(myCommonOptionsForm.getAnchor());
|
||||
}
|
||||
|
||||
protected void resetEditorFrom(RestRunConfiguration configuration) {
|
||||
AbstractPythonRunConfiguration.copyParams(configuration,
|
||||
myCommonOptionsForm);
|
||||
myInputFileField.setText(configuration.getInputFile());
|
||||
myOutputFileField.setText(configuration.getOutputFile());
|
||||
myParamsTextField.setText(configuration.getParams());
|
||||
myTasks.setSelectedItem(configuration.getTask());
|
||||
myOpenInBrowser.setSelected(configuration.openInBrowser());
|
||||
if (configuration.getTask().equals("rst2latex")
|
||||
|| configuration.getTask().equals("rst2odt"))
|
||||
myOpenInBrowser.setEnabled(false);
|
||||
else
|
||||
myOpenInBrowser.setEnabled(true);
|
||||
}
|
||||
|
||||
protected void applyEditorTo(RestRunConfiguration configuration) throws ConfigurationException {
|
||||
AbstractPythonRunConfiguration.copyParams(myCommonOptionsForm, configuration);
|
||||
configuration.setInputFile(myInputFileField.getText().trim());
|
||||
configuration.setOutputFile(myOutputFileField.getText().trim());
|
||||
configuration.setParams(myParamsTextField.getText().trim());
|
||||
Object task = myTasks.getSelectedItem();
|
||||
if (task != null)
|
||||
configuration.setTask(task.toString());
|
||||
|
||||
|
||||
configuration.setOpenInBrowser(myOpenInBrowser.isSelected());
|
||||
if (!myOpenInBrowser.isEnabled())
|
||||
configuration.setOpenInBrowser(false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JComponent createEditor() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
protected void disposeEditor() {
|
||||
}
|
||||
|
||||
public void setOpenInBrowserVisible(boolean visible) {
|
||||
myOpenInBrowser.setVisible(visible);
|
||||
}
|
||||
|
||||
public void setInputDescriptor(FileChooserDescriptor descriptor) {
|
||||
String title = RestBundle.message("runcfg.dlg.select.script.path");
|
||||
myInputFileField.addBrowseFolderListener(title, null, myProject, descriptor);
|
||||
}
|
||||
|
||||
public void setOutputDescriptor(FileChooserDescriptor descriptor) {
|
||||
String title = RestBundle.message("runcfg.dlg.select.script.path");
|
||||
myOutputFileField.addBrowseFolderListener(title, null, myProject, descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getAnchor() {
|
||||
return anchor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchor(@Nullable JComponent anchor) {
|
||||
this.anchor = anchor;
|
||||
myCommandLabel.setAnchor(anchor);
|
||||
myCommonOptionsForm.setAnchor(anchor);
|
||||
}
|
||||
|
||||
public void setConfigurationName(String name) {
|
||||
myConfigurationName.setText(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.jetbrains.rest.run;
|
||||
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.execution.configurations.RunConfigurationModule;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizerUtil;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public abstract class RestRunConfiguration extends AbstractPythonRunConfiguration {
|
||||
private String myInputFile = "";
|
||||
private String myOutputFile = "";
|
||||
private String myParams = "";
|
||||
private String myTask = "";
|
||||
private boolean openInBrowser = false;
|
||||
|
||||
private static final String INPUT_FILE_FIELD = "docutils_input_file";
|
||||
private static final String OUTPUT_FILE_FIELD = "docutils_output_file";
|
||||
private static final String PARAMS_FIELD = "docutils_params";
|
||||
private static final String TASK = "docutils_task";
|
||||
private static final String OPEN_IN_BROWSER = "docutils_open_in_browser";
|
||||
|
||||
public RestRunConfiguration(final String name,
|
||||
final RunConfigurationModule module,
|
||||
final ConfigurationFactory factory) {
|
||||
super(name, module, factory);
|
||||
}
|
||||
|
||||
public String getInputFile() {
|
||||
return myInputFile;
|
||||
}
|
||||
|
||||
public void setInputFile(String inputFile) {
|
||||
myInputFile = inputFile;
|
||||
}
|
||||
|
||||
public String getOutputFile() {
|
||||
return myOutputFile;
|
||||
}
|
||||
|
||||
public void setOutputFile(String file) {
|
||||
myOutputFile = file;
|
||||
}
|
||||
|
||||
public void setParams(String params) {
|
||||
myParams = params;
|
||||
}
|
||||
|
||||
public String getParams() {
|
||||
return myParams;
|
||||
}
|
||||
|
||||
public String getTask() {
|
||||
return myTask;
|
||||
}
|
||||
|
||||
public void setTask(Object task) {
|
||||
if (task != null) myTask = task.toString();
|
||||
else myTask = "rst2html";
|
||||
}
|
||||
|
||||
public void setOpenInBrowser(boolean open) {
|
||||
openInBrowser = open;
|
||||
}
|
||||
|
||||
public boolean openInBrowser() {
|
||||
return openInBrowser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
super.readExternal(element);
|
||||
myInputFile = JDOMExternalizerUtil.readField(element, INPUT_FILE_FIELD);
|
||||
myOutputFile = JDOMExternalizerUtil.readField(element, OUTPUT_FILE_FIELD);
|
||||
myParams = JDOMExternalizerUtil.readField(element, PARAMS_FIELD);
|
||||
myTask = JDOMExternalizerUtil.readField(element, TASK);
|
||||
openInBrowser = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, OPEN_IN_BROWSER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
super.writeExternal(element);
|
||||
JDOMExternalizerUtil.writeField(element, INPUT_FILE_FIELD, myInputFile);
|
||||
JDOMExternalizerUtil.writeField(element, OUTPUT_FILE_FIELD, myOutputFile);
|
||||
JDOMExternalizerUtil.writeField(element, PARAMS_FIELD, myParams);
|
||||
JDOMExternalizerUtil.writeField(element, TASK, myTask);
|
||||
JDOMExternalizerUtil.writeField(element, OPEN_IN_BROWSER, String.valueOf(openInBrowser));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRunWithCoverage() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.jetbrains.rest.run;
|
||||
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.jetbrains.rest.RestBundle;
|
||||
import com.jetbrains.rest.RestFileType;
|
||||
import com.jetbrains.rest.run.docutils.DocutilsRunConfiguration;
|
||||
import com.jetbrains.rest.run.sphinx.SphinxRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestRunConfigurationType implements ConfigurationType {
|
||||
public final ConfigurationFactory DOCUTILS_FACTORY = new DocutilsRunConfigurationFactory(this);
|
||||
public final ConfigurationFactory SPHINX_FACTORY = new SphinxRunConfigurationFactory(this);
|
||||
|
||||
private String myId = "docs";
|
||||
|
||||
public String getDisplayName() {
|
||||
return RestBundle.message("runcfg.docutils.display_name");
|
||||
}
|
||||
|
||||
public static RestRunConfigurationType getInstance() {
|
||||
return ConfigurationTypeUtil.findConfigurationType(RestRunConfigurationType.class);
|
||||
}
|
||||
|
||||
public String getConfigurationTypeDescription() {
|
||||
return RestBundle.message("runcfg.docutils.description");
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return RestFileType.INSTANCE.getIcon();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public ConfigurationFactory[] getConfigurationFactories() {
|
||||
return new ConfigurationFactory[] {DOCUTILS_FACTORY, SPHINX_FACTORY};
|
||||
}
|
||||
|
||||
private static abstract class RestConfigurationFactory extends ConfigurationFactory {
|
||||
private final String myName;
|
||||
|
||||
public RestConfigurationFactory(@NotNull final ConfigurationType type, @NotNull String name) {
|
||||
super(type);
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DocutilsRunConfigurationFactory extends RestConfigurationFactory {
|
||||
protected DocutilsRunConfigurationFactory(ConfigurationType type) {
|
||||
super(type, "Docutils task");
|
||||
}
|
||||
|
||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
||||
return new DocutilsRunConfiguration("", new RunConfigurationModule(project), this);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SphinxRunConfigurationFactory extends RestConfigurationFactory {
|
||||
protected SphinxRunConfigurationFactory(ConfigurationType type) {
|
||||
super(type, "Sphinx task");
|
||||
}
|
||||
|
||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
||||
return new SphinxRunConfiguration("", new RunConfigurationModule(project), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.jetbrains.rest.run.docutils;
|
||||
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.rest.run.RestCommandLineState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class DocutilsCommandLineState extends RestCommandLineState {
|
||||
|
||||
public DocutilsCommandLineState(DocutilsRunConfiguration configuration,
|
||||
ExecutionEnvironment env) {
|
||||
super(configuration, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Runnable getAfterTask() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VirtualFile virtualFile = findOutput();
|
||||
if (virtualFile != null) {
|
||||
if (myConfiguration.openInBrowser()) {
|
||||
BrowserUtil.launchBrowser(virtualFile.getUrl());
|
||||
}
|
||||
else {
|
||||
FileEditorManager.getInstance(myConfiguration.getProject()).openFile(virtualFile, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRunnerPath() {
|
||||
return "rest_runners/rst2smth.py";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTask() {
|
||||
return myConfiguration.getTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected String getKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package com.jetbrains.rest.run.docutils;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.execution.actions.ConfigurationContext;
|
||||
import com.intellij.execution.junit.RuntimeConfigurationProducer;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.rest.RestFileType;
|
||||
import com.jetbrains.rest.run.RestRunConfiguration;
|
||||
import com.jetbrains.rest.run.RestRunConfigurationType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class DocutilsConfigurationProducer extends RuntimeConfigurationProducer implements Cloneable {
|
||||
private PsiFile mySourceFile = null;
|
||||
|
||||
public DocutilsConfigurationProducer() {
|
||||
super(RestRunConfigurationType.getInstance().DOCUTILS_FACTORY);
|
||||
}
|
||||
|
||||
public PsiElement getSourceElement() {
|
||||
return mySourceFile;
|
||||
}
|
||||
|
||||
protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
|
||||
PsiFile script = location.getPsiElement().getContainingFile();
|
||||
if (script == null || script.getFileType() != RestFileType.INSTANCE) {
|
||||
return null;
|
||||
}
|
||||
Module module = ModuleUtil.findModuleForPsiElement(script);
|
||||
mySourceFile = script;
|
||||
|
||||
final Project project = mySourceFile.getProject();
|
||||
RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
|
||||
DocutilsRunConfiguration configuration = (DocutilsRunConfiguration) settings.getConfiguration();
|
||||
final VirtualFile vFile = mySourceFile.getVirtualFile();
|
||||
if (vFile == null) return null;
|
||||
configuration.setInputFile(vFile.getPath());
|
||||
configuration.setName(script.getName());
|
||||
|
||||
String outputPath = vFile.getPath();
|
||||
int index = outputPath.lastIndexOf('.');
|
||||
if (index > 0) outputPath = outputPath.substring(0, index);
|
||||
outputPath += ".html";
|
||||
VirtualFile outputFile = LocalFileSystem.getInstance().findFileByPath(outputPath);
|
||||
if (outputFile == null) {
|
||||
configuration.setOutputFile(outputPath);
|
||||
configuration.setOpenInBrowser(true);
|
||||
}
|
||||
|
||||
if (configuration.getTask().isEmpty())
|
||||
configuration.setTask("rst2html");
|
||||
final VirtualFile parent = vFile.getParent();
|
||||
if (parent != null) {
|
||||
configuration.setWorkingDirectory(parent.getPath());
|
||||
}
|
||||
configuration.setName(configuration.suggestedName());
|
||||
if (module != null) {
|
||||
configuration.setUseModuleSdk(true);
|
||||
configuration.setModule(module);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RunnerAndConfigurationSettings findExistingByElement(Location location,
|
||||
@NotNull RunnerAndConfigurationSettings[] existingConfigurations,
|
||||
ConfigurationContext context) {
|
||||
PsiFile script = location.getPsiElement().getContainingFile();
|
||||
if (script == null) {
|
||||
return null;
|
||||
}
|
||||
final VirtualFile vFile = script.getVirtualFile();
|
||||
if (vFile == null) {
|
||||
return null;
|
||||
}
|
||||
String path = vFile.getPath();
|
||||
for (RunnerAndConfigurationSettings configuration : existingConfigurations) {
|
||||
final String scriptName = ((RestRunConfiguration)configuration.getConfiguration()).getInputFile();
|
||||
if (FileUtil.toSystemIndependentName(scriptName).equals(FileUtil.toSystemIndependentName(path))) {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int compareTo(final Object o) {
|
||||
return PREFERED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.jetbrains.rest.run.docutils;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.Executor;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.jetbrains.rest.run.RestConfigurationEditor;
|
||||
import com.jetbrains.rest.run.RestRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class DocutilsRunConfiguration extends RestRunConfiguration {
|
||||
|
||||
public DocutilsRunConfiguration(final String name,
|
||||
final RunConfigurationModule module,
|
||||
final ConfigurationFactory factory) {
|
||||
super(name, module, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModuleBasedConfiguration createInstance() {
|
||||
return new DocutilsRunConfiguration(getName(), getConfigurationModule(), getFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SettingsEditor<? extends RunConfiguration> createConfigurationEditor() {
|
||||
RestConfigurationEditor editor = new RestConfigurationEditor(getProject(), this, new DocutilsTasksModel());
|
||||
editor.setConfigurationName("Docutils task");
|
||||
editor.setInputDescriptor(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
|
||||
editor.setOutputDescriptor(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
return new DocutilsCommandLineState(this, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkConfiguration() throws RuntimeConfigurationException {
|
||||
super.checkConfiguration();
|
||||
if (StringUtil.isEmptyOrSpaces(getInputFile()))
|
||||
throw new RuntimeConfigurationError("Please specify input file name.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String suggestedName() {
|
||||
return "docutils task in " + getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.jetbrains.rest.run.docutils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.ui.CollectionComboBoxModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class DocutilsTasksModel extends CollectionComboBoxModel {
|
||||
public DocutilsTasksModel() {
|
||||
super(getTasks(), "rst2html");
|
||||
}
|
||||
|
||||
private static List<String> getTasks() {
|
||||
List<String> result = Lists.newArrayList();
|
||||
result.add("rst2html");
|
||||
result.add("rst2latex");
|
||||
result.add("rst2odt");
|
||||
result.add("rst2pseudoxml");
|
||||
result.add("rst2s5");
|
||||
result.add("rst2xml");
|
||||
result.add("rstpep2html");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jetbrains.rest.run.sphinx;
|
||||
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.rest.run.RestCommandLineState;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class SphinxCommandLineState extends RestCommandLineState {
|
||||
|
||||
public SphinxCommandLineState(SphinxRunConfiguration configuration,
|
||||
ExecutionEnvironment env) {
|
||||
super(configuration, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Runnable getAfterTask() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VirtualFile virtualFile = findOutput();
|
||||
if (virtualFile != null)
|
||||
LocalFileSystem.getInstance().refreshFiles(Collections.singleton(virtualFile), false, true, null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRunnerPath() {
|
||||
return "rest_runners/sphinx_runner.py";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKey() {
|
||||
return "-b";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTask() {
|
||||
return myConfiguration.getTask().trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.jetbrains.rest.run.sphinx;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.execution.actions.ConfigurationContext;
|
||||
import com.intellij.execution.junit.RuntimeConfigurationProducer;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.rest.RestFile;
|
||||
import com.jetbrains.rest.run.RestRunConfiguration;
|
||||
import com.jetbrains.rest.run.RestRunConfigurationType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class SphinxConfigurationProducer extends RuntimeConfigurationProducer implements Cloneable {
|
||||
private PsiDirectory mySourceFile = null;
|
||||
|
||||
public SphinxConfigurationProducer() {
|
||||
super(RestRunConfigurationType.getInstance().SPHINX_FACTORY);
|
||||
}
|
||||
|
||||
public PsiElement getSourceElement() {
|
||||
return mySourceFile;
|
||||
}
|
||||
|
||||
protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
|
||||
PsiElement element = location.getPsiElement();
|
||||
if (!(element instanceof PsiDirectory)) return null;
|
||||
|
||||
mySourceFile = (PsiDirectory)element;
|
||||
boolean hasRstFile = false;
|
||||
boolean hasConf = false;
|
||||
for (PsiFile file : mySourceFile.getFiles()) {
|
||||
if ("conf.py".equals(file.getName()))
|
||||
hasConf = true;
|
||||
if (file instanceof RestFile) {
|
||||
hasRstFile = true;
|
||||
}
|
||||
}
|
||||
if (!hasRstFile || !hasConf) return null;
|
||||
final Project project = mySourceFile.getProject();
|
||||
RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
|
||||
SphinxRunConfiguration configuration = (SphinxRunConfiguration) settings.getConfiguration();
|
||||
final VirtualFile vFile = mySourceFile.getVirtualFile();
|
||||
configuration.setInputFile(vFile.getPath());
|
||||
|
||||
configuration.setName(((PsiDirectory)element).getName());
|
||||
if (configuration.getTask().isEmpty())
|
||||
configuration.setTask("html");
|
||||
final VirtualFile parent = vFile.getParent();
|
||||
if (parent != null) {
|
||||
configuration.setWorkingDirectory(parent.getPath());
|
||||
}
|
||||
configuration.setName(configuration.suggestedName());
|
||||
Module module = ModuleUtil.findModuleForPsiElement(element);
|
||||
if (module != null) {
|
||||
configuration.setUseModuleSdk(true);
|
||||
configuration.setModule(module);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RunnerAndConfigurationSettings findExistingByElement(Location location,
|
||||
@NotNull RunnerAndConfigurationSettings[] existingConfigurations,
|
||||
ConfigurationContext context) {
|
||||
PsiElement element = location.getPsiElement();
|
||||
if (!(element instanceof PsiDirectory)) return null;
|
||||
final VirtualFile vFile = ((PsiDirectory)element).getVirtualFile();
|
||||
String path = vFile.getPath();
|
||||
for (RunnerAndConfigurationSettings configuration : existingConfigurations) {
|
||||
final String scriptName = ((RestRunConfiguration)configuration.getConfiguration()).getInputFile();
|
||||
if (FileUtil.toSystemIndependentName(scriptName).equals(FileUtil.toSystemIndependentName(path))) {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int compareTo(final Object o) {
|
||||
return PREFERED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.jetbrains.rest.run.sphinx;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.Executor;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.jetbrains.rest.run.RestConfigurationEditor;
|
||||
import com.jetbrains.rest.run.RestRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class SphinxRunConfiguration extends RestRunConfiguration {
|
||||
public SphinxRunConfiguration(final String name,
|
||||
final RunConfigurationModule module,
|
||||
final ConfigurationFactory factory) {
|
||||
super(name, module, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModuleBasedConfiguration createInstance() {
|
||||
return new SphinxRunConfiguration(getName(), getConfigurationModule(), getFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SettingsEditor<? extends RunConfiguration> createConfigurationEditor() {
|
||||
RestConfigurationEditor editor = new RestConfigurationEditor(getProject(), this, new SphinxTasksModel());
|
||||
editor.setConfigurationName("Sphinx task");
|
||||
editor.setOpenInBrowserVisible(false);
|
||||
editor.setInputDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
editor.setOutputDescriptor(FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
|
||||
return new SphinxCommandLineState(this, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkConfiguration() throws RuntimeConfigurationException {
|
||||
super.checkConfiguration();
|
||||
if (StringUtil.isEmptyOrSpaces(getInputFile()))
|
||||
throw new RuntimeConfigurationError("Please specify input directory name.");
|
||||
if (StringUtil.isEmptyOrSpaces(getOutputFile()))
|
||||
throw new RuntimeConfigurationError("Please specify output directory name.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String suggestedName() {
|
||||
return "sphinx task in " + getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.jetbrains.rest.run.sphinx;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.ui.CollectionComboBoxModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class SphinxTasksModel extends CollectionComboBoxModel {
|
||||
public SphinxTasksModel() {
|
||||
super(getTasks(), "html");
|
||||
}
|
||||
|
||||
private static List<String> getTasks() {
|
||||
List<String> result = Lists.newArrayList();
|
||||
result.add("html");
|
||||
result.add("dirhtml");
|
||||
result.add("singlehtml");
|
||||
result.add("pickle");
|
||||
result.add("json");
|
||||
result.add("web");
|
||||
result.add("htmlhelp");
|
||||
result.add("devhelp");
|
||||
result.add("qthelp");
|
||||
result.add("epub");
|
||||
result.add("latex");
|
||||
result.add("text");
|
||||
result.add("man");
|
||||
result.add("texinfo");
|
||||
result.add("changes");
|
||||
result.add("linkcheck");
|
||||
result.add("websupport");
|
||||
result.add("gettext");
|
||||
result.add("doctest");
|
||||
result.add("coverage");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.rest.sphinx.SphinxBaseCommand.AskForWorkDir">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="815" height="69"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4a1a7" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Sphinx working directory"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e1b53" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myInputFile">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jetbrains.rest.sphinx;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.jetbrains.rest.RestPythonUtil;
|
||||
|
||||
/**
|
||||
* user : catherine
|
||||
*/
|
||||
public class RunSphinxQuickStartAction extends AnAction implements DumbAware {
|
||||
@Override
|
||||
public void update(final AnActionEvent event) {
|
||||
super.update(event);
|
||||
RestPythonUtil.updateSphinxQuickStartRequiredAction(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
final Presentation presentation = RestPythonUtil.updateSphinxQuickStartRequiredAction(e);
|
||||
assert presentation.isEnabled() && presentation.isVisible() : "Sphinx requirements for action are not satisfied";
|
||||
|
||||
final Project project = e.getData(PlatformDataKeys.PROJECT);
|
||||
|
||||
if (project == null) return;
|
||||
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
final Module module = modules.length == 0 ? null : modules [0];
|
||||
|
||||
if (module == null) return;
|
||||
|
||||
final SphinxBaseCommand action = new SphinxBaseCommand();
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
action.execute(module);
|
||||
}
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.jetbrains.rest.sphinx;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.RunContentExecutor;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.configurations.ParamsGroup;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.process.ProcessTerminatedListener;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.python.buildout.BuildoutFacet;
|
||||
import com.jetbrains.python.run.PythonCommandLineState;
|
||||
import com.jetbrains.python.run.PythonProcessRunner;
|
||||
import com.jetbrains.python.run.PythonTracebackFilter;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import com.jetbrains.rest.ReSTService;
|
||||
import com.jetbrains.rest.RestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.jetbrains.python.sdk.PythonEnvUtil.setPythonIOEncoding;
|
||||
import static com.jetbrains.python.sdk.PythonEnvUtil.setPythonUnbuffered;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
* base command for the sphinx actions
|
||||
* asks for the "Sphinx documentation sources"
|
||||
*/
|
||||
public class SphinxBaseCommand {
|
||||
|
||||
protected boolean setWorkDir(Module module) {
|
||||
ReSTService service = ReSTService.getInstance(module.getProject());
|
||||
String workDir = service.getWorkdir();
|
||||
if (workDir.isEmpty()) {
|
||||
AskForWorkDir dialog = new AskForWorkDir(module.getProject());
|
||||
dialog.show();
|
||||
if(!dialog.isOK())
|
||||
return false;
|
||||
service.setWorkdir(dialog.getInputFile());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class AskForWorkDir extends DialogWrapper {
|
||||
private TextFieldWithBrowseButton myInputFile;
|
||||
private JPanel myPanel;
|
||||
|
||||
private AskForWorkDir(Project project) {
|
||||
super(project);
|
||||
|
||||
setTitle("Set sphinx working directory: ");
|
||||
init();
|
||||
VirtualFile baseDir = project.getBaseDir();
|
||||
String path = baseDir != null? baseDir.getPath() : "";
|
||||
myInputFile.setText(path);
|
||||
myInputFile.setEditable(false);
|
||||
myInputFile.addBrowseFolderListener("Choose sphinx working directory (containing makefile): ", null, project,
|
||||
FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
|
||||
myPanel.setPreferredSize(new Dimension(600, 20));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
public String getInputFile() {
|
||||
return myInputFile.getText();
|
||||
}
|
||||
}
|
||||
|
||||
protected final String myCommand = "sphinx-quickstart"+ (SystemInfo.isWindows ? ".exe" : "");
|
||||
|
||||
public void execute(@NotNull final Module module) {
|
||||
final Project project = module.getProject();
|
||||
|
||||
try {
|
||||
if (!setWorkDir(module)) return;
|
||||
final ProcessHandler process = createProcess(module);
|
||||
new RunContentExecutor(project, process)
|
||||
.withFilter(new PythonTracebackFilter(project))
|
||||
.withTitle("reStructuredText")
|
||||
.withRerun(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
execute(module);
|
||||
}
|
||||
})
|
||||
.withAfterCompletion(getAfterTask(module))
|
||||
.run();
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
Messages.showErrorDialog(e.getMessage(), "Restructuredtext error");
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Runnable getAfterTask(final Module module) {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
ReSTService service = ReSTService.getInstance(module.getProject());
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(service.getWorkdir());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ProcessHandler createProcess(Module module) throws ExecutionException {
|
||||
GeneralCommandLine commandLine = createCommandLine(module, Collections.<String>emptyList());
|
||||
ProcessHandler handler = PythonProcessRunner.createProcess(commandLine);
|
||||
ProcessTerminatedListener.attach(handler);
|
||||
return handler;
|
||||
}
|
||||
|
||||
protected GeneralCommandLine createCommandLine(Module module, List<String> params) throws ExecutionException {
|
||||
GeneralCommandLine cmd = new GeneralCommandLine();
|
||||
|
||||
Sdk sdk = PythonSdkType.findPythonSdk(module);
|
||||
if (sdk == null) {
|
||||
throw new ExecutionException("No sdk specified");
|
||||
}
|
||||
|
||||
ReSTService service = ReSTService.getInstance(module.getProject());
|
||||
cmd.setWorkDirectory(service.getWorkdir().isEmpty()? module.getProject().getBaseDir().getPath(): service.getWorkdir());
|
||||
PythonCommandLineState.createStandardGroupsIn(cmd);
|
||||
ParamsGroup script_params = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
|
||||
assert script_params != null;
|
||||
|
||||
if (getCommandPath(sdk) != null)
|
||||
cmd.setExePath(getCommandPath(sdk));
|
||||
|
||||
if (params != null) {
|
||||
for (String p : params) {
|
||||
script_params.addParameter(p);
|
||||
}
|
||||
}
|
||||
|
||||
cmd.setPassParentEnvs(true);
|
||||
cmd.setEnvParams(setPythonUnbuffered(setPythonIOEncoding(Maps.<String, String>newHashMap(), "utf-8")));
|
||||
|
||||
List<String> pathList = Lists.newArrayList(PythonCommandLineState.getAddedPaths(sdk));
|
||||
pathList.addAll(PythonCommandLineState.collectPythonPath(module));
|
||||
|
||||
PythonCommandLineState.initPythonPath(cmd, true, pathList, sdk.getHomePath());
|
||||
|
||||
PythonSdkType.patchCommandLineForVirtualenv(cmd, sdk.getHomePath(), true);
|
||||
BuildoutFacet facet = BuildoutFacet.getInstance(module);
|
||||
if (facet != null) {
|
||||
facet.patchCommandLineForBuildout(cmd);
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getCommandPath(Sdk sdk) {
|
||||
return RestUtil.findRunner(sdk.getHomePath(), myCommand);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestGotoDeclarationTest extends RestFixtureTestCase {
|
||||
|
||||
public void testFootnote() {
|
||||
doTest("[1]");
|
||||
}
|
||||
|
||||
public void testCitation() {
|
||||
doTest("[CIT01]");
|
||||
}
|
||||
|
||||
public void testHyperlink() {
|
||||
doTest("_Reddit:");
|
||||
}
|
||||
|
||||
public void testEscapedHyperlink() {
|
||||
doTest("_Reddit and digg:");
|
||||
}
|
||||
|
||||
public void testSubstitution() {
|
||||
doTest("|text|");
|
||||
}
|
||||
|
||||
public void testAnonimousHyperlink() {
|
||||
doTest("__");
|
||||
}
|
||||
|
||||
public void testTitle() {
|
||||
doTest("=============\nTitle\n=============\n");
|
||||
}
|
||||
|
||||
public void testInsideFootnote() {
|
||||
doTest("_Reddit:");
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
RestGotoProvider provider = new RestGotoProvider();
|
||||
final String path = "/goto/empty.rst";
|
||||
myFixture.configureByFile(path);
|
||||
int e = myFixture.getCaretOffset();
|
||||
PsiElement result = provider.getGotoDeclarationTarget(myFixture.getFile().findElementAt(e), myFixture.getEditor());
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
private void doTest(String expected) {
|
||||
RestGotoProvider provider = new RestGotoProvider();
|
||||
final String path = "/goto/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
|
||||
int e = myFixture.getCaretOffset();
|
||||
PsiElement result = provider.getGotoDeclarationTarget(myFixture.getFile().findElementAt(e), myFixture.getEditor());
|
||||
assertNotNull(result);
|
||||
assertEquals(expected, result.getText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.jetbrains.rest.lexer._RestFlexLexer;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestLexerTest extends TestCase {
|
||||
|
||||
public void testTitle() throws IOException {
|
||||
doTest("\n" +
|
||||
".. _quickstart:\n" +
|
||||
"\n" +
|
||||
"Quick start guide\n" +
|
||||
"=================\n",
|
||||
"[\n, WHITESPACE]",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[_quickstart:, HYPERLINK]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[Quick start guide\n" +
|
||||
"=================\n" +
|
||||
", TITLE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testDirective() throws IOException {
|
||||
doTest("\n" +
|
||||
".. note::\n" +
|
||||
" Please",
|
||||
"[\n, WHITESPACE]",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[note::, DIRECTIVE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[ , WHITESPACE]",
|
||||
"[Please, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testSubstitution() throws IOException {
|
||||
doTest(".. |grappelli| replace:: Grappelli",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[|grappelli|, SUBSTITUTION]",
|
||||
"[ , WHITESPACE]",
|
||||
"[replace::, DIRECTIVE]",
|
||||
"[ Grappelli, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testField() throws IOException {
|
||||
doTest(".. figure:: image.png\n" +
|
||||
" :width: 300pt",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[figure::, DIRECTIVE]",
|
||||
"[ image.png, LINE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[ , WHITESPACE]",
|
||||
"[:width:, FIELD]",
|
||||
"[ , LINE]",
|
||||
"[300pt, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testRole() throws IOException { //PY-3810
|
||||
doTest(" role :roole1:`some text` :notparsed: text\n" +
|
||||
":list field:\n" +
|
||||
" :second field:\n",
|
||||
"[ , LINE]",
|
||||
"[role, LINE]",
|
||||
"[ , LINE]",
|
||||
"[:roole1:, FIELD]",
|
||||
"[`some text`, INTERPRETED]",
|
||||
"[ , LINE]",
|
||||
"[:, LINE]",
|
||||
"[notparsed, LINE]",
|
||||
"[:, LINE]",
|
||||
"[ , LINE]",
|
||||
"[text, LINE]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[:list field:, FIELD]",
|
||||
"[\n, WHITESPACE]",
|
||||
"[ , LINE]",
|
||||
"[:second field:, FIELD]",
|
||||
"[\n, WHITESPACE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testFootnote() throws IOException {
|
||||
doTest(".. [2] Random",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[[2], FOOTNOTE]",
|
||||
"[ , LINE]",
|
||||
"[Random, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testHyperlink() throws IOException {
|
||||
doTest(".. _`dvipng`: http://savannah.nongnu.org/projects/dvipng/",
|
||||
"[.. , EXPLISIT_MARKUP_START]",
|
||||
"[_`dvipng`:, HYPERLINK]",
|
||||
"[ , LINE]",
|
||||
"[http://savannah.nongnu.org/projects/dvipng/, DIRECT_HYPERLINK]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testItalics() throws IOException {
|
||||
doTest("*italics* highlighting",
|
||||
"[*italics*, ITALIC]",
|
||||
"[ , LINE]",
|
||||
"[highlighting, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
public void testBold() throws IOException {
|
||||
doTest("**bold** highlighting",
|
||||
"[**bold**, BOLD]",
|
||||
"[ , LINE]",
|
||||
"[highlighting, LINE]"
|
||||
);
|
||||
}
|
||||
|
||||
private static void doTest(String text, String... expected) throws IOException {
|
||||
_RestFlexLexer lexer = createLexer(text);
|
||||
for (String expectedTokenText : expected) {
|
||||
IElementType type = lexer.advance();
|
||||
if (type == null) {
|
||||
fail("Not enough tokens");
|
||||
}
|
||||
String tokenText = "[" + lexer.yytext() + ", " + type + "]";
|
||||
assertEquals(expectedTokenText, tokenText);
|
||||
}
|
||||
}
|
||||
|
||||
public static _RestFlexLexer createLexer(String text) {
|
||||
_RestFlexLexer lexer = new _RestFlexLexer((Reader)null);
|
||||
lexer.reset(text, 0, text.length(), _RestFlexLexer.YYINITIAL);
|
||||
return lexer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jetbrains.rest;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.testFramework.ParsingTestCase;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import com.jetbrains.rest.parsing.RestParserDefinition;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestParsingTest extends ParsingTestCase {
|
||||
|
||||
public RestParsingTest() {
|
||||
super("", "rst", new RestParserDefinition());
|
||||
PyTestCase.initPlatformPrefix();
|
||||
}
|
||||
|
||||
public void testTitle() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testInjection() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testReference() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testReferenceTarget() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testSubstitution() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PathManager.getHomePath() + "/python/testData/rest/psi";
|
||||
}
|
||||
|
||||
|
||||
protected boolean checkAllPsiRoots() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.jetbrains.rest.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestDirectiveCompletionTest extends RestFixtureTestCase {
|
||||
|
||||
public void testNote() {
|
||||
CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInline() {
|
||||
final String filePath = "/completion/directive/inline.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(0, items.length);
|
||||
}
|
||||
|
||||
public void testMultiple() {
|
||||
CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
|
||||
final String filePath = "/completion/directive/multiple.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(7, items.length);
|
||||
|
||||
assertEquals("caution::", items[0].getLookupString());
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/directive/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(path + ".after.rst");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.jetbrains.rest.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestOptionCompletionTest extends RestFixtureTestCase {
|
||||
|
||||
public void testFootnote() {
|
||||
final String filePath = "/completion/option/footnote.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(0, items.length);
|
||||
}
|
||||
|
||||
public void testImage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOutsideDirective() {
|
||||
final String filePath = "/completion/option/outside.rst";
|
||||
myFixture.configureByFiles(filePath);
|
||||
final LookupElement[] items = myFixture.completeBasic();
|
||||
assertNotNull(items);
|
||||
assertEquals(0, items.length);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/option/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(path + ".after.rst");
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.jetbrains.rest.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestRefereneceCompletionTest extends RestFixtureTestCase {
|
||||
|
||||
public void testFootnote() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCitation() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testHyperlink() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnonimHyperlink() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSubstitution() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUnderscore() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAlreadyFilled() {
|
||||
final String path = "/completion/reference/alreadyFilled.rst";
|
||||
myFixture.configureByFile(path);
|
||||
LookupElement[] lookups = myFixture.completeBasic();
|
||||
assertNotNull(lookups);
|
||||
assertEquals(0, lookups.length);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
final String path = "/completion/reference/" + getTestName(true);
|
||||
myFixture.configureByFile(path + ".rst");
|
||||
myFixture.completeBasic();
|
||||
myFixture.checkResultByFile(path + ".after.rst");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.jetbrains.rest.fixtures;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.module.EmptyModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
@TestDataPath("$CONTENT_ROOT/../testData/rest")
|
||||
public abstract class RestFixtureTestCase extends UsefulTestCase {
|
||||
private static final RestDescriptor ourDescriptor = new RestDescriptor();
|
||||
|
||||
protected CodeInsightTestFixture myFixture;
|
||||
private static boolean ourPlatformPrefixInitialized;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
PyTestCase.initPlatformPrefix();
|
||||
IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder(getProjectDescriptor());
|
||||
final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
|
||||
myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture,
|
||||
new LightTempDirTestFixtureImpl(true));
|
||||
myFixture.setUp();
|
||||
|
||||
myFixture.setTestDataPath(getTestDataPath());
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PathManager.getHomePath() + "/python/testData/rest";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFixture.tearDown();
|
||||
myFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected RestDescriptor getProjectDescriptor() {
|
||||
return ourDescriptor;
|
||||
}
|
||||
|
||||
protected static class RestDescriptor implements LightProjectDescriptor {
|
||||
public RestDescriptor() {}
|
||||
|
||||
@Override
|
||||
public ModuleType getModuleType() {
|
||||
return EmptyModuleType.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.jetbrains.rest.inspections;
|
||||
|
||||
import com.jetbrains.rest.fixtures.RestFixtureTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class RestInspectionTest extends RestFixtureTestCase {
|
||||
public void testUndefinedRole() {
|
||||
doTest(RestRoleInspection.class);
|
||||
}
|
||||
|
||||
public void testHyperlinkAnnotator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFootnoteAnnotator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testReferenceTargetAnnotator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest(Class<? extends RestInspection> inspection) {
|
||||
myFixture.configureByFile("/inspections/" + getTestName(true) + ".rst");
|
||||
if (inspection != null)
|
||||
myFixture.enableInspections(inspection);
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(null);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
<orderEntry type="module" module-name="xml" />
|
||||
<orderEntry type="module" module-name="relaxng" scope="RUNTIME" />
|
||||
<orderEntry type="library" name="Velocity" level="project" />
|
||||
<orderEntry type="module" module-name="rest" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
@@ -644,20 +644,6 @@
|
||||
|
||||
<qualifiedNameProvider implementation="com.jetbrains.python.actions.PyQualifiedNameProvider"/>
|
||||
|
||||
<!-- ReST files -->
|
||||
|
||||
<lang.fileViewProviderFactory language="ReST"
|
||||
implementationClass="com.jetbrains.rest.RestFileProviderFactory"/>
|
||||
<editorHighlighterProvider filetype="ReST" implementationClass="com.jetbrains.rest.RestEditorHighlighterProvider"/>
|
||||
|
||||
<localInspection language="ReST" shortName="RestRoleInspection" bundle="com.jetbrains.rest.RestBundle" key="INSP.role.not.defined"
|
||||
groupKey="INSP.GROUP.rest" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.jetbrains.rest.inspections.RestRoleInspection"/>
|
||||
|
||||
<configurationType implementation="com.jetbrains.rest.run.RestRunConfigurationType"/>
|
||||
<configurationProducer implementation="com.jetbrains.rest.run.docutils.DocutilsConfigurationProducer"/>
|
||||
<configurationProducer implementation="com.jetbrains.rest.run.sphinx.SphinxConfigurationProducer"/>
|
||||
|
||||
<!-- Mako files -->
|
||||
<multiLangCommenter implementation="com.jetbrains.python.templateLanguages.TemplatesCommentProvider"/>
|
||||
<highlightErrorFilter implementation="com.jetbrains.mako.inspection.MakoErrorFilter"/>
|
||||
@@ -900,11 +886,6 @@
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</group>
|
||||
|
||||
<action id="com.jetbrains.rest.actions.sphinx.RunSphinxQuickStartAction"
|
||||
class="com.jetbrains.rest.actions.sphinx.RunSphinxQuickStartAction"
|
||||
text="Sphinx quickstart" description="Allows to run sphinx quick-start action">
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<action id="ExecuteInPyConsoleAction"
|
||||
class="com.jetbrains.python.actions.ExecuteInConsoleAction"
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.xdebugger.XDebugProcess;
|
||||
import com.intellij.xdebugger.XDebugProcessStarter;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
@@ -31,11 +30,9 @@ import com.jetbrains.python.run.CommandLinePatcher;
|
||||
import com.jetbrains.python.run.PythonCommandLineState;
|
||||
import com.jetbrains.python.run.PythonRunConfiguration;
|
||||
import com.jetbrains.python.sdk.PythonSdkFlavor;
|
||||
import com.jetbrains.rest.run.RestRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.List;
|
||||
|
||||
@@ -58,7 +55,7 @@ public class PyDebugRunner extends GenericProgramRunner {
|
||||
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
|
||||
return DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) &&
|
||||
profile instanceof AbstractPythonRunConfiguration &&
|
||||
!(profile instanceof RestRunConfiguration);
|
||||
((AbstractPythonRunConfiguration)profile).canRunWithCoverage();
|
||||
}
|
||||
|
||||
protected RunContentDescriptor doExecute(final Project project, Executor executor, RunProfileState profileState,
|
||||
|
||||
@@ -346,4 +346,8 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
|
||||
final Module module = getModule();
|
||||
return module != null ? ModuleType.get(module) instanceof PythonModuleTypeBase : true;
|
||||
}
|
||||
|
||||
public boolean canRunWithCoverage() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user