WEB-32237 Kubernetes+Json. QuickHelp. add key name, type, kubernetes version

This commit is contained in:
Anton Lobov
2018-04-19 09:35:54 +02:00
parent 3d133941a0
commit 452f30bca5
15 changed files with 82 additions and 15 deletions
@@ -21,4 +21,9 @@ public interface JsonSchemaFileProvider {
default JsonSchemaVersion getSchemaVersion() {
return JsonSchemaVersion.SCHEMA_4;
}
@Nullable
default String getThirdPartyApiInformation() {
return null;
}
}
@@ -7,13 +7,16 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.jsonSchema.extension.JsonLikePsiWalker;
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider;
import com.jetbrains.jsonSchema.ide.JsonSchemaService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class JsonSchemaDocumentationProvider implements DocumentationProvider {
@@ -59,12 +62,66 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
if (position == null) return null;
final Collection<JsonSchemaObject> schemas = new JsonSchemaResolver(rootSchema, true, position).resolve();
String htmlDescription = null;
List<JsonSchemaType> possibleTypes = ContainerUtil.newArrayList();
for (JsonSchemaObject schema : schemas) {
final String htmlDescription = getBestDocumentation(preferShort, schema);
if (htmlDescription != null) return htmlDescription;
if (htmlDescription == null) {
htmlDescription = getBestDocumentation(preferShort, schema);
}
if (schema.getType() != null && schema.getType() != JsonSchemaType._any) {
possibleTypes.add(schema.getType());
}
else if (schema.getTypeVariants() != null) {
possibleTypes.addAll(schema.getTypeVariants());
}
}
return null;
return htmlDescription == null
? null
: appendNameTypeAndApi(position, getThirdPartyApiInfo(element, rootSchema), possibleTypes, htmlDescription);
}
@Nullable
private static String concatTypeInfo(@NotNull List<JsonSchemaType> possibleTypes) {
if (possibleTypes.size() == 0) return null;
if (possibleTypes.size() == 1) return possibleTypes.get(0).getDescription();
return StringUtil.join(possibleTypes.stream().map(t -> t.getDescription()).distinct().sorted().collect(Collectors.toList()), " | ");
}
@NotNull
private static String appendNameTypeAndApi(@NotNull List<JsonSchemaVariantsTreeBuilder.Step> position,
@NotNull String apiInfo,
@NotNull List<JsonSchemaType> possibleTypes,
@NotNull String htmlDescription) {
if (position.size() == 0) return htmlDescription;
JsonSchemaVariantsTreeBuilder.Step lastStep = position.get(position.size() - 1);
String name = lastStep.getName();
if (name == null) return htmlDescription;
String type = "";
String schemaType = concatTypeInfo(possibleTypes);
if (schemaType != null) {
type = ": " + schemaType;
}
htmlDescription = "<b>" + name + "</b>" + type + apiInfo + "<br/><br/>" + htmlDescription;
return htmlDescription;
}
@NotNull
private static String getThirdPartyApiInfo(@NotNull PsiElement element,
@NotNull JsonSchemaObject rootSchema) {
JsonSchemaService service = JsonSchemaService.Impl.get(element.getProject());
String apiInfo = "";
JsonSchemaFileProvider provider = service.getSchemaProvider(rootSchema.getSchemaFile());
if (provider != null) {
String information = provider.getThirdPartyApiInformation();
if (information != null) {
apiInfo = "&nbsp;&nbsp;<i>(" + information + ")</i>";
}
}
return apiInfo;
}
@Nullable
@@ -37,4 +37,9 @@ public enum JsonSchemaType {
return false;
}
}
public String getDescription() {
if (this == _any) return "*";
return getName();
}
}
@@ -1 +1 @@
Number of port to expose on the pod&#39;s IP address. &quot;This&quot; must be a valid port number, 0 &lt; x &lt; 65536.
<b>no-reference</b><br/><br/>Number of port to expose on the pod&#39;s IP address. &quot;This&quot; must be a valid port number, 0 &lt; x &lt; 65536.
@@ -1 +1 @@
Disallows /// &lt;reference path=&gt; imports (use ES6-style imports instead)
<b>no-reference</b><br/><br/>Disallows /// &lt;reference path=&gt; imports (use ES6-style imports instead)
@@ -1 +1 @@
<b>Hello</b> and <font color="blue">enjoy</font> <i>new</i> <a href="http://google.com">description!</a>
<b>ccc</b><br/><br/><b>Hello</b> and <font color="blue">enjoy</font> <i>new</i> <a href="http://google.com">description!</a>
@@ -1 +1 @@
<b>Hello</b> and <font color="blue">enjoy</font> <i>new</i> <a href="http://google.com">description!</a>
<b>ccc</b><br/><br/><b>Hello</b> and <font color="blue">enjoy</font> <i>new</i> <a href="http://google.com">description!</a>
@@ -1 +1 @@
my second level property description 1
<b>my_second_level_property</b><br/><br/>my second level property description 1
@@ -1 +1 @@
my second level property description 1
<b>my_second_level_property</b><br/><br/>my second level property description 1
@@ -1 +1 @@
my property description 1
<b>my_property</b><br/><br/>my property description 1
@@ -1 +1 @@
my property description 1
<b>my_property</b><br/><br/>my property description 1
@@ -1 +1 @@
Description found through definition
<b>source</b><br/><br/>Description found through definition
@@ -1 +1 @@
Description found through definition
<b>source</b><br/><br/>Description found through definition
@@ -1 +1 @@
Description found through definition
<b>source</b><br/><br/>Description found through definition
@@ -1 +1 @@
Title found through definition
<b>source</b><br/><br/>Title found through definition