diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaConflictNotificationProvider.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaConflictNotificationProvider.java index a8a5c96ea868..139ad3fa0db5 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaConflictNotificationProvider.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaConflictNotificationProvider.java @@ -63,11 +63,12 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications. final List> descriptors = myJsonSchemaService.getMatchingSchemaDescriptors(file); if (descriptors == null || descriptors.size() <= 1) return null; - final String message = createMessage(descriptors); + final Worker worker = new Worker(); + final String message = worker.createMessage(descriptors); final EditorNotificationPanel panel = new EditorNotificationPanel() { @Override public Color getBackground() { - return LightColors.RED; + return worker.myIsOverridingSystemSchemaCase ? LightColors.SLIGHTLY_GREEN : LightColors.RED; } }; panel.setText(message); @@ -81,20 +82,33 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications. return panel; } - private static String createMessage(@NotNull final List> descriptors) { - boolean haveSystemSchemas = false; - for (Pair pair : descriptors) { - haveSystemSchemas |= !Boolean.TRUE.equals(pair.getFirst()); - } - boolean withTypes = haveSystemSchemas; - final List names = new ArrayList<>(); - for (Pair pair : descriptors) { - if (withTypes) { - names.add((Boolean.TRUE.equals(pair.getFirst()) ? "user" : "system") + " schema '" + pair.getSecond() + "'"); - } else { - names.add(pair.getSecond()); + private static class Worker { + private boolean myIsOverridingSystemSchemaCase; + + public String createMessage(@NotNull final List> descriptors) { + int numOfSystemSchemas = 0; + String systemSchemaName = ""; + for (Pair pair : descriptors) { + if (!Boolean.TRUE.equals(pair.getFirst())) { + ++ numOfSystemSchemas; + systemSchemaName = pair.getSecond(); + } } + String additionalInfo = ""; + if (numOfSystemSchemas == 1) { + myIsOverridingSystemSchemaCase = true; + additionalInfo = "
System schema '" + systemSchemaName + "' was not applied."; + } + boolean withTypes = numOfSystemSchemas > 0; + final List names = new ArrayList<>(); + for (Pair pair : descriptors) { + if (withTypes) { + names.add((Boolean.TRUE.equals(pair.getFirst()) ? "user" : "system") + " schema '" + pair.getSecond() + "'"); + } else { + names.add(pair.getSecond()); + } + } + return "There are several JSON Schemas mapped to this file: " + StringUtil.join(names, "; ") + additionalInfo + ""; } - return "There are several JSON Schemas mapped to this file: " + StringUtil.join(names, "; ") + ""; } } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java index 963ad394954b..85fce4bc421a 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java @@ -14,6 +14,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; @@ -156,7 +157,21 @@ public class JsonSchemaServiceImpl implements JsonSchemaService { private DocumentationProvider myDocumentationProvider; public CompositeCodeInsightProviderWithWarning(List wrappers) { - myWrappers = wrappers; + final List userSchemaWrappers = + ContainerUtil.filter(wrappers, new Condition() { + @Override + public boolean value(JsonSchemaObjectCodeInsightWrapper wrapper) { + return wrapper.isUserSchema(); + } + }); + // filter for the case when there are one system schema and one (several) user schemas + // then do not use provided system schema: user schema will override it (maybe the user updated the version himself) + // if there are 2 or more system schemas - just go the common way: it is unclear what happened and why + if (!userSchemaWrappers.isEmpty() && ((userSchemaWrappers.size() + 1) == wrappers.size())) { + myWrappers = userSchemaWrappers; + } else { + myWrappers = wrappers; + } myContributor = new CompletionContributor() { @Override public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {