Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 2.6.0 #104

Merged
merged 16 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(yaml): resolve references in single quotes '#/components/...'
  • Loading branch information
Pakisan committed Aug 28, 2024
commit 646db5695020a661d86f4c4a5fc99eaa5bf636f6
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ version = "2.6.0+jre17"
repositories {
mavenCentral()
intellijPlatform {
jetbrainsRuntime()
defaultRepositories()
}
}
@@ -26,8 +27,9 @@ dependencies {
"org.jetbrains.plugins.yaml"
))

instrumentationTools()
pluginVerifier()
jetbrainsRuntime()
instrumentationTools()
testFramework(TestFrameworkType.Platform)
}

Original file line number Diff line number Diff line change
@@ -18,8 +18,10 @@ abstract class PsiFileXPath<AsyncAPISpecification: PsiFile> {
*/
fun compileXPath(specificationReference: String): String {
return specificationReference
.removePrefix("\"")
.removePrefix("\"") // double quoted "some text"
.removeSuffix("\"")
.removePrefix("\'") // single quoted 'some text'
.removeSuffix("\'")
.replace("#/", "")
.split("/")
.joinToString(".", "$.", "")
Original file line number Diff line number Diff line change
@@ -14,7 +14,11 @@ object YamlFileXPath: PsiFileXPath<YAMLFile>() {

override fun findText(asyncAPISpecification: YAMLFile?, psiXPath: String, partialMatch: Boolean): List<String> {
return findPsi(asyncAPISpecification, psiXPath, partialMatch).map {
it.text.removePrefix("\"").removeSuffix("\"")
it.text
.removePrefix("\"") // double quoted "some text"
.removeSuffix("\"")
.removePrefix("\'") // single quoted 'some text'
.removeSuffix("\'")
}
}

Original file line number Diff line number Diff line change
@@ -84,11 +84,23 @@ class AsyncAPIFileReference(
}

private fun extractFileLocation(fileReference: String): String? {
return fileReference.removePrefix("\"").removeSuffix("\"").split("#/").firstOrNull()
return fileReference
.removePrefix("\"") // double quoted 'some text'
.removeSuffix("\"")
.removePrefix("\'") // single quoted 'some text'
.removeSuffix("\'")
.split("#/")
.firstOrNull()
}

private fun extractLocalReference(fileReference: String): String? {
return fileReference.removePrefix("\"").removeSuffix("\"").split("#/").getOrNull(1)
return fileReference
.removePrefix("\"") // double quoted 'some text'
.removeSuffix("\"")
.removePrefix("\'") // single quoted 'some text'
.removeSuffix("\'")
.split("#/")
.getOrNull(1)
}

private fun findFile(fileLocation: String): PsiFile? {
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ class AsyncAPISpecificationReferenceContributor: PsiReferenceContributor() {
return expectedChild.withParent(expectedParent)
}

private fun fileReferencePattern(): PsiElementPattern.Capture<YAMLValue> {
val expectedChild = PlatformPatterns.psiElement(YAMLValue::class.java)
private fun fileReferencePattern(): PsiElementPattern.Capture<YAMLQuotedText> {
val expectedChild = PlatformPatterns.psiElement(YAMLQuotedText::class.java)
.withText(StandardPatterns.string().contains(".yaml"))

val expectedParent = PlatformPatterns.psiElement(YAMLKeyValue::class.java)
Original file line number Diff line number Diff line change
@@ -14,7 +14,10 @@ class AsyncAPIFileReferenceProvider: PsiReferenceProvider() {

override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> {
/* experimental */
val value = element.text.removePrefix("\"").removeSuffix("\"")
val value = element.text.removePrefix("\"") // Double quoted "some text"
.removeSuffix("\"")
.removePrefix("\'") // Single quoted 'some text'
.removePrefix("\'")
val textRange = TextRange(1, value.length + 1)
/* experimental */

Original file line number Diff line number Diff line change
@@ -14,7 +14,10 @@ class AsyncAPILocalReferenceProvider: PsiReferenceProvider() {

override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> {
/* experimental */
val value = element.text.removePrefix("\"").removeSuffix("\"")
val value = element.text.removePrefix("\"") // Double quoted "some text"
.removeSuffix("\"")
.removePrefix("\'") // Single quoted 'some text'
.removeSuffix("\'")
val textRange = TextRange(1, value.length + 1)
/* experimental */

Loading