diff --git a/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaCrossReferencesTest.java b/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaCrossReferencesTest.java index b842cf180334..16471b16e212 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaCrossReferencesTest.java +++ b/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaCrossReferencesTest.java @@ -16,6 +16,9 @@ package com.jetbrains.jsonSchema; import com.intellij.codeInsight.lookup.impl.LookupImpl; +import com.intellij.json.psi.JsonObject; +import com.intellij.json.psi.JsonProperty; +import com.intellij.json.psi.JsonValue; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.extensions.AreaPicoContainer; @@ -503,4 +506,36 @@ public class JsonSchemaCrossReferencesTest extends JsonSchemaHeavyAbstractTest { } }); } + + public void testNavigateToDefinitionByRef() throws Exception { + skeleton(new Callback() { + @Override + public void registerSchemes() { + final String moduleDir = getModuleDir(getProject()); + addSchema(new JsonSchemaMappingsConfigurationBase.SchemaInfo("one", moduleDir + "/withReferenceToDefinitionSchema.json", false, Collections.emptyList())); + } + + @Override + public void configureFiles() throws Exception { + configureByFiles(null, "withReferenceToDefinitionSchema.json"); + } + + @Override + public void doCheck() { + int offset = myEditor.getCaretModel().getPrimaryCaret().getOffset(); + final PsiReference referenceAt = myFile.findReferenceAt(offset); + Assert.assertNotNull(referenceAt); + final PsiElement resolve = referenceAt.resolve(); + Assert.assertNotNull(resolve); + Assert.assertEquals("\"findDefinition\"", resolve.getText()); + final PsiElement parent = resolve.getParent(); + Assert.assertTrue(parent instanceof JsonProperty); + final JsonValue value = ((JsonProperty)parent).getValue(); + Assert.assertTrue(value instanceof JsonObject); + final JsonProperty anEnum = ((JsonObject)value).findProperty("enum"); + Assert.assertNotNull(anEnum); + Assert.assertEquals("[1,4,8]", anEnum.getValue().getText()); + } + }); + } } diff --git a/json/tests/testData/jsonSchema/crossReferences/withReferenceToDefinitionSchema.json b/json/tests/testData/jsonSchema/crossReferences/withReferenceToDefinitionSchema.json new file mode 100644 index 000000000000..debc7978d4c0 --- /dev/null +++ b/json/tests/testData/jsonSchema/crossReferences/withReferenceToDefinitionSchema.json @@ -0,0 +1,12 @@ +{ + "definitions": { + "findDefinition" : { + "enum": [1,4,8] + } + }, + "properties": { + "referent": { + "$ref": "#/definitions/findDefinition" + } + } +} \ No newline at end of file