1414import com .intellij .codeInsight .completion .CompletionParameters ;
1515import com .intellij .codeInsight .completion .CompletionProvider ;
1616import com .intellij .codeInsight .completion .CompletionResultSet ;
17- import com .intellij .codeInsight .completion .CompletionUtil ;
1817import com .intellij .codeInsight .lookup .LookupElementBuilder ;
1918import com .intellij .openapi .diagnostic .Logger ;
2019import com .intellij .openapi .project .Project ;
2625import com .intellij .psi .ResolveState ;
2726import com .intellij .psi .util .PsiTreeUtil ;
2827import com .intellij .util .ProcessingContext ;
28+ import org .apache .commons .lang3 .StringUtils ;
2929import org .jetbrains .annotations .NotNull ;
3030import org .jetbrains .annotations .Nullable ;
3131
@@ -40,7 +40,6 @@ public abstract class ORMCompletionProvider extends CompletionProvider<Completio
4040 private static final Logger LOG = Logger .getInstance (ORMCompletionProvider .class );
4141
4242 protected void addCompletions (@ NotNull CompletionParameters parameters , @ NotNull ProcessingContext context , @ NotNull CompletionResultSet result ) {
43-
4443 PsiElement currentElement = parameters .getPosition ();
4544
4645 LOG .info ("currentElement: " + currentElement + " text: " + currentElement .getText ());
@@ -59,6 +58,37 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull
5958 if (!ORMPsiTreeUtil .callHasArgumentAtIndex (goCallExpr , argumentIndex , currentElement .getParent ()) && !(currentElement .getParent ().getParent () instanceof GoKey ))
6059 return ;
6160
61+ String prefix = result .getPrefixMatcher ().getPrefix ();
62+ int lastSpace = prefix .lastIndexOf (' ' );
63+ if (lastSpace >= 0 && lastSpace < prefix .length () - 1 ) {
64+ String previous = prefix .substring (0 , lastSpace );
65+ LOG .info ("previous: " + previous + "origin prefix: " + prefix );
66+
67+ prefix = prefix .substring (lastSpace + 1 );
68+ LOG .info ("new prefix: " + prefix );
69+
70+ result = result .withPrefixMatcher (prefix );
71+
72+ if (StringUtils .containsAnyIgnoreCase (previous , Types .USE_LOGICAL_OPERATOR_SCENE .toArray (new CharSequence []{}))) {
73+ for (String s : Types .LOGICAL_OPERATOR_EXPR ) {
74+ if (StringUtils .containsIgnoreCase (s , prefix )) {
75+ result .addElement (LookupElementBuilder
76+ .create (s )
77+ .withPresentableText (s )
78+ .withIcon (getIcon ()));
79+
80+ String lowerCase = s .toLowerCase ();
81+
82+ result .addElement (LookupElementBuilder
83+ .create (lowerCase )
84+ .withPresentableText (lowerCase )
85+ .withIcon (getIcon ()));
86+ }
87+ }
88+ return ;
89+ }
90+ }
91+
6292 GoCompositeElement argument = findTargetGoCompositeElement (currentElement );
6393
6494 LOG .info ("argument: " + argument );
@@ -352,20 +382,17 @@ private void scanFields(@NotNull CompletionParameters parameters, GoCallableDesc
352382 comment = GoDocumentationProvider .getCommentText (GoDocumentationProvider .getCommentsForElement (field ), false );
353383 }
354384
355- GoStringLiteral goStringLiteral = (GoStringLiteral ) parameters .getPosition ().getParent ();
356- String currentString = goStringLiteral .getDecodedText ().replace (CompletionUtil .DUMMY_IDENTIFIER , "" );
357-
358- if (column != null && !column .contains (currentString .trim ())) continue ;
385+ if (column != null && !column .contains (result .getPrefixMatcher ().getPrefix ())) continue ;
359386
360- addElement (parameters , result , column , comment , type , goTypeSpec );
387+ addElement (result , column , comment , type , goTypeSpec );
361388
362389 if (!(parameters .getPosition ().getParent ().getParent () instanceof GoKey )) {
363390 Map <GoCallableDescriptor , List <String >> queryExpr = queryExpr ();
364391 if (queryExpr != null ) {
365392 List <String > whereExpr = queryExpr .get (descriptor );
366393 if (whereExpr != null ) {
367394 for (String s : whereExpr ) {
368- addElement (parameters , result , String .format (s , column ), comment , type , goTypeSpec );
395+ addElement (result , String .format (s , column ), comment , type , goTypeSpec );
369396 }
370397 }
371398 }
@@ -374,7 +401,7 @@ private void scanFields(@NotNull CompletionParameters parameters, GoCallableDesc
374401 }
375402 }
376403
377- private void addElement (@ NotNull CompletionParameters parameters , @ NotNull CompletionResultSet result , String column , String comment , String type , @ NotNull GoTypeSpec goTypeSpec ) {
404+ private void addElement (@ NotNull CompletionResultSet result , String column , String comment , String type , @ NotNull GoTypeSpec goTypeSpec ) {
378405 LookupElementBuilder builder = LookupElementBuilder
379406 .createWithSmartPointer (column , goTypeSpec )
380407 .withPresentableText (column )
0 commit comments