Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementDescription for ElixirVariable #744

Merged
merged 2 commits into from Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/org/elixir_lang/psi/ElementDescriptionProvider.java
@@ -1,6 +1,5 @@
package org.elixir_lang.psi;

import com.ericsson.otp.erlang.OtpErlangObject;
import com.intellij.psi.ElementDescriptionLocation;
import com.intellij.psi.PsiElement;
import com.intellij.usageView.UsageViewLongNameLocation;
Expand Down Expand Up @@ -31,6 +30,7 @@
* {@link org.elixir_lang.FindUsagesProvider#getType(PsiElement)}) together together.
*/
public class ElementDescriptionProvider implements com.intellij.psi.ElementDescriptionProvider {
public static final String VARIABLE_USAGE_VIEW_TYPE_LOCATION_ELEMENT_DESCRIPTION = "variable";
/*
*
* Instance Methods
Expand All @@ -52,6 +52,8 @@ public String getElementDescription(@NotNull PsiElement element, @NotNull Elemen
elementDescription = getElementDescription((ElixirIdentifier) element, location);
} else if (element instanceof ElixirKeywordKey) {
elementDescription = getElementDescription((ElixirKeywordKey) element, location);
} else if (element instanceof ElixirVariable) {
elementDescription = getElementDescription((ElixirVariable) element, location);
} else if (element instanceof MaybeModuleName) {
elementDescription = getElementDescription((MaybeModuleName) element, location);
}
Expand Down Expand Up @@ -130,6 +132,20 @@ private String getElementDescription(@NotNull ElixirKeywordKey keywordKey,
return elementDescription;
}

@Nullable
private String getElementDescription(@NotNull ElixirVariable variable,
@NotNull ElementDescriptionLocation location) {
String elementDescription = null;

if (location == UsageViewLongNameLocation.INSTANCE || location == UsageViewShortNameLocation.INSTANCE) {
elementDescription = variable.getName();
} else if (location == UsageViewTypeLocation.INSTANCE) {
elementDescription = VARIABLE_USAGE_VIEW_TYPE_LOCATION_ELEMENT_DESCRIPTION;
}

return elementDescription;
}

@Nullable
private String getElementDescription(@NotNull MaybeModuleName maybeModuleName,
@NotNull ElementDescriptionLocation location) {
Expand Down
5 changes: 4 additions & 1 deletion src/org/elixir_lang/reference/Callable.java
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Set;

import static org.elixir_lang.psi.ElementDescriptionProvider.VARIABLE_USAGE_VIEW_TYPE_LOCATION_ELEMENT_DESCRIPTION;
import static org.elixir_lang.psi.impl.ElixirPsiImplUtil.*;

public class Callable extends PsiReferenceBase<Call> implements PsiPolyVariantReference {
Expand Down Expand Up @@ -353,7 +354,7 @@ public static String variableElementDescription(Call call, ElementDescriptionLoc
if (location == UsageViewLongNameLocation.INSTANCE || location == UsageViewShortNameLocation.INSTANCE) {
elementDescription = call.getName();
} else if (location == UsageViewTypeLocation.INSTANCE) {
elementDescription = "variable";
elementDescription = VARIABLE_USAGE_VIEW_TYPE_LOCATION_ELEMENT_DESCRIPTION;
}

return elementDescription;
Expand Down Expand Up @@ -434,6 +435,8 @@ private static boolean isVariable(@NotNull Call call) {
isVariable = true;
} else if (call.isCalling(Module.KERNEL, Function.VAR_BANG)) {
isVariable = true;
} else if (call instanceof UnqualifiedParenthesesCall) {
isVariable = false;
} else {
PsiElement parent = call.getParent();
isVariable = isVariable(parent);
Expand Down
2 changes: 1 addition & 1 deletion tests/org/elixir_lang/reference/callable/Issue436Test.java
Expand Up @@ -23,7 +23,7 @@ public void testIsParameter() {

assertInstanceOf(variable, UnqualifiedNoArgumentsCall.class);
assertFalse("alias is marked as a parameter", isParameter(variable));
assertTrue("alias is not marked as a variable", isVariable(variable));
assertFalse("alias is marked as a variable", isVariable(variable));
}

/*
Expand Down