Skip to content

Commit

Permalink
Merge pull request #217 from xonixx/Improve-auto-complete-for-this-ca…
Browse files Browse the repository at this point in the history
…se-#186

Improve auto complete for this case #186
  • Loading branch information
xonixx committed Apr 29, 2024
2 parents 5bf3104 + 576f0fd commit 23d39c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/main/java/intellij_awk/Awk.bnf
Expand Up @@ -502,15 +502,11 @@ lvalue ::= gawk_var_name | DOLLAR expr

// XXX this covers a[1][2][3] like in Gawk
// XXX awk only supports a[1]
private gawk_var_name ::= var_name (LBRACKET expr_lst RBRACKET)*

// XXX for some reason the below makes it terribly slow or hanging on profile5.awk
/*private gawk_var_name ::= var_name (subscript_start RBRACKET)*
private subscript_start ::= LBRACKET expr_lst {
private gawk_var_name ::= var_name (subscript_start RBRACKET)*
private subscript_start ::= LBRACKET expr_lst
{
pin=1
recoverWhile=recover_on_rbracket
}
private recover_on_rbracket ::= !RBRACKET*/

private var_name ::= builtin_var_name | user_var_name

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/intellij_awk/AwkParserDefinition.java
Expand Up @@ -26,7 +26,7 @@ public class AwkParserDefinition implements ParserDefinition {
new IStubFileElementType<>(AwkLanguage.INSTANCE) {
@Override
public int getStubVersion() {
return 16;
return 17;
}

@Override
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/intellij_awk/AwkCompletionTests.java
Expand Up @@ -430,21 +430,32 @@ public void testLocalVariableInAction3() {
}

public void testGlobalVariableInAction1() {
checkCompletionAuto("{ Xxx=1 } function f(){ Xx<caret> }", "{ Xxx=1 } function f(){ Xxx<caret> }");
checkCompletionAuto(
"{ Xxx=1 } function f(){ Xx<caret> }", "{ Xxx=1 } function f(){ Xxx<caret> }");
}

public void testGlobalVariableInAction2() {
checkCompletionAuto("{ Xxx=1 }\nXx<caret>", "{ Xxx=1 }\nXxx<caret>");
}

public void testGlobalVariableInAction3() {
checkCompletionAuto("/a/{ xxx=1 } /b/{ xx<caret> }", "/a/{ xxx=1 } /b/{ xxx<caret> }");
}

public void testGlobalVariableInAction4() {
checkCompletionAuto("function f(){ Xxx=1 } { Xx<caret> }", "function f(){ Xxx=1 } { Xxx<caret> }");
checkCompletionAuto(
"function f(){ Xxx=1 } { Xx<caret> }", "function f(){ Xxx=1 } { Xxx<caret> }");
}

public void testGlobalVariableInAction5_NotLocal() {
checkCompletionEmpty("function f(Xxx){ Xxx=1 } { Xx<caret> }");
}

public void testMustCompleteInsideEmptySubscript() {
checkCompletion(
Set.of("q1q2q3"), Set.of(), "BEGIN {\n a[<caret>]\n}\n\nfunction q1q2q3() {\n}");
}

private void checkFunctionArgs(String code, String fName, String expectedArgs) {
setupCode(code);
LookupElement[] variants = myFixture.completeBasic();
Expand Down

0 comments on commit 23d39c1

Please sign in to comment.