Skip to content

Commit

Permalink
Merge pull request #237 from cedricziel/type-completion
Browse files Browse the repository at this point in the history
[Fluid] Complete types of provided variables
  • Loading branch information
cedricziel authored Aug 31, 2018
2 parents 98c88b7 + 7461a55 commit 3e31896
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cedricziel.idea.fluid.util;

import com.cedricziel.idea.fluid.extensionPoints.VariableProvider;
import com.cedricziel.idea.fluid.lang.psi.FluidFieldChain;
import com.cedricziel.idea.fluid.lang.psi.FluidFieldExpr;
import com.cedricziel.idea.fluid.lang.psi.FluidInlineChain;
import com.cedricziel.idea.fluid.lang.psi.FluidTypes;
import com.cedricziel.idea.fluid.variables.FluidTypeContainer;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static String getParentIdentifierAsTextUntil(PsiElement psiElement, Eleme
}
}

for (PsiElement parent = psiElement.getParent(); parent instanceof FluidFieldChain; parent = parent.getParent()) {
for (PsiElement parent = psiElement.getParent(); parent instanceof FluidFieldExpr; parent = parent.getParent()) {
if (pattern.accepts(parent)) {
if (includeMatching) {
return parent.getText() + prevText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.cedricziel.idea.fluid.AbstractFluidTest;

import java.util.List;

public class FluidCompletionContributorTest extends AbstractFluidTest {
@Override
protected String getTestDataPath() {
Expand Down Expand Up @@ -31,4 +33,16 @@ public void testInlineArgumentsAreCompleted() {
assertLookupStringOnFluidCaret("{namespace a=App\\ViewHelpers}\n{ a:foo(u<caret>) }", "uid", "uncle");
assertLookupStringOnFluidCaret("{namespace a=App\\ViewHelpers}\n{ a:foo(u<caret>:) }", "uid", "uncle");
}

public void testVariablesFromControllerAndTypesAreCompleted() {
myFixture.copyFileToProject("classes.php");
myFixture.copyFileToProject("Index.fluid", "Book/Index.fluid");

myFixture.configureByFile("Book/Index.fluid");

myFixture.completeBasic();

List<String> lookupElementStrings = myFixture.getLookupElementStrings();
assertContainsElements(lookupElementStrings, "author");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{book.<caret>}
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,33 @@ public function setRenderChildrenClosure(\Closure $renderChildrenClosure)
}
}
}

namespace My\App\Domain {
class Author
{
}

class Book
{
/**
* @return Author
*/
public function getAuthor()
{

}
}
}

namespace My\App\Controller {

use My\App\Domain\Book;

class BookController
{
public function indexAction()
{
$this->view->assign('book', new Book());
}
}
}

0 comments on commit 3e31896

Please sign in to comment.