mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-185069 Kubernetes: Json. QuickHelp. Provide quick help for completion list items
This commit is contained in:
@@ -52,7 +52,7 @@ public class JsonBreadcrumbsProvider implements BreadcrumbsProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getElementTooltip(@NotNull PsiElement e) {
|
||||
return JsonSchemaDocumentationProvider.findSchemaAndGenerateDoc(e, null, true);
|
||||
return JsonSchemaDocumentationProvider.findSchemaAndGenerateDoc(e, null, true, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -349,7 +349,9 @@ public class JsonSchemaCompletionContributor extends CompletionContributor {
|
||||
|
||||
final String typeText = JsonSchemaDocumentationProvider.getBestDocumentation(true, jsonSchemaObject);
|
||||
if (!StringUtil.isEmptyOrSpaces(typeText)) {
|
||||
builder = builder.withTypeText(StringUtil.removeHtmlTags(typeText), true);
|
||||
final String text = StringUtil.removeHtmlTags(typeText);
|
||||
final int firstSentenceMark = text.indexOf(". ");
|
||||
builder = builder.withTypeText(firstSentenceMark == -1 ? text : text.substring(0, firstSentenceMark + 1), true);
|
||||
}
|
||||
else {
|
||||
String type = jsonSchemaObject.getTypeDescription(true);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.jsonSchema.impl;
|
||||
|
||||
import com.intellij.json.psi.JsonProperty;
|
||||
import com.intellij.lang.documentation.DocumentationProvider;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.impl.FakePsiElement;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.jsonSchema.extension.JsonLikePsiWalker;
|
||||
@@ -23,7 +26,7 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
return findSchemaAndGenerateDoc(element, originalElement, true);
|
||||
return findSchemaAndGenerateDoc(element, originalElement, true, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -35,11 +38,20 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
|
||||
return findSchemaAndGenerateDoc(element, originalElement, false);
|
||||
String forcedPropName = null;
|
||||
if (element instanceof FakeDocElement) {
|
||||
forcedPropName = ((FakeDocElement)element).myAltName;
|
||||
element = ((FakeDocElement)element).myContextElement;
|
||||
}
|
||||
return findSchemaAndGenerateDoc(element, originalElement, false, forcedPropName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String findSchemaAndGenerateDoc(PsiElement element, @Nullable PsiElement originalElement, final boolean preferShort) {
|
||||
public static String findSchemaAndGenerateDoc(PsiElement element,
|
||||
@Nullable PsiElement originalElement,
|
||||
final boolean preferShort,
|
||||
@Nullable String forcedPropName) {
|
||||
if (element instanceof FakeDocElement) return null;
|
||||
element = ObjectUtils.coalesce(originalElement, element);
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile == null) return null;
|
||||
@@ -49,12 +61,14 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
|
||||
final JsonSchemaObject rootSchema = service.getSchemaObject(virtualFile);
|
||||
if (rootSchema == null) return null;
|
||||
|
||||
return generateDoc(element, rootSchema, preferShort);
|
||||
return generateDoc(element, rootSchema, preferShort, forcedPropName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String generateDoc(@NotNull final PsiElement element,
|
||||
@NotNull final JsonSchemaObject rootSchema, final boolean preferShort) {
|
||||
@NotNull final JsonSchemaObject rootSchema,
|
||||
final boolean preferShort,
|
||||
@Nullable String forcedPropName) {
|
||||
final JsonLikePsiWalker walker = JsonLikePsiWalker.getWalker(element, rootSchema);
|
||||
if (walker == null) return null;
|
||||
|
||||
@@ -62,6 +76,12 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
|
||||
if (checkable == null) return null;
|
||||
final List<JsonSchemaVariantsTreeBuilder.Step> position = walker.findPosition(checkable, true);
|
||||
if (position == null) return null;
|
||||
if (forcedPropName != null) {
|
||||
if (position.isEmpty()) return null;
|
||||
final JsonSchemaVariantsTreeBuilder.Step lastStep = position.get(position.size() - 1);
|
||||
if (lastStep.getName() == null) return null;
|
||||
position.set(position.size() - 1, JsonSchemaVariantsTreeBuilder.Step.createPropertyStep(forcedPropName));
|
||||
}
|
||||
final Collection<JsonSchemaObject> schemas = new JsonSchemaResolver(rootSchema, true, position).resolve();
|
||||
|
||||
String htmlDescription = null;
|
||||
@@ -146,6 +166,9 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element) {
|
||||
if (element instanceof JsonProperty && object instanceof String) {
|
||||
return new FakeDocElement(((JsonProperty)element).getNameElement(), (String)object);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -154,4 +177,25 @@ public class JsonSchemaDocumentationProvider implements DocumentationProvider {
|
||||
public PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class FakeDocElement extends FakePsiElement {
|
||||
private final PsiElement myContextElement;
|
||||
private final String myAltName;
|
||||
|
||||
private FakeDocElement(PsiElement context, String name) {
|
||||
myContextElement = context;
|
||||
myAltName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getParent() {
|
||||
return myContextElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getTextRangeInParent() {
|
||||
return myContextElement.getTextRange().shiftLeft(myContextElement.getTextOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class YamlJsonSchemaDocumentationProvider extends DocumentationProviderEx
|
||||
if (virtualFile == null) return null;
|
||||
JsonSchemaObject schemaObject = jsonSchemaService.getSchemaObject(virtualFile);
|
||||
if (schemaObject == null) return null;
|
||||
return JsonSchemaDocumentationProvider.generateDoc(element, schemaObject, preferShort);
|
||||
return JsonSchemaDocumentationProvider.generateDoc(element, schemaObject, preferShort, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+5
@@ -79,4 +79,9 @@ public class YamlByJsonSchemaHeavyCompletionTest extends JsonBySchemaHeavyComple
|
||||
public void testRequiredPropsLast() throws Exception {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testWhitespaceAfterColon() throws Exception {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user