-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide completion of class methods when referencing it in an array
- Loading branch information
Showing
4 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.klesun.deep_keys.entry; | ||
|
||
import com.intellij.codeInsight.completion.CompletionParameters; | ||
import com.intellij.codeInsight.completion.CompletionProvider; | ||
import com.intellij.codeInsight.completion.CompletionResultSet; | ||
import com.intellij.codeInsight.lookup.LookupElement; | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.util.ProcessingContext; | ||
import com.jetbrains.php.PhpIcons; | ||
import com.jetbrains.php.lang.psi.elements.Method; | ||
import com.jetbrains.php.lang.psi.elements.PhpExpression; | ||
import com.jetbrains.php.lang.psi.elements.impl.ArrayCreationExpressionImpl; | ||
import com.jetbrains.php.lang.psi.elements.impl.FunctionReferenceImpl; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.klesun.deep_keys.DeepType; | ||
import org.klesun.deep_keys.helpers.FuncCtx; | ||
import org.klesun.deep_keys.helpers.IFuncCtx; | ||
import org.klesun.deep_keys.helpers.MultiType; | ||
import org.klesun.deep_keys.helpers.SearchContext; | ||
import org.klesun.deep_keys.resolvers.ArrCtorRes; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.klesun.lang.Lang.*; | ||
|
||
/** | ||
* provides completion of method names in `[Some\ClassName::class, '']` | ||
*/ | ||
public class ArrFuncRefPvdr extends CompletionProvider<CompletionParameters> | ||
{ | ||
private static LookupElement makeLookup(Method method) | ||
{ | ||
return LookupElementBuilder.create(method.getName()) | ||
.bold() | ||
.withIcon(PhpIcons.METHOD) | ||
.withTypeText(method.getLocalType(false).toString()); | ||
} | ||
|
||
@Override | ||
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet result) | ||
{ | ||
long startTime = System.nanoTime(); | ||
L<Method> methods = opt(parameters.getPosition().getParent()) | ||
.fap(literal -> opt(literal.getParent()) | ||
.map(arrVal -> arrVal.getParent()) | ||
.fap(toCast(ArrayCreationExpressionImpl.class)) | ||
.map(arrCtor -> L(arrCtor.getChildren())) | ||
.flt(params -> params.size() == 2) | ||
.flt(params -> literal.isEquivalentTo(params.get(1).getFirstChild())) | ||
.fap(params -> params.gat(0)) | ||
.fap(ArrCtorRes::resolveClass) | ||
.map(cls -> L(cls.getMethods()).flt(meth -> meth.isStatic()))) | ||
.def(L()); | ||
|
||
methods.map(m -> makeLookup(m)).fch(result::addElement); | ||
result.addLookupAdvertisement("Press <Page Down> few times to skip built-in suggestions"); | ||
|
||
long elapsed = System.nanoTime() - startTime; | ||
System.out.println("Resolved in " + (elapsed / 1000000000.0) + " seconds"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters