Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d6fd5d

Browse files
Merge pull request #1645 from adamwojs/issue_1631
Fixed #1631: PhpConstGotoCompletionProvider throws IndexOutOfBoundsException when cursor is before scope operator
2 parents de0d5cb + 52ee25f commit 5d6fd5d

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

‎src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ public void getLookupElements(@NotNull GotoCompletionProviderLookupArguments arg
4242
PhpIndex phpIndex = PhpIndex.getInstance(this.getProject());
4343
CompletionResultSet resultSet = arguments.getResultSet();
4444

45-
final String prefix = getElement().getText().replace(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED, "");
45+
var elementText = getElement().getText();
46+
var scopeOperatorPos = elementText.indexOf(SCOPE_OPERATOR);
47+
var cursorPos = elementText.indexOf(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED);
4648

4749
// Class constants: !php/const Foo::<caret>
48-
if (prefix.contains(SCOPE_OPERATOR)) {
49-
String classFQN = prefix.substring(0, getElement().getText().indexOf(SCOPE_OPERATOR));
50-
PhpClass phpClass = PhpElementsUtil.getClassInterface(this.getProject(), classFQN);
50+
if (scopeOperatorPos > -1 && scopeOperatorPos < cursorPos) {
51+
var prefix = elementText.replace(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED, "");
52+
var classFQN = prefix.substring(0, scopeOperatorPos);
53+
var phpClass = PhpElementsUtil.getClassInterface(this.getProject(), classFQN);
54+
5155
if (phpClass != null) {
5256
// reset the prefix matcher, starting after ::
5357
resultSet = resultSet.withPrefixMatcher(prefix.substring(prefix.indexOf(SCOPE_OPERATOR) + 2));

‎src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/completion/yaml/YamlGotoCompletionRegistrarTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,35 @@ public void testThatDecoratesPrioritizeLookupElementOnInstance() {
101101
lookupElement -> "foo".equals(lookupElement.getItemText()) && lookupElement.isItemTextBold() && lookupElement.isItemTextBold()
102102
);
103103
}
104+
105+
public void testThatPhpConstAreCompletedAndNavigable() {
106+
assertCompletionContains(
107+
YAMLFileType.YML,
108+
"services:\n" +
109+
" foo:\n" +
110+
" class: Foo\\Foobar\n" +
111+
" arguments: \n" +
112+
" - !php/const <caret>\n",
113+
"Bar", "Foobar"
114+
);
115+
116+
assertCompletionContains(
117+
YAMLFileType.YML,
118+
"services:\n" +
119+
" foo:\n" +
120+
" class: Foo\\Foobar\n" +
121+
" arguments: \n" +
122+
" - !php/const Foo\\Bar::<caret>\n",
123+
"BAZ"
124+
);
125+
126+
assertCompletionIsEmpty(
127+
YAMLFileType.YML,
128+
"services:\n" +
129+
" foo:\n" +
130+
" class: Foo\\Foobar\n" +
131+
" arguments: \n" +
132+
" - !php/const Foo\\Bar<caret>::BAZ\n"
133+
);
134+
}
104135
}

‎src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/completion/yaml/fixtures/YamlGotoCompletionRegistrar.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
{
55
class Bar
66
{
7+
public const BAZ = 'baz';
8+
79
public function create() {}
810
}
911

1012
class Foobar extends Bar
1113
{
14+
public function __construct($arg = null) {}
1215
}
1316
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /