Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit
targets.addAll(constantGoto(psiElement, psiText));
}

// mind the whitespace
if(hasNewConst(psiElement)) {
targets.addAll(newConstantGoto(psiElement, psiText));
}

if(psiText.contains("\\")) {
targets.addAll(classGoToDeclaration(psiElement, psiText)) ;
}
Expand Down Expand Up @@ -162,6 +167,22 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit
return targets.toArray(new PsiElement[targets.size()]);
}

private boolean hasNewConst(@NotNull PsiElement psiElement) {
PsiElement prevSibling = psiElement.getPrevSibling();
while (prevSibling != null) {
IElementType elementType = prevSibling.getNode().getElementType();
if (elementType == YAMLTokenTypes.TEXT || elementType == YAMLTokenTypes.SCALAR_DSTRING || elementType == YAMLTokenTypes.SCALAR_STRING || elementType == YAMLTokenTypes.TAG) {
String psiText = PsiElementUtils.getText(prevSibling);

return psiText.equals("!php/const");
}

prevSibling = prevSibling.getPrevSibling();
}

return false;
}

@NotNull
private Collection<PsiElement> classGoToDeclaration(@NotNull PsiElement psiElement, @NotNull String className) {

Expand Down Expand Up @@ -234,6 +255,14 @@ private Collection<PsiElement> constantGoto(@NotNull PsiElement psiElement, @Not
return ServiceContainerUtil.getTargetsForConstant(psiElement.getProject(), constantName);
}

@NotNull
private Collection<PsiElement> newConstantGoto(@NotNull PsiElement psiElement, @NotNull String constantName) {
if(StringUtils.isBlank(constantName)) {
return Collections.emptyList();
}

return ServiceContainerUtil.getTargetsForConstant(psiElement.getProject(), constantName);
}

@NotNull
private Collection<PsiElement> visitConfigKey(@NotNull PsiElement psiElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.yaml.YAMLFileType;

import java.io.File;

/**
* @author Daniel Espendiller <daniel@espendiller.net>
*
Expand Down Expand Up @@ -94,6 +92,15 @@ public void testPhpConstantNavigation() {
assertNavigationMatch(YAMLFileType.YML, "bar: '!php/const:\\YAML_<caret>FOO_BAR'");
}

public void testPhpConstantNavigation34() {
assertNavigationMatch(YAMLFileType.YML, "bar: !php/const \\YAML_<caret>FOO_BAR");
assertNavigationMatch(YAMLFileType.YML, "bar: !php/const YAML_<caret>FOO_BAR");
assertNavigationMatch(YAMLFileType.YML, "bar: !php/const Yaml\\Foo\\Bar::YAML_FOO_BAR<caret>_CLASS");
assertNavigationMatch(YAMLFileType.YML, "bar: !php/const Yaml\\Foo\\Bar::::YAML_FOO_BAR<caret>_CLASS");
assertNavigationMatch(YAMLFileType.YML, "bar: !php/const Yaml\\Foo\\Bar:YAML_FOO_BAR<caret>_CLASS");
assertNavigationMatch(YAMLFileType.YML, "bar: !php/const \\Yaml\\Foo\\Bar:YAML_FOO_BAR<caret>_CLASS");
}

public void testParameter() {
assertNavigationMatch(YAMLFileType.YML, "bar: %foo_p<caret>arameter%");
}
Expand Down