com.wix.annotator.ExternalLintAnnotationInput Java Examples

The following examples show how to use com.wix.annotator.ExternalLintAnnotationInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SassLintExternalAnnotator.java    From sass-lint-plugin with MIT License 5 votes vote down vote up
@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);
    }
 
Example #2
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
    }
 
Example #3
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@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);
    }
 
Example #4
Source File: ESLintExternalAnnotator.java    From eslint-plugin with MIT License 5 votes vote down vote up
@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);
    }
 
Example #5
Source File: SassLintExternalAnnotator.java    From sass-lint-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
Example #6
Source File: SassLintExternalAnnotator.java    From sass-lint-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
Example #7
Source File: SassLintExternalAnnotator.java    From sass-lint-plugin with MIT License 4 votes vote down vote up
@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;
}
 
Example #8
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
Example #9
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
Example #10
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@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;
    }
 
Example #11
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
Example #12
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
Example #13
Source File: RTExternalAnnotator.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@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;
    }
 
Example #14
Source File: ESLintExternalAnnotator.java    From eslint-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file) {
    return collectInformation(file, null);
}
 
Example #15
Source File: ESLintExternalAnnotator.java    From eslint-plugin with MIT License 4 votes vote down vote up
@Nullable
@Override
public ExternalLintAnnotationInput collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
    return collectInformation(file, editor);
}
 
Example #16
Source File: ESLintExternalAnnotator.java    From eslint-plugin with MIT License 4 votes vote down vote up
@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;
    }