|
24 | 24 | import org.jetbrains.annotations.Nullable; |
25 | 25 |
|
26 | 26 | import java.util.*; |
| 27 | +import java.util.regex.Matcher; |
| 28 | +import java.util.regex.Pattern; |
27 | 29 |
|
28 | 30 | public class QueryBuilderCompletionContributor extends CompletionContributor { |
29 | 31 |
|
@@ -171,6 +173,9 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters |
171 | 173 | return; |
172 | 174 | } |
173 | 175 |
|
| 176 | + // $qb->andWhere('foo.id = ":foo_id"') |
| 177 | + addParameterNameCompletion(completionParameters, completionResultSet, psiElement); |
| 178 | + |
174 | 179 | // querybuilder parser is too slow longer values, and that dont make sense here at all |
175 | 180 | // user can fire a manual completion event, when needed... |
176 | 181 | if(completionParameters.isAutoPopup()) { |
@@ -199,6 +204,35 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters |
199 | 204 |
|
200 | 205 | } |
201 | 206 |
|
| 207 | + private void addParameterNameCompletion(CompletionParameters completionParameters, CompletionResultSet completionResultSet, PsiElement psiElement) { |
| 208 | + |
| 209 | + PsiElement literalExpr = psiElement.getParent(); |
| 210 | + if(!(literalExpr instanceof StringLiteralExpression)) { |
| 211 | + return; |
| 212 | + } |
| 213 | + |
| 214 | + String content = PsiElementUtils.getStringBeforeCursor((StringLiteralExpression) literalExpr, completionParameters.getOffset() - literalExpr.getTextOffset()); |
| 215 | + if(content == null) { |
| 216 | + return; |
| 217 | + } |
| 218 | + |
| 219 | + Matcher matcher = Pattern.compile("(\\w+)\\.(\\w+)[\\s+]*[=><]+[\\s+]$").matcher(content); |
| 220 | + if (matcher.find()) { |
| 221 | + final String complete = matcher.group(1) + "_" + matcher.group(2); |
| 222 | + |
| 223 | + // fill underscore and underscore completion |
| 224 | + Set<String> strings = new HashSet<String>() {{ |
| 225 | + add(complete); |
| 226 | + add(fr.adrienbrault.idea.symfony2plugin.util.StringUtils.camelize(complete, true)); |
| 227 | + }}; |
| 228 | + |
| 229 | + for(String string: strings) { |
| 230 | + completionResultSet.addElement(LookupElementBuilder.create(":" + string).withIcon(Symfony2Icons.DOCTRINE)); |
| 231 | + } |
| 232 | + |
| 233 | + } |
| 234 | + } |
| 235 | + |
202 | 236 | }); |
203 | 237 |
|
204 | 238 | // $qb->join('test.foo', 'foo'); |
|
0 commit comments