com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider#com.wix.annotator.ExternalLintAnnotationInput源码实例Demo

下面列出了com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider#com.wix.annotator.ExternalLintAnnotationInput 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Nullable
    private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) {
        if (psiFile.getContext() != null || !SassLintConfigFileUtil.isSassFile(psiFile)) {
            return null;
        }
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
            return null;
        }
        if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
            return null;
        }
        Project project = psiFile.getProject();
        SassLintProjectComponent component = project.getComponent(SassLintProjectComponent.class);
        if (!component.isSettingsValid() || !component.isEnabled()) {
            return null;
        }
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        if (document == null) {
            return null;
        }
        String fileContent = document.getText();
        if (StringUtil.isEmptyOrSpaces(fileContent)) {
            return null;
        }
        EditorColorsScheme colorsScheme = editor != null ? editor.getColorsScheme() : null;
//        tabSize = getTabSize(editor);
//        tabSize = 4;
        return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme);
    }
 
@Nullable
    private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) {
        if (psiFile.getContext() != null || !RTFileUtil.isRTFile(psiFile)) {
            return null;
        }
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
            return null;
        }
        if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
            return null;
        }
        Project project = psiFile.getProject();
        RTProjectComponent component = project.getComponent(RTProjectComponent.class);
        if (component == null || !component.isValidAndEnabled()) {
            return null;
        }
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        if (document == null) {
            return null;
        }
        String fileContent = document.getText();
        if (StringUtil.isEmptyOrSpaces(fileContent)) {
            return null;
        }
        EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme();
//        tabSize = getTabSize(editor);
//        tabSize = 4;
        return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme);
    }
 
@Nullable
    private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) {
        if (psiFile.getContext() != null || !RTFileUtil.isRTFile(psiFile)) {
            return null;
        }
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
            return null;
        }
        if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
            return null;
        }
        Project project = psiFile.getProject();
        RTProjectComponent component = project.getComponent(RTProjectComponent.class);
        if (component == null || !component.isValidAndEnabled()) {
            return null;
        }
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        if (document == null) {
            return null;
        }
        String fileContent = document.getText();
        if (StringUtil.isEmptyOrSpaces(fileContent)) {
            return null;
        }
        EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme();
//        tabSize = getTabSize(editor);
//        tabSize = 4;
        return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme);
    }
 
源代码4 项目: eslint-plugin   文件: ESLintExternalAnnotator.java
@Nullable
    private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) {
        if (psiFile.getContext() != null) {
            return null;
        }
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
            return null;
        }
        if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
            return null;
        }
        Project project = psiFile.getProject();
        ESLintProjectComponent component = project.getComponent(ESLintProjectComponent.class);
        if (!component.isSettingsValid() || !component.isEnabled() || !isJavaScriptFile(psiFile, component.ext)) {
            return null;
        }
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        if (document == null) {
            return null;
        }
        String fileContent = document.getText();
        if (StringUtil.isEmptyOrSpaces(fileContent)) {
            return null;
        }
        EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme();
//        tabSize = getTabSize(editor);
//        tabSize = 4;
        return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme);
    }
 
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
@Nullable
@Override
public ExternalLintAnnotationResult<LintResult> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
    ActualFile2 actualCodeFile = null;
    try {
        PsiFile file = collectedInfo.psiFile;
        if (!SassLintConfigFileUtil.isSassFile(file)) return null;
        SassLintProjectComponent component = file.getProject().getComponent(SassLintProjectComponent.class);
        if (!component.isSettingsValid() || !component.isEnabled()) {
            return null;
        }

        SassLintConfigFileListener.start(collectedInfo.project);
        String relativeFile;
        actualCodeFile = ActualFile2.getOrCreateActualFile(SASS_LINT_TEMP_FILE, file, collectedInfo.fileContent);
        if (actualCodeFile == null || actualCodeFile.getActualFile() == null) {
            return null;
        }
        relativeFile = FileUtils.makeRelative(new File(file.getProject().getBasePath()), actualCodeFile.getActualFile());
        if (relativeFile == null) {
            LOG.error("Error running Sass Lint inspection: relative file path is null");
            return null;
        }
        LintResult result = SassLintRunner.lint(file.getProject().getBasePath(), relativeFile, component.nodeInterpreter, component.lintExecutable, component.configFile, component.customRulesPath, component.extensions);

        actualCodeFile.deleteTemp();
        if (StringUtils.isNotEmpty(result.errorOutput)) {
            component.showInfoNotification(result.errorOutput, NotificationType.WARNING);
            return null;
        }
        Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
        if (document == null) {
            component.showInfoNotification("Error running Sass Lint inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
            LOG.error("Could not get document for file " + file.getName());
            return null;
        }
        return new ExternalLintAnnotationResult<LintResult>(collectedInfo, result);
    } catch (Exception e) {
        LOG.error("Error running Sass Lint inspection: ", e);
        showNotification("Error running Sass Lint inspection: " + e.getMessage(), NotificationType.ERROR);
    } finally {
        if (actualCodeFile != null) {
            actualCodeFile.deleteTemp();
        }
    }
    return null;
}
 
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
@Nullable
    @Override
    public ExternalLintAnnotationResult<Result> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
        ActualFile actualCodeFile = null;
        try {
            PsiFile file = collectedInfo.psiFile;
            if (!RTFileUtil.isRTFile(file)) return null;
            Project project = file.getProject();
            RTProjectComponent component = project.getComponent(RTProjectComponent.class);
            if (component == null || !component.isValidAndEnabled()) {
                return null;
            }

            String relativeFile;
            actualCodeFile = ActualFile.getOrCreateActualFile(RT_TEMP_FILE_KEY, file.getVirtualFile(), collectedInfo.fileContent);
            if (actualCodeFile == null || actualCodeFile.getActualFile() == null) {
                return null;
            }
            relativeFile = FileUtils.makeRelative(new File(project.getBasePath()), actualCodeFile.getActualFile());
            RTSettings settings = RTSettings.buildSettings(component.settings, project.getBasePath(), relativeFile);
            Result result = RTRunner.INSTANCE.compile(settings);

            if (StringUtils.isNotEmpty(result.getErrorOutput())) {
                component.showInfoNotification(result.getErrorOutput(), NotificationType.WARNING);
                return null;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document == null) {
                component.showInfoNotification("Error running RT inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
                LOG.error("Could not get document for file " + file.getName());
                return null;
            }
            return new ExternalLintAnnotationResult<Result>(collectedInfo, result);
        } catch (Exception e) {
            LOG.error("Error running RT inspection: ", e);
            showNotification("Error running RT inspection: " + e.getMessage(), NotificationType.ERROR);
//            return new ExternalLintAnnotationResult<Result>(collectedInfo, result); file level annotation
        } finally {
            if (actualCodeFile != null) {
                actualCodeFile.deleteTemp();
            }
        }
        return null;
    }
 
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
@Nullable
    @Override
    public ExternalLintAnnotationResult<Result> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
        ActualFile actualCodeFile = null;
        try {
            PsiFile file = collectedInfo.psiFile;
            if (!RTFileUtil.isRTFile(file)) return null;
            Project project = file.getProject();
            RTProjectComponent component = project.getComponent(RTProjectComponent.class);
            if (component == null || !component.isValidAndEnabled()) {
                return null;
            }

            String relativeFile;
            actualCodeFile = ActualFile.getOrCreateActualFile(RT_TEMP_FILE_KEY, file.getVirtualFile(), collectedInfo.fileContent);
            if (actualCodeFile == null || actualCodeFile.getActualFile() == null) {
                return null;
            }
            relativeFile = FileUtils.makeRelative(new File(project.getBasePath()), actualCodeFile.getActualFile());
            RTSettings settings = RTSettings.buildSettings(component.settings, project.getBasePath(), relativeFile);
            Result result = RTRunner.INSTANCE.compile(settings);

            if (StringUtils.isNotEmpty(result.getErrorOutput())) {
                component.showInfoNotification(result.getErrorOutput(), NotificationType.WARNING);
                return null;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document == null) {
                component.showInfoNotification("Error running RT inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
                LOG.error("Could not get document for file " + file.getName());
                return null;
            }
            return new ExternalLintAnnotationResult<Result>(collectedInfo, result);
        } catch (Exception e) {
            LOG.error("Error running RT inspection: ", e);
            showNotification("Error running RT inspection: " + e.getMessage(), NotificationType.ERROR);
//            return new ExternalLintAnnotationResult<Result>(collectedInfo, result); file level annotation
        } finally {
            if (actualCodeFile != null) {
                actualCodeFile.deleteTemp();
            }
        }
        return null;
    }
 
源代码14 项目: eslint-plugin   文件: ESLintExternalAnnotator.java
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
源代码15 项目: eslint-plugin   文件: ESLintExternalAnnotator.java
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
源代码16 项目: eslint-plugin   文件: ESLintExternalAnnotator.java
@Nullable
    @Override
    public ExternalLintAnnotationResult<Result> doAnnotate(ExternalLintAnnotationInput collectedInfo) {
        try {
            LOG.info("Running ESLint inspection");
            PsiFile file = collectedInfo.psiFile;
            Project project = file.getProject();
            ESLintProjectComponent component = project.getComponent(ESLintProjectComponent.class);
            if (!component.isSettingsValid() || !component.isEnabled() || !isJavaScriptFile(file, component.ext)) {
                return null;
            }
            ESLintConfigFileListener.start(collectedInfo.project);
            String relativeFile;
            ActualFile actualCodeFile = ActualFile.getOrCreateActualFile(ESLINT_TEMP_FILE_KEY, file.getVirtualFile(), collectedInfo.fileContent);
            if (actualCodeFile == null || actualCodeFile.getFile() == null) {
                return null;
            }
            relativeFile = FileUtils.makeRelative(new File(project.getBasePath()), actualCodeFile.getActualFile());
            Result result = ESLintRunner.lint(project.getBasePath(), relativeFile, component);

            if (component.settings.autoFix) {
//            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
//            document.
//            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
                // read lock
//            ApplicationManager.getApplication().runWriteAction()
//            ApplicationManager.getApplication().runWriteAction()
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    public void run() {
                        file.getVirtualFile().refresh(false, false);
                    }
                }, ModalityState.NON_MODAL);

//            WriteAction.run(() -> file.getVirtualFile().refresh(false, false));
//            UIUtil.invokeLaterIfNeeded(new Runnable() {
//                public void run() {
//                    file.getVirtualFile().refresh(false, false);
//                }
//            });
            }

            actualCodeFile.deleteTemp();
            if (StringUtils.isNotEmpty(result.errorOutput)) {
                component.showInfoNotification(result.errorOutput, NotificationType.WARNING);
                return null;
            }
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document == null) {
                component.showInfoNotification("Error running ESLint inspection: Could not get document for file " + file.getName(), NotificationType.WARNING);
                LOG.error("Could not get document for file " + file.getName());
                return null;
            }
            return new ExternalLintAnnotationResult<>(collectedInfo, result);
        } catch (Exception e) {
            LOG.error("Error running ESLint inspection: ", e);
            ESLintProjectComponent.showNotification("Error running ESLint inspection: " + e.getMessage(), NotificationType.ERROR);
        }
        return null;
    }