Skip to content

Commit

Permalink
Implemented proper completion for slots names
Browse files Browse the repository at this point in the history
Fixes #1636
  • Loading branch information
hurricup committed Nov 28, 2017
1 parent 1b3867b commit 3d54e08
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<li>Intention to convert statement with modifier to compound statement and vice versa, by <a href="https://github.com/Camelcade/Perl5-IDEA/issues/1604">cjelli</a>
<li>Re-worked live templates: abbreviations, defaults and so on (need a feedback)</li>
<li>Already typed import parameters are now excluded from completion</li>
<li>Completion in braces after typeglobs now contains slots names</li>
</ul>
</p>
<p>Fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ProcessingContext;
import com.perl5.lang.perl.idea.PerlElementPatterns;
import com.perl5.lang.perl.idea.completion.util.PerlPackageCompletionUtil;
import com.perl5.lang.perl.idea.completion.util.PerlStringCompletionUtil;
import com.perl5.lang.perl.psi.PsiPerlAnnotationInject;
import com.perl5.lang.perl.psi.PsiPerlGlobSlot;
import com.perl5.lang.perl.psi.PsiPerlHashIndex;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -50,7 +53,13 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
}
else if (SIMPLE_HASH_INDEX.accepts(element)) // hash indexes
{
PerlStringCompletionUtil.fillWithHashIndexes(element, result);
PsiPerlHashIndex indexElement = PsiTreeUtil.getParentOfType(element, PsiPerlHashIndex.class);
if (indexElement != null && indexElement.getParent() instanceof PsiPerlGlobSlot) {
PerlStringCompletionUtil.fillWithRefTypes(result);
}
else {
PerlStringCompletionUtil.fillWithHashIndexes(element, result);
}
}
else if (USE_PARAMETERS_PATTERN.accepts(element)) // use or no parameters
{
Expand Down
2 changes: 2 additions & 0 deletions test/completion/PerlCompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,6 @@ public void testTryCatch() {
public void testPackageVarTypeAnnotation() {doTestCompletion();}

public void testLazyExportOkQw() {doTestCompletion();}

public void testGlobSlots() {doTestCompletion();}
}
1 change: 1 addition & 0 deletions testData/completion/perl/globSlots.code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*a{<caret>}
11 changes: 11 additions & 0 deletions testData/completion/perl/globSlots.pl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Lookups: ARRAY; Text: ARRAY; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: CODE; Text: CODE; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: FORMAT; Text: FORMAT; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: GLOB; Text: GLOB; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: HASH; Text: HASH; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: IO; Text: IO; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: LVALUE; Text: LVALUE; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: REF; Text: REF; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: Regexp; Text: Regexp; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: SCALAR; Text: SCALAR; Tail: null; Type: null; Icon: null; Type Icon: null
Lookups: VSTRING; Text: VSTRING; Tail: null; Type: null; Icon: null; Type Icon: null

0 comments on commit 3d54e08

Please sign in to comment.