Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nvlad committed Feb 3, 2017
2 parents 68968f3 + 44d1691 commit 9d0f80f
Show file tree
Hide file tree
Showing 29 changed files with 1,506 additions and 290 deletions.
43 changes: 37 additions & 6 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<idea-plugin version="2">
<id>com.yii2support</id>
<name>Yii2 Support</name>
<version>0.2.2</version>
<version>0.2.10.9</version>
<vendor email="[email protected]" url="http://nvlad.com">NVlad</vendor>

<description><![CDATA[
Yii2 Support for PhpStorm<br/>
<br/>
<strong>Features</strong>
<ul>
<li>Views (autocomplete, jump to view)</li>
<li>i18n (autocomplete, generate params array)</li>
<li>
Views<br/>
- View files completion<br/>
- Add View parameters after completion<br/>
- Inspection missed View files<br/>
- QuickFix for missed files<br/>
- Jump to View file (go to declaration)<br/>
- Inspection by required &amp; unused parameters for View render<br/>
- QuickFix for required &amp; unused parameters<br/>
- Update path to View file on file move<br/>
</li>
<li>i18n (completion, generate params array)</li>
</ul>
]]></description>

<change-notes><![CDATA[
<ul>
<li>Fix show autocompletion popup</li>
<li>Update path to View file on file move</li>
<li>Fixed replace View path on file rename</li>
<li>Fix mark as error view paths started with "//" or "@" (references to files is not work)</li>
</ul>
]]>
</change-notes>
Expand All @@ -33,8 +45,27 @@
<depends>com.intellij.modules.platform</depends>

<extensions defaultExtensionNs="com.intellij">
<completion.contributor language="PHP" implementationClass="com.yii2support.views.CompletionContributor"/>
<psi.referenceContributor language="PHP" implementation="com.yii2support.views.PsiReferenceContributor"/>
<!-- Views -->
<completion.contributor language="PHP" implementationClass="com.yii2support.views.completion.CompletionContributor"/>
<psi.referenceContributor language="PHP" implementation="com.yii2support.views.references.PsiReferenceContributor"/>
<renamePsiElementProcessor implementation="com.yii2support.views.refactor.RenameViewProcessor"/>
<localInspection language="PHP" shortName="MissedViewInspection"
displayName="Missing View file"
groupName="Views" groupPath="PHP,Framework,Yii2"
enabledByDefault="true" level="ERROR"
implementationClass="com.yii2support.views.inspections.MissedViewInspection"/>
<localInspection language="PHP" shortName="RequireParameterInspection"
displayName="Require parameters"
groupName="Views" groupPath="PHP,Framework,Yii2"
enabledByDefault="true" level="ERROR"
implementationClass="com.yii2support.views.inspections.RequireParameterInspection"/>
<localInspection language="PHP" shortName="UnusedParameterInspection"
displayName="Unused parameters"
groupName="Views" groupPath="PHP,Framework,Yii2"
enabledByDefault="true" level="WARNING"
implementationClass="com.yii2support.views.inspections.UnusedParameterInspection"/>

<!-- i18n -->
<completion.contributor language="PHP" implementationClass="com.yii2support.i18n.CompletionContributor"/>
</extensions>

Expand Down
9 changes: 9 additions & 0 deletions resources/inspectionDescriptions/MissedViewInspection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<body>
Check for View file existing
<!-- tooltip end -->
<p>
- QuickFix - create View file
</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
View require parameters
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
Detecting unused View parameters.
</body>
</html>
29 changes: 29 additions & 0 deletions src/com/yii2support/common/PhpUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.yii2support.common;

import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression;
import com.jetbrains.php.lang.psi.elements.ArrayHashElement;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashSet;

/**
* Created by NVlad on 23.01.2017.
*/
public class PhpUtil {
@NotNull
public static Collection<String> getArrayKeys(ArrayCreationExpression array) {
final HashSet<String> result = new HashSet<>();

Iterable<ArrayHashElement> items = array.getHashElements();

for (ArrayHashElement item : items) {
if (item.getKey() != null && item.getKey() instanceof StringLiteralExpression) {
result.add(((StringLiteralExpression) item.getKey()).getContents());
}
}

return result;
}
}
55 changes: 55 additions & 0 deletions src/com/yii2support/common/PsiUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.yii2support.common;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression;

/**
* Created by NVlad on 17.01.2017.
*/
public class PsiUtil {
public static void deleteArrayElement(PsiElement element) {
PsiElement next = element.getNextSibling();
String endArray = ((ArrayCreationExpression) element.getParent()).isShortSyntax() ? "]" : ")";

if (next instanceof PsiWhiteSpace && next.getNextSibling().getText() != null) {
if (next.getNextSibling().getText().equals(endArray)) {
next = next.getNextSibling();
}
}
if (next.getText().equals(endArray)) {
Boolean deleteComma = false;
if (element.getPrevSibling() instanceof PsiWhiteSpace) {
deleteComma = !element.getPrevSibling().getText().contains("\n");
element.getPrevSibling().delete();
}
if (deleteComma && element.getPrevSibling().getText().equals(",")) {
element.getPrevSibling().delete();
}
}
if (next.getText().equals(",")) {
if (next.getNextSibling() instanceof PsiWhiteSpace) {
next.getNextSibling().delete();
}
next.delete();
}
element.delete();
}

public static void deleteFunctionParam(PsiElement element) {
PsiElement next = element.getNextSibling();
if (next != null && next.getText().equals(",")) {
next.delete();
} else {
PsiElement prev = element.getPrevSibling();
if (prev != null && prev instanceof PsiWhiteSpace) {
prev.delete();
prev = element.getPrevSibling();
}
if (prev != null && prev.getText().equals(",")) {
prev.delete();
}
}
element.delete();
}
}
4 changes: 2 additions & 2 deletions src/com/yii2support/i18n/CategoryLookupElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/**
* Created by NVlad on 06.01.2017.
*/
public class CategoryLookupElement extends LookupElement {
private PsiElement myCategory;
class CategoryLookupElement extends LookupElement {
final private PsiElement myCategory;

CategoryLookupElement(PsiElement category) {
myCategory = category;
Expand Down
19 changes: 14 additions & 5 deletions src/com/yii2support/i18n/CompletionContributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.php.lang.psi.elements.ClassReference;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.elements.ParameterList;
import com.yii2support.common.Patterns;
Expand All @@ -20,12 +22,19 @@ public CompletionContributor() {

@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
if (typeChar == '\'' || typeChar == '"') {
if (position instanceof LeafPsiElement && (position.getText().equals("$category") || position.getText().equals("$message"))) {
return true;
MethodReference reference = PsiTreeUtil.getParentOfType(position, MethodReference.class);
if (reference != null && reference.getName() != null && reference.getName().equals("t")) {
ClassReference classReference = (ClassReference) reference.getClassReference();
if (classReference == null || classReference.getName() == null || !classReference.getName().equals("Yii")) {
return false;
}
if (position.getNextSibling() instanceof ParameterList || position.getParent() instanceof MethodReference) {
return true;
if (typeChar == '\'' || typeChar == '"') {
if (position instanceof LeafPsiElement && (position.getText().equals("$category") || position.getText().equals("$message"))) {
return true;
}
if (position.getNextSibling() instanceof ParameterList) {
return true;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/yii2support/i18n/CompletionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Created by NVlad on 06.01.2017.
*/
public class CompletionProvider extends com.intellij.codeInsight.completion.CompletionProvider<CompletionParameters> {
class CompletionProvider extends com.intellij.codeInsight.completion.CompletionProvider<CompletionParameters> {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PhpPsiElement psiElement = (PhpPsiElement) parameters.getPosition().getParent();
Expand Down
6 changes: 3 additions & 3 deletions src/com/yii2support/i18n/MessageLookupElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
/**
* Created by NVlad on 06.01.2017.
*/
public class MessageLookupElement extends LookupElement {
private PhpPsiElement myElement;
private ArrayHashElement myMessage;
class MessageLookupElement extends LookupElement {
final private PhpPsiElement myElement;
final private ArrayHashElement myMessage;

MessageLookupElement(PhpPsiElement element, ArrayHashElement message) {
myElement = element;
Expand Down
97 changes: 0 additions & 97 deletions src/com/yii2support/views/CompletionProvider.java

This file was deleted.

Loading

0 comments on commit 9d0f80f

Please sign in to comment.