Skip to content

Commit

Permalink
Provide method name completion in @return doc even when ther is no pr…
Browse files Browse the repository at this point in the history
…eceeding return type
  • Loading branch information
klesun committed Aug 5, 2018
1 parent e9cac43 commit 4c879a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>lv.midiana.misc.phpstorm-plugins.deep-keys</id>
<name>deep-assoc-completion</name>
<version>2018.08.01.001</version>
<version>2018.08.01.002</version>
<vendor email="safronevev@gmail.com" url="http://midiana.lv/entry/phpstorm-deep-keys">Klesun</vendor>

<description><![CDATA[
Expand Down Expand Up @@ -37,6 +37,7 @@ This plugin greatly extends phpstorm's typing with associative array support<br/

<change-notes><![CDATA[
<ul>
<li>#42 Use _called_ class to resolve static::doSomething() rather than current class</li>
<li>Provide method name completion when typing self:: or static:: in phpdoc</li>
<li>#42 Use _called_ class to resolve static::$someProp rather than current class</li>
<li>Support ... operator in methods</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.PhpLanguage;
import com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocType;
import com.jetbrains.php.lang.documentation.phpdoc.psi.impl.tags.PhpDocReturnTagImpl;
import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocReturnTag;
import com.jetbrains.php.lang.psi.elements.*;
import org.jetbrains.annotations.NotNull;
Expand All @@ -20,9 +22,7 @@
import java.util.*;

import static org.klesun.deep_assoc_completion.completion_providers.DeepKeysPvdr.getMaxDepth;
import static org.klesun.lang.Lang.L;
import static org.klesun.lang.Lang.list;
import static org.klesun.lang.Lang.opt;
import static org.klesun.lang.Lang.*;

/**
* provides completion for class/functions inside a @param doc comment
Expand Down Expand Up @@ -82,8 +82,19 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
Project project = tagValue.getProject();

String prefix = "<?php\n$arg = ";
String regex = tagValue.getParent() instanceof PhpDocReturnTag
? "^\\s*(?:like|=|)\\s*(.+)$" : "^\\s*=\\s*(.+)$";
String regex = "^\\s*=\\s*(.+)$";
if (tagValue.getParent() instanceof PhpDocReturnTagImpl) {
PhpDocReturnTagImpl returnTag = (PhpDocReturnTagImpl)tagValue.getParent();
regex = "^\\s*(?:like|=|)\\s*(.+)$";
if (docValue.matches("::[a-zA-Z0-9_]*IntellijIdeaRulezzz")) {
// class name gets resolved as return type psi
String typePart = L(returnTag.getChildren())
.fop(toCast(PhpDocType.class))
.map(typ -> typ.getText())
.wap(parts -> Tls.implode("", parts));
docValue = typePart + docValue;
}
}
FuncCtx ctx = new FuncCtx(search);
ctx.fakeFileSource = opt(tagValue);
Tls.regex(regex, docValue)
Expand Down

0 comments on commit 4c879a7

Please sign in to comment.