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);
}
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);
}
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());
}
Aggregations