mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
[json] IJPL-63554 Use the new schema resolve API in dependent plugins
GitOrigin-RevId: a43d3c69c27b36f4e75b451ccdf972771014f5ca
This commit is contained in:
committed by
intellij-monorepo-bot
parent
41ccf9c452
commit
ba0a9dc16e
@@ -12,6 +12,7 @@ import com.intellij.codeInsight.completion.PrioritizedLookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.json.pointer.JsonPointerPosition
|
||||
import com.intellij.openapi.editor.EditorModificationUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
@@ -23,12 +24,14 @@ import com.intellij.util.Consumer
|
||||
import com.intellij.util.ThreeState
|
||||
import com.jetbrains.jsonSchema.extension.JsonLikePsiWalker
|
||||
import com.jetbrains.jsonSchema.extension.adapters.JsonPropertyAdapter
|
||||
import com.jetbrains.jsonSchema.extension.adapters.JsonValueAdapter
|
||||
import com.jetbrains.jsonSchema.ide.JsonSchemaService
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaDocumentationProvider
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaObject
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaResolver
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaType
|
||||
import com.jetbrains.jsonSchema.impl.light.legacy.JsonSchemaObjectReadingUtils
|
||||
import com.jetbrains.jsonSchema.impl.tree.JsonSchemaNodeExpansionRequest
|
||||
import one.util.streamex.StreamEx
|
||||
import org.toml.ide.experiments.TomlExperiments
|
||||
import org.toml.lang.psi.TomlLiteral
|
||||
@@ -68,7 +71,8 @@ class TomlJsonSchemaCompletionContributor : CompletionContributor() {
|
||||
val pointerPosition = walker.findPosition(checkable, isName == ThreeState.NO)
|
||||
if (pointerPosition == null || pointerPosition.isEmpty && isName == ThreeState.NO) return
|
||||
|
||||
val schemas = JsonSchemaResolver(project, rootSchema, pointerPosition).resolve()
|
||||
val expansionRequest = JsonSchemaNodeExpansionRequest(walker.createValueAdapter(checkable), false)
|
||||
val schemas = JsonSchemaResolver(project, rootSchema, pointerPosition, expansionRequest).resolve()
|
||||
val knownNames = hashSetOf<String>()
|
||||
|
||||
for (schema in schemas) {
|
||||
@@ -110,14 +114,14 @@ class TomlJsonSchemaCompletionContributor : CompletionContributor() {
|
||||
|
||||
if (isTomlHeader && JsonSchemaObjectReadingUtils.guessType(jsonSchemaObject) !in JSON_COMPOUND_TYPES) continue
|
||||
|
||||
addPropertyVariant(variant, jsonSchemaObject)
|
||||
addPropertyVariant(variant, jsonSchemaObject, adapter?.nameValueAdapter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NAME_SHADOWING")
|
||||
private fun addPropertyVariant(key: String, jsonSchemaObject: JsonSchemaObject) {
|
||||
val currentVariants = JsonSchemaResolver(project, jsonSchemaObject).resolve()
|
||||
private fun addPropertyVariant(key: String, jsonSchemaObject: JsonSchemaObject, originalPositionAdapter: JsonValueAdapter?) {
|
||||
val currentVariants = JsonSchemaResolver(project, jsonSchemaObject, JsonPointerPosition(), JsonSchemaNodeExpansionRequest(originalPositionAdapter, false)).resolve()
|
||||
val jsonSchemaObject = currentVariants.firstOrNull() ?: jsonSchemaObject
|
||||
|
||||
var description = JsonSchemaDocumentationProvider.getBestDocumentation(true, jsonSchemaObject)
|
||||
|
||||
@@ -47,7 +47,7 @@ public class YamlJsonSchemaDeprecationInspection extends YamlJsonSchemaInspectio
|
||||
return;
|
||||
}
|
||||
|
||||
final MatchResult result = new JsonSchemaResolver(project, schema, position).detailedResolve();
|
||||
final MatchResult result = new JsonSchemaResolver(project, schema, position, walker.createValueAdapter(key)).detailedResolve();
|
||||
for (JsonSchemaObject object : result.mySchemas) {
|
||||
String message = object.getDeprecationMessage();
|
||||
if (message != null) {
|
||||
|
||||
@@ -29,18 +29,20 @@ public class YamlJsonSchemaGotoDeclarationHandler implements GotoDeclarationHand
|
||||
|
||||
final IElementType elementType = PsiUtilCore.getElementType(sourceElement);
|
||||
if (elementType != YAMLTokenTypes.SCALAR_KEY) return null;
|
||||
final YAMLKeyValue literal = PsiTreeUtil.getParentOfType(sourceElement, YAMLKeyValue.class);
|
||||
final YAMLKeyValue keyValue = PsiTreeUtil.getParentOfType(sourceElement, YAMLKeyValue.class);
|
||||
// do not override injected references
|
||||
if (literal == null || literal.getKey() != sourceElement|| !ArrayUtil.isEmpty(literal.getReferences())) return null;
|
||||
final JsonSchemaService service = JsonSchemaService.Impl.get(literal.getProject());
|
||||
final PsiFile containingFile = literal.getContainingFile();
|
||||
if (keyValue == null || keyValue.getKey() != sourceElement|| !ArrayUtil.isEmpty(keyValue.getReferences())) return null;
|
||||
final JsonSchemaService service = JsonSchemaService.Impl.get(keyValue.getProject());
|
||||
final PsiFile containingFile = keyValue.getContainingFile();
|
||||
final VirtualFile file = containingFile.getVirtualFile();
|
||||
if (file == null || !service.isApplicableToFile(file)) return null;
|
||||
final JsonPointerPosition steps = YamlJsonPsiWalker.INSTANCE.findPosition(literal, true);
|
||||
final JsonPointerPosition steps = YamlJsonPsiWalker.INSTANCE.findPosition(keyValue, true);
|
||||
if (steps == null) return null;
|
||||
final JsonSchemaObject schemaObject = service.getSchemaObject(containingFile);
|
||||
if (schemaObject != null) {
|
||||
final PsiElement target = new JsonSchemaResolver(sourceElement.getProject(), schemaObject, steps).findNavigationTarget(literal.getValue());
|
||||
final PsiElement target = new JsonSchemaResolver(sourceElement.getProject(), schemaObject, steps, YamlJsonPsiWalker.INSTANCE.createValueAdapter(keyValue.getParent()))
|
||||
//final PsiElement target = new JsonSchemaResolver(sourceElement.getProject(), schemaObject, steps, YamlJsonPsiWalker.INSTANCE.getParentPropertyAdapter(keyValue).getNameValueAdapter())
|
||||
.findNavigationTarget(keyValue.getValue());
|
||||
if (target != null) {
|
||||
return new PsiElement[] {target};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user