From 8da26ae318573613b6f373b83d58e1ebe527e88c Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Thu, 14 Dec 2023 01:29:36 +0400 Subject: [PATCH] feat: v3 collect referenced components --- .../plugin/idea/_core/xpath/PsiFileXPath.kt | 2 +- .../index/v3/AsyncAPISpecificationIndex.kt | 63 +++++++++++ ...syncAPISpecificationReferencesCollector.kt | 106 +++++++++++++++++- 3 files changed, 169 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/asyncapi/plugin/idea/_core/xpath/PsiFileXPath.kt b/src/main/kotlin/com/asyncapi/plugin/idea/_core/xpath/PsiFileXPath.kt index 4522984..b711988 100644 --- a/src/main/kotlin/com/asyncapi/plugin/idea/_core/xpath/PsiFileXPath.kt +++ b/src/main/kotlin/com/asyncapi/plugin/idea/_core/xpath/PsiFileXPath.kt @@ -5,7 +5,7 @@ import com.intellij.psi.PsiFile /** * Dummy implementation of XPath for [PsiFile]. - * + * // TODO: Support collections * @author Pavel Bodiachevskii */ abstract class PsiFileXPath { diff --git a/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationIndex.kt b/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationIndex.kt index 57447e0..edd0b1c 100644 --- a/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationIndex.kt +++ b/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationIndex.kt @@ -59,6 +59,69 @@ class AsyncAPISpecificationIndex: FileBasedIndexExtension>() @JvmStatic val references = "references" + @JvmStatic + val tags = "tags" + + @JvmStatic + val externalDocs = "externalDocs" + + @JvmStatic + val servers = "servers" + + @JvmStatic + val serverVariables = "serverVariables" + + @JvmStatic + val serverBindings = "serverBindings" + + @JvmStatic + val channels = "channels" + + @JvmStatic + val channelParameters = "channelParameters" + + @JvmStatic + val channelBindings = "channelBindings" + + @JvmStatic + val operations = "operations" + + @JvmStatic + val operationBindings = "operationBindings" + + @JvmStatic + val operationTraits = "operationTraits" + + @JvmStatic + val operationReplies = "operationReplies" + + @JvmStatic + val operationReplyAddresses = "operationReplyAddresses" + + @JvmStatic + val messages = "messages" + + @JvmStatic + val messageHeaders = "messageHeaders" + + @JvmStatic + val messagePayloads = "messagePayloads" + + @JvmStatic + val messageCorrelationIds = "messageCorrelationIds" + + @JvmStatic + val messageBindings = "messageBindings" + + @JvmStatic + val messageTraits = "messageTraits" + + @JvmStatic + val schemas = "schemas" + + @JvmStatic + val securitySchemes = "securitySchemes" + } } \ No newline at end of file diff --git a/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationReferencesCollector.kt b/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationReferencesCollector.kt index add5c2c..32d593d 100644 --- a/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationReferencesCollector.kt +++ b/src/main/kotlin/com/asyncapi/plugin/idea/extensions/index/v3/AsyncAPISpecificationReferencesCollector.kt @@ -13,7 +13,111 @@ class AsyncAPISpecificationReferencesCollector( ): AbstractAsyncAPISpecificationReferencesCollector(asyncAPISpecification, asyncAPISpecificationDir) { override fun possibleReferencesLocation(): Map> { - return emptyMap() + return mapOf( + AsyncAPISpecificationIndex.tags to setOf( + "\$.info.tags.*.\$ref", + "\$.servers.*.tags.*.\$ref", + "\$.channels.*.tags.*.\$ref", + "\$.operations.*.tags.*.\$ref", + "\$.channels.*.messages.*.tags.*.\$ref", + "\$.operations.*.messages.*.tags.*.\$ref", + "\$.components.tags.*.\$ref", + ), + AsyncAPISpecificationIndex.externalDocs to setOf( + "\$.info.externalDocs.\$ref", + "\$.servers.*.externalDocs.\$ref", + "\$.channels.*.externalDocs.\$ref", + "\$.operations.*.externalDocs.\$ref", + "\$.channels.*.messages.*.externalDocs.\$ref", + "\$.operations.*.messages.*.externalDocs.\$ref", + "\$.components.externalDocs.*.\$ref", + ), + AsyncAPISpecificationIndex.servers to setOf( + "\$.servers.*.\$ref", + "\$.channels.*.servers.*.\$ref", + "\$.components.servers.*.\$ref", + ), + AsyncAPISpecificationIndex.serverVariables to setOf( + "\$.servers.*.variables.*.\$ref", + "\$.components.serverVariables.*.\$ref", + ), + AsyncAPISpecificationIndex.serverBindings to setOf( + "\$.servers.*.bindings.*.\$ref", + "\$.components.serverBindings.*.\$ref", + ), + AsyncAPISpecificationIndex.channels to setOf( + "\$.channels.*.\$ref", + "\$.operations.*.channel.\$ref", + "\$.operations.*.reply.*.channel.\$ref", + "\$.components.replies.*.channel.\$ref", + "\$.components.channels.*.\$ref", + ), + AsyncAPISpecificationIndex.channelParameters to setOf( + "\$.channels.*.parameters.*.\$ref", + "\$.components.parameters.*.\$ref", + ), + AsyncAPISpecificationIndex.channelBindings to setOf( + "\$.channels.*.bindings.*.\$ref", + "\$.components.channelBindings.*.\$ref", + ), + AsyncAPISpecificationIndex.operations to setOf( + "\$.operations.*.\$ref", + "\$.components.operations.*.\$ref", + ), + AsyncAPISpecificationIndex.operationBindings to setOf( + "\$.operations.*.bindings.*.\$ref", + "\$.components.operationBindings.*.\$ref", + ), + AsyncAPISpecificationIndex.operationTraits to setOf( + "\$.operations.*.traits.*.\$ref", + "\$.components.operationTraits.*.\$ref", + ), + AsyncAPISpecificationIndex.operationReplies to setOf( + "\$.operations.*.reply.*.\$ref", + "\$.components.replies.*.\$ref", + ),AsyncAPISpecificationIndex.operationReplyAddresses to setOf( + "\$.operations.*.reply.*.address.\$ref", + "\$.components.replies.*.address.\$ref", + ), + AsyncAPISpecificationIndex.messages to setOf( + "\$.channels.*.messages.*.\$ref", + "\$.operations.*.messages.*.\$ref", + "\$.operations.*.reply.*.messages.*.\$ref", + "\$.components.replies.*.messages.*.\$ref", + "\$.components.messages.*.\$ref", + ), + AsyncAPISpecificationIndex.messageHeaders to setOf( + "\$.channels.*.messages.*.headers.\$ref", + "\$.operations.*.messages.*.headers.\$ref", + ), + AsyncAPISpecificationIndex.messagePayloads to setOf( + "\$.channels.*.messages.*.payload.\$ref", + "\$.operations.*.messages.*.payload.\$ref", + ), + AsyncAPISpecificationIndex.messageCorrelationIds to setOf( + "\$.channels.*.messages.*.correlationId.\$ref", + "\$.operations.*.messages.*.correlationId.\$ref", + "\$.components.correlationIds.*.\$ref", + ), + AsyncAPISpecificationIndex.messageBindings to setOf( + "\$.channels.*.messages.*.bindings.*.\$ref", + "\$.operations.*.messages.*.bindings.*.\$ref", + "\$.components.messageBindings.*.\$ref", + ), + AsyncAPISpecificationIndex.messageTraits to setOf( + "\$.channels.*.messages.*.traits.*.\$ref", + "\$.operations.*.messages.*.traits.*.\$ref", + "\$.components.messageTraits.*.\$ref", + ), + AsyncAPISpecificationIndex.securitySchemes to setOf( + "\$.servers.*.security.*.\$ref", + "\$.operations.*.security.*.\$ref", + "\$.components.securitySchemes.*.\$ref", + ), + AsyncAPISpecificationIndex.schemas to setOf( + "\$.components.schemas.*.\$ref", + ), + ) } } \ No newline at end of file