Search in sources :

Example 1 with TsLinterError

use of com.intellij.lang.javascript.linter.tslint.execution.TsLinterError in project intellij-plugins by JetBrains.

the class TsLintExternalAnnotator method apply.

@Override
public void apply(@NotNull PsiFile file, @Nullable JSLinterAnnotationResult<TsLintState> annotationResult, @NotNull AnnotationHolder holder) {
    if (annotationResult == null)
        return;
    TsLintConfigurable configurable = new TsLintConfigurable(file.getProject(), true);
    final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    IntentionAction fixAllFileIntention = new TsLintFileFixAction().asIntentionAction();
    JSLinterStandardFixes fixes = new JSLinterStandardFixes() {

        @Override
        public List<IntentionAction> createListForError(@Nullable VirtualFile configFile, @NotNull UntypedJSLinterConfigurable configurable, @NotNull JSLinterErrorBase errorBase) {
            List<IntentionAction> defaultIntentions = super.createListForError(configFile, configurable, errorBase);
            if (errorBase instanceof TsLinterError && ((TsLinterError) errorBase).hasFix()) {
                ArrayList<IntentionAction> result = ContainerUtil.newArrayList();
                if (document != null && myOnTheFly) {
                    result.add(new TsLintErrorFixAction((TsLinterError) errorBase, document));
                }
                result.add(fixAllFileIntention);
                result.addAll(defaultIntentions);
                return result;
            }
            return defaultIntentions;
        }
    };
    new JSLinterAnnotationsBuilder<>(file, annotationResult, holder, TsLintInspection.getHighlightDisplayKey(), configurable, TsLintBundle.message("tslint.framework.title") + ": ", getInspectionClass(), fixes).setHighlightingGranularity(HighlightingGranularity.element).apply(document);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TsLintErrorFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintErrorFixAction) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) TsLintConfigurable(com.intellij.lang.javascript.linter.tslint.ui.TsLintConfigurable) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TsLintFileFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintFileFixAction) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TsLinterError

use of com.intellij.lang.javascript.linter.tslint.execution.TsLinterError in project intellij-plugins by JetBrains.

the class TsLintExternalAnnotator method annotate.

@Nullable
@Override
public JSLinterAnnotationResult<TsLintState> annotate(@NotNull TsLinterInput collectedInfo) {
    TsLintLanguageService service = TsLintLanguageService.getService(collectedInfo.getProject());
    VirtualFile config = collectedInfo.getConfig();
    Future<List<TsLinterError>> highlight = service.highlight(collectedInfo.getVirtualFile(), config, collectedInfo.getFileContent());
    List<TsLinterError> annotationErrors = JSLanguageServiceUtil.awaitFuture(highlight);
    if (annotationErrors == null) {
        if (!service.isServiceCreated() || service.getServiceCreationError() != null) {
            String error = service.getServiceCreationError();
            error = error == null ? JSLanguageServiceQueueImpl.CANNOT_START_LANGUAGE_SERVICE_PROCESS : error;
            return JSLinterAnnotationResult.create(collectedInfo, new JSLinterFileLevelAnnotation(error), config);
        }
        return null;
    }
    if (!annotationErrors.isEmpty()) {
        final Optional<TsLinterError> globalError = annotationErrors.stream().filter(error -> error.isGlobal()).findFirst();
        if (globalError.isPresent()) {
            final JSLinterAnnotationResult<TsLintState> annotation = createGlobalErrorMessage(collectedInfo, config, globalError.get().getDescription());
            if (annotation != null)
                return annotation;
        }
    }
    List<JSLinterError> result = filterResultByFile(collectedInfo, annotationErrors);
    return JSLinterAnnotationResult.createLinterResult(collectedInfo, result, config);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) AnnotationHolder(com.intellij.lang.annotation.AnnotationHolder) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DialectDetector(com.intellij.lang.javascript.DialectDetector) DialectOptionHolder(com.intellij.lang.javascript.DialectOptionHolder) TsLintBundle(com.intellij.lang.javascript.linter.tslint.TsLintBundle) JSUtils(com.intellij.lang.javascript.psi.util.JSUtils) TsLintState(com.intellij.lang.javascript.linter.tslint.config.TsLintState) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FileUtil(com.intellij.openapi.util.io.FileUtil) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) StringUtil(com.intellij.openapi.util.text.StringUtil) JSLanguageServiceUtil(com.intellij.lang.javascript.service.JSLanguageServiceUtil) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Set(java.util.Set) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) TsLintConfigurable(com.intellij.lang.javascript.linter.tslint.ui.TsLintConfigurable) Collectors(java.util.stream.Collectors) TsLintConfigFileSearcher(com.intellij.lang.javascript.linter.tslint.execution.TsLintConfigFileSearcher) Nullable(org.jetbrains.annotations.Nullable) TsLintFileFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintFileFixAction) List(java.util.List) com.intellij.lang.javascript.linter(com.intellij.lang.javascript.linter) JSLanguageServiceQueueImpl(com.intellij.lang.javascript.service.JSLanguageServiceQueueImpl) TsLintConfiguration(com.intellij.lang.javascript.linter.tslint.config.TsLintConfiguration) TsLintErrorFixAction(com.intellij.lang.javascript.linter.tslint.fix.TsLintErrorFixAction) ProcessOutput(com.intellij.execution.process.ProcessOutput) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Optional(java.util.Optional) TsLintLanguageService(com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) TsLintState(com.intellij.lang.javascript.linter.tslint.config.TsLintState) TsLintLanguageService(com.intellij.lang.javascript.linter.tslint.service.TsLintLanguageService) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with TsLinterError

use of com.intellij.lang.javascript.linter.tslint.execution.TsLinterError in project intellij-plugins by JetBrains.

the class TsLintLanguageService method parseResults.

@Nullable
private static List<TsLinterError> parseResults(@NotNull JSLanguageServiceAnswer answer, @NotNull String path) {
    final JsonObject element = answer.getElement();
    final JsonElement error = element.get("error");
    if (error != null) {
        return Collections.singletonList(new TsLinterError(error.getAsString()));
    }
    final JsonElement body = parseBody(element);
    if (body == null)
        return null;
    final String version = element.get("version").getAsString();
    final SemVer tsLintVersion = SemVer.parseFromText(version);
    final boolean isZeroBased = TsLintOutputJsonParser.isVersionZeroBased(tsLintVersion);
    final TsLintOutputJsonParser parser = new TsLintOutputJsonParser(path, body, isZeroBased);
    return ContainerUtil.newArrayList(parser.getErrors());
}
Also used : JsonElement(com.google.gson.JsonElement) TsLinterError(com.intellij.lang.javascript.linter.tslint.execution.TsLinterError) JsonObject(com.google.gson.JsonObject) SemVer(com.intellij.util.text.SemVer) TsLintOutputJsonParser(com.intellij.lang.javascript.linter.tslint.execution.TsLintOutputJsonParser) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TsLinterError (com.intellij.lang.javascript.linter.tslint.execution.TsLinterError)3 Nullable (org.jetbrains.annotations.Nullable)3 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 TsLintErrorFixAction (com.intellij.lang.javascript.linter.tslint.fix.TsLintErrorFixAction)2 TsLintFileFixAction (com.intellij.lang.javascript.linter.tslint.fix.TsLintFileFixAction)2 TsLintConfigurable (com.intellij.lang.javascript.linter.tslint.ui.TsLintConfigurable)2 Document (com.intellij.openapi.editor.Document)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 ProcessOutput (com.intellij.execution.process.ProcessOutput)1 AnnotationHolder (com.intellij.lang.annotation.AnnotationHolder)1 DialectDetector (com.intellij.lang.javascript.DialectDetector)1 DialectOptionHolder (com.intellij.lang.javascript.DialectOptionHolder)1 com.intellij.lang.javascript.linter (com.intellij.lang.javascript.linter)1 TsLintBundle (com.intellij.lang.javascript.linter.tslint.TsLintBundle)1 TsLintConfiguration (com.intellij.lang.javascript.linter.tslint.config.TsLintConfiguration)1 TsLintState (com.intellij.lang.javascript.linter.tslint.config.TsLintState)1