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 6e02aa1

Browse files
committed
Fixed #1631: PhpConstGotoCompletionProvider throws IndexOutOfBoundsException when cursor is before scope operator
1 parent eab20ad commit 6e02aa1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-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));

0 commit comments

Comments
(0)

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