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: add support for parsing, inspecting and autocompleting in a group stage written using Spring Data MongoDB INTELLIJ-175 #132

Merged
merged 5 commits into from
Jan 24, 2025

Conversation

himanshusinghs
Copy link
Contributor

Description

This PR adds support for parsing, inspecting and autocompleting in a group stage written using Aggregation.group and chained GroupOperations using sum, avg, first, last, max, min, push and addToSet.

Checklist

Open Questions

@github-actions github-actions bot added the feat label Jan 24, 2025
@github-actions github-actions bot added feat and removed feat labels Jan 24, 2025
Comment on lines -816 to -846
private fun parseComputedExpression(element: PsiElement): HasValueReference<PsiElement> {
val (constant, value) = element.tryToResolveAsConstant()
return HasValueReference(
when {
constant && value is String -> HasValueReference.Computed(
element,
type = ComputedBsonType(
BsonAny,
Node(
element,
listOf(
HasFieldReference(
FromSchema(element, value.trim('$'), value)
)
)
)
)
)
constant -> HasValueReference.Constant(
element,
value,
value?.javaClass.toBsonType(value)
)
!constant && element is PsiExpression -> HasValueReference.Runtime(
element,
element.type?.toBsonType() ?: BsonAny
)
else -> HasValueReference.Unknown as HasValueReference.ValueReference<PsiElement>
}
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed this method so I pulled it out of class and put it as an extension method on PsiElement, down below in the file.

methodCall.argumentList.expressions.toList()
} else {
val fieldsObjectExpression = methodCall.argumentList.expressions.getOrNull(0)
fieldsObjectExpression?.resolveFieldStringExpressionsFromFieldsObject() ?: emptyList()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a method that I am reusing from ProjectStageParser. That was originally a private method but I pulled it out as an extension method to support this.

Comment on lines -72 to -82
private fun fieldObjectExpressionToProjectedFieldNode(
fieldObjectExpression: PsiExpression,
projectionName: Name
): Node<PsiElement>? {
val fieldExpression = fieldObjectExpression.resolveFieldStringExpressionFromFieldObject()
?: return null
return createProjectedFieldNode(
fieldExpression = fieldExpression,
projectionName = projectionName
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire method was not needed after refactor so I removed it.

}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire logic is shifted down below as extension method

Copy link

github-actions bot commented Jan 24, 2025

Coverage Report

Overall Project 80.13% -0.39%
Files changed 85.2%

File Coverage
FieldCheckingLinter.kt 96.06% -2.54%
ProjectStageParser.kt 93.54% -1.9%
GroupStageParser.kt 92.25% -7.75%
SpringCriteriaDialectParser.kt 88.93%
JavaDriverDialectParser.kt 88.03% -0.66%
Parser.kt 81.48%
HasFieldReference.kt 53.55% -22.34% 🚫

Copy link

🤖 Benchmark Comparison for chore: add CHANGELOG entry

Benchmark Previous Current Change
com.mongodb.jbplugin.jmh.SampleBenchmark.init 2,656,261,067.12 ops/s 2,676,614,310.27 ops/s 0.77%

@himanshusinghs himanshusinghs requested a review from kmruiz January 24, 2025 16:06
Copy link

🤖 Benchmark Comparison for chore: minor rename of variables

Benchmark Previous Current Change
com.mongodb.jbplugin.jmh.SampleBenchmark.init 2,656,261,067.12 ops/s 2,598,473,547.98 ops/s -2.18%

@himanshusinghs himanshusinghs merged commit ba14a57 into main Jan 24, 2025
12 checks passed
@himanshusinghs himanshusinghs deleted the INTELLIJ-175-spring-group branch January 24, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants