Skip to content

Commit

Permalink
Allow specifying keys in @return php doc
Browse files Browse the repository at this point in the history
  • Loading branch information
klesun committed May 22, 2018
1 parent 7ab23fa commit 7dbc9d7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
19 changes: 17 additions & 2 deletions src/org/klesun/deep_assoc_completion/resolvers/MethCallRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.intellij.database.psi.DbPsiFacade;
import com.intellij.openapi.project.Project;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocReturnTag;
import com.jetbrains.php.lang.psi.elements.*;
import com.jetbrains.php.lang.psi.elements.impl.FieldReferenceImpl;
import com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl;
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
import org.klesun.deep_assoc_completion.DeepType;
import org.klesun.deep_assoc_completion.helpers.FuncCtx;
import org.klesun.deep_assoc_completion.helpers.MultiType;
import org.klesun.deep_assoc_completion.resolvers.var_res.DocParamRes;
import org.klesun.lang.Lang;
import org.klesun.lang.Opt;
import org.klesun.lang.Tls;
Expand Down Expand Up @@ -107,13 +109,26 @@ private MultiType findBuiltInRetType(Method meth, FuncCtx argCtx, MethodReferenc
return new MultiType(types);
}

private static MultiType parseReturnDoc(PhpDocReturnTag returnDoc, FuncCtx funcCtx)
{
FuncCtx docCtx = new FuncCtx(funcCtx.getSearch());
docCtx.fakeFileSource = opt(returnDoc);
return Tls.regex("^\\s*(like\\s*|)(.+)$", returnDoc.getTagValue())
.fop(match -> match.gat(1))
.fop(expr -> DocParamRes.parseExpression(expr, returnDoc.getProject(), docCtx))
.def(MultiType.INVALID_PSI);
}

public static F<FuncCtx, L<DeepType>> findMethRetType(Method meth)
{
L<Method> impls = meth.isAbstract()
? findOverridingMethods(meth)
: list(meth);
return (FuncCtx funcCtx) -> impls.fap(m ->
ClosRes.getReturnedValue(m, funcCtx).types);
return (FuncCtx funcCtx) -> impls.fap(m -> list(
ClosRes.getReturnedValue(m, funcCtx).types,
opt(meth.getDocComment()).map(doc -> doc.getReturnTag())
.fap(tag -> parseReturnDoc(tag, funcCtx).types)
).fap(a -> a));
}

private static List<Method> resolveMethodsNoNs(String clsName, String func, Project proj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DocParamRes(FuncCtx ctx)
this.ctx = ctx;
}

private static Opt<MultiType> parseExpression(String expr, Project project, FuncCtx docCtx)
public static Opt<MultiType> parseExpression(String expr, Project project, FuncCtx docCtx)
{
// adding "$arg = " so anonymous functions were parsed as expressions
expr = "<?php\n$arg = " + expr + ";";
Expand Down
10 changes: 5 additions & 5 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,7 @@ private static function testInArray()
}
}

//============================
// not implemented follow
//============================

/** pressing _Ctrl + Alt + ;_ and specifying test number (say 3) should get you to the 3-rd */
/** pressing _Tools -> deep-assoc-completion -> To N-th Test_ and specifying test number (say 3) should get you to the 3-rd */
public function testGetNthTestCase()
{
$list = [];
Expand All @@ -570,6 +566,10 @@ public function testGetNthTestCase()
return $list;
}

//============================
// not implemented follow
//============================

private static function makeCoolOutfit($materials)
{
return [
Expand Down
20 changes: 19 additions & 1 deletion tests/src/DeepTest/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Rbs\Parsers\Sabre\Pricing\PqParserFull;
use Rbs\Parsers\Sabre\Pricing\PqParserUnshiftOverflow;
use TestSamples\CmsSessionMemoryOverflow\CmsStatefulSession;
use TestSamples\CmsSessionMemoryOverflow\ICmsGdsTerminal;
use TouhouNs\ReimuHakurei;
use TouhouNs\YakumoRan;

Expand Down Expand Up @@ -1784,6 +1783,25 @@ public function provideYield()
return $list;
}

/** @return array [
* 'baseUrl' => 'http://midiana.lv',
* 'isDevelopment' => true,
* 'fluentdIp' => '128.0.0.1',
* 'fluentdPort' => '468138',
* ] */
private static function getLocalConfig()
{
return json_decode(file_get_contents('/var/www/html/local_config.json'), true);
}

public function provideReturnDoc()
{
$config = static::getLocalConfig();
$config['fluentdPort'];
$list[] = [$config, ['baseUrl' => [], 'isDevelopment' => [], 'fluentdIp' => [], 'fluentdPort' => []]];
return $list;
}

//=============================
// following are not implemented yet
//=============================
Expand Down

0 comments on commit 7dbc9d7

Please sign in to comment.