mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-20499 JSON Schema: in case of system and user schemas overlapping - use user schema only
This commit is contained in:
+29
-15
@@ -63,11 +63,12 @@ public class JsonSchemaConflictNotificationProvider extends EditorNotifications.
|
||||
final List<Pair<Boolean, String>> 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<Pair<Boolean, String>> descriptors) {
|
||||
boolean haveSystemSchemas = false;
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
haveSystemSchemas |= !Boolean.TRUE.equals(pair.getFirst());
|
||||
}
|
||||
boolean withTypes = haveSystemSchemas;
|
||||
final List<String> names = new ArrayList<>();
|
||||
for (Pair<Boolean, String> 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<Pair<Boolean, String>> descriptors) {
|
||||
int numOfSystemSchemas = 0;
|
||||
String systemSchemaName = "";
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
if (!Boolean.TRUE.equals(pair.getFirst())) {
|
||||
++ numOfSystemSchemas;
|
||||
systemSchemaName = pair.getSecond();
|
||||
}
|
||||
}
|
||||
String additionalInfo = "";
|
||||
if (numOfSystemSchemas == 1) {
|
||||
myIsOverridingSystemSchemaCase = true;
|
||||
additionalInfo = "<br><b>System schema '" + systemSchemaName + "' was not applied.</b>";
|
||||
}
|
||||
boolean withTypes = numOfSystemSchemas > 0;
|
||||
final List<String> names = new ArrayList<>();
|
||||
for (Pair<Boolean, String> pair : descriptors) {
|
||||
if (withTypes) {
|
||||
names.add((Boolean.TRUE.equals(pair.getFirst()) ? "user" : "system") + " schema '" + pair.getSecond() + "'");
|
||||
} else {
|
||||
names.add(pair.getSecond());
|
||||
}
|
||||
}
|
||||
return "<html>There are several JSON Schemas mapped to this file: " + StringUtil.join(names, "; ") + additionalInfo + "</html>";
|
||||
}
|
||||
return "<html>There are several JSON Schemas mapped to this file: " + StringUtil.join(names, "; ") + "</html>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<JsonSchemaObjectCodeInsightWrapper> wrappers) {
|
||||
myWrappers = wrappers;
|
||||
final List<JsonSchemaObjectCodeInsightWrapper> userSchemaWrappers =
|
||||
ContainerUtil.filter(wrappers, new Condition<JsonSchemaObjectCodeInsightWrapper>() {
|
||||
@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) {
|
||||
|
||||
Reference in New Issue
Block a user