Skip to content

Commit bab2042

Browse files
Merge pull request #47 from protostuff/feature/find-usages-for-options
#44: Search for usages for custom options
2 parents 2d3d6dd + a7eda4e commit bab2042

File tree

19 files changed

+257
-64
lines changed

19 files changed

+257
-64
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,35 @@
44

55
[Protobuf Support Plugin](https://plugins.jetbrains.com/plugin/8277) for IntelliJ IDEA & other JetBrains products.
66

7-
Plugin is compatible with IntelliJ IDEA 2016.1. Other JetBrains IDEs of the same or higher version should be supported as well.
7+
Latest plugin release is compatible with IntelliJ IDEA 2017.1 (older releases are compatible with IDEA 13+).
8+
Other JetBrains IDEs of the same or higher version should be supported as well.
9+
10+
### Installation
11+
12+
IntelliJ IDEA should suggest you to install plugin automatically
13+
when you open `.proto` file.
14+
You can install plugin manually by opening "Plugins" settings,
15+
"Browse repositories..." - search for "Protobuf Support".
16+
17+
Plugin page: https://plugins.jetbrains.com/plugin/8277-protobuf-support
18+
819

920
### Roadmap
1021

1122
https://github.com/protostuff/protobuf-jetbrains-plugin/wiki/Roadmap
1223

1324
### Build
1425

26+
Run following command in the shell:
27+
1528
```
1629
./gradlew build
1730
```
1831

19-
Requirements:
32+
It should be possible to run build on any platform (Linux, Windows, MacOS) where
33+
[Gradle](https://gradle.org/) is supported.
2034

21-
1. JDK 8
35+
JDK 8 must be installed and available on PATH in order to run build.
2236

2337
### Run IntelliJ IDEA with enabled plugin (for development)
2438

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://www.jetbrains.com/intellij-repository/releases
33
# https://www.jetbrains.com/intellij-repository/snapshots
44
version=0.8.0
5-
ideaVersion=2016.1
5+
ideaVersion=2017.1
66
# https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under
77
# Java 8 is required to run IntelliJ IDEA starting from version 16
88
javaVersion=1.8

src/main/java/io/protostuff/jetbrains/plugin/ProtoFindUsagesProvider.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.intellij.lang.findUsages.FindUsagesProvider;
66
import com.intellij.psi.PsiElement;
77
import io.protostuff.jetbrains.plugin.psi.DataType;
8+
import io.protostuff.jetbrains.plugin.psi.DataTypeContainer;
89
import io.protostuff.jetbrains.plugin.psi.EnumNode;
10+
import io.protostuff.jetbrains.plugin.psi.MessageField;
911
import io.protostuff.jetbrains.plugin.psi.MessageNode;
1012
import org.jetbrains.annotations.NotNull;
1113
import org.jetbrains.annotations.Nullable;
@@ -29,7 +31,8 @@ public WordsScanner getWordsScanner() {
2931

3032
@Override
3133
public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
32-
return psiElement instanceof DataType;
34+
return psiElement instanceof DataType
35+
|| psiElement instanceof MessageField;
3336
}
3437

3538
@Nullable
@@ -47,6 +50,9 @@ public String getType(@NotNull PsiElement element) {
4750
if (element instanceof EnumNode) {
4851
return "enum";
4952
}
53+
if (element instanceof MessageField) {
54+
return "field";
55+
}
5056
return "";
5157
}
5258

@@ -57,6 +63,10 @@ public String getDescriptiveName(@NotNull PsiElement element) {
5763
DataType type = (DataType) element;
5864
return type.getFullName();
5965
}
66+
if (element instanceof MessageField) {
67+
MessageField field = (MessageField) element;
68+
return field.getFieldName();
69+
}
6070
return "";
6171
}
6272

@@ -71,6 +81,28 @@ public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
7181
//noinspection ConstantConditions
7282
return type.getName();
7383
}
84+
if (element instanceof MessageField) {
85+
MessageField field = (MessageField) element;
86+
if (useFullName) {
87+
String namespace = getNamespace(field);
88+
return namespace + field.getFieldName();
89+
}
90+
return field.getFieldName();
91+
}
92+
return "";
93+
}
94+
95+
private String getNamespace(MessageField field) {
96+
PsiElement tmp = field;
97+
while (tmp != null) {
98+
tmp = tmp.getParent();
99+
if (tmp instanceof DataTypeContainer) {
100+
DataTypeContainer container = (DataTypeContainer) tmp;
101+
return container.getNamespace();
102+
}
103+
}
74104
return "";
75105
}
106+
107+
76108
}

src/main/java/io/protostuff/jetbrains/plugin/psi/DataTypeContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package io.protostuff.jetbrains.plugin.psi;
22

3+
import com.intellij.psi.PsiElement;
34
import java.util.Collection;
45

56
/**
67
* Container node that can hold user types - can be a message or proto file.
78
*
89
* @author Kostiantyn Shchepanovskyi
910
*/
10-
public interface DataTypeContainer {
11+
public interface DataTypeContainer extends PsiElement {
1112

1213
/**
1314
* Returns string prefix that is common for all children full names.

src/main/java/io/protostuff/jetbrains/plugin/psi/EnumConstantNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import static io.protostuff.jetbrains.plugin.psi.Util.decodeIntegerFromText;
77

88
import com.intellij.lang.ASTNode;
9+
import com.intellij.navigation.ItemPresentation;
10+
import com.intellij.navigation.ItemPresentationProviders;
911
import com.intellij.psi.PsiElement;
1012
import com.intellij.psi.PsiNamedElement;
1113
import io.protostuff.compiler.parser.ProtoParser;
@@ -59,4 +61,9 @@ public ASTNode getConstantValueNode() {
5961
return node.findChildByType(rule(RULE_enumFieldValue));
6062
}
6163

64+
@Override
65+
public ItemPresentation getPresentation() {
66+
return ItemPresentationProviders.getItemPresentation(this);
67+
}
68+
6269
}

src/main/java/io/protostuff/jetbrains/plugin/psi/FieldNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import static io.protostuff.jetbrains.plugin.psi.Util.decodeIntegerFromText;
77

88
import com.intellij.lang.ASTNode;
9+
import com.intellij.navigation.ItemPresentation;
10+
import com.intellij.navigation.ItemPresentationProviders;
911
import com.intellij.openapi.diagnostic.Logger;
1012
import com.intellij.psi.PsiElement;
1113
import io.protostuff.compiler.parser.ProtoParser;
@@ -86,6 +88,11 @@ public ASTNode getFieldLabelNode() {
8688
return node.findChildByType(R_FIELD_MODIFIER);
8789
}
8890

91+
@Override
92+
public ItemPresentation getPresentation() {
93+
return ItemPresentationProviders.getItemPresentation(this);
94+
}
95+
8996
@Override
9097
public String toString() {
9198
return "FieldNode(" + getFieldName() + "=" + getTag() + ")";

src/main/java/io/protostuff/jetbrains/plugin/psi/MapNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import static io.protostuff.jetbrains.plugin.psi.Util.decodeIntegerFromText;
66

77
import com.intellij.lang.ASTNode;
8+
import com.intellij.navigation.ItemPresentation;
9+
import com.intellij.navigation.ItemPresentationProviders;
810
import java.util.Optional;
911
import org.antlr.jetbrains.adapter.psi.AntlrPsiNode;
1012
import org.jetbrains.annotations.NotNull;
@@ -65,4 +67,9 @@ public ASTNode getFieldLabelNode() {
6567
return null;
6668
}
6769

70+
@Override
71+
public ItemPresentation getPresentation() {
72+
return ItemPresentationProviders.getItemPresentation(this);
73+
}
74+
6875
}

src/main/java/io/protostuff/jetbrains/plugin/psi/MessageField.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package io.protostuff.jetbrains.plugin.psi;
22

33
import com.intellij.lang.ASTNode;
4-
import com.intellij.psi.PsiElement;
4+
import com.intellij.psi.NavigatablePsiElement;
55
import java.util.Optional;
66

77
/**
88
* Message field node.
99
*
1010
* @author Kostiantyn Shchepanovskyi
1111
*/
12-
public interface MessageField extends PsiElement {
12+
public interface MessageField extends NavigatablePsiElement {
1313

1414
String getFieldName();
1515

src/main/java/io/protostuff/jetbrains/plugin/psi/OneofFieldNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import static io.protostuff.jetbrains.plugin.psi.Util.decodeIntegerFromText;
77

88
import com.intellij.lang.ASTNode;
9+
import com.intellij.navigation.ItemPresentation;
10+
import com.intellij.navigation.ItemPresentationProviders;
911
import com.intellij.openapi.diagnostic.Logger;
1012
import com.intellij.psi.PsiElement;
1113
import io.protostuff.compiler.parser.ProtoParser;
@@ -82,4 +84,9 @@ public TypeReferenceNode getFieldType() {
8284
return findChildByClass(TypeReferenceNode.class);
8385
}
8486

87+
@Override
88+
public ItemPresentation getPresentation() {
89+
return ItemPresentationProviders.getItemPresentation(this);
90+
}
91+
8592
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.protostuff.jetbrains.plugin.psi.presentation;
2+
3+
import io.protostuff.jetbrains.plugin.Icons;
4+
import io.protostuff.jetbrains.plugin.psi.EnumConstantNode;
5+
import javax.swing.Icon;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
/**
9+
* Message node presentation provider.
10+
*
11+
* @author Kostiantyn Shchepanovskyi
12+
*/
13+
public class EnumValuePresentationProvider extends AbstractPresentationProvider<EnumConstantNode> {
14+
15+
@Override
16+
protected Icon getIcon() {
17+
return Icons.CONSTANT;
18+
}
19+
20+
@Override
21+
protected String getName(@NotNull EnumConstantNode item) {
22+
return PresentationUtil.getNameForElement(item);
23+
}
24+
}

0 commit comments

Comments
 (0)