Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postfix completion for SCAN and MASK #521

Merged
merged 1 commit into from
Oct 23, 2024
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 @@ -178,6 +178,7 @@ private static void addPostfixCompletionItems(
addValPostfix(completionItems, typedVar, identifierName, rangeToInsert, deleteEdit);
addIncrementDecrementPostfix(completionItems, typedVar, identifierName, rangeToInsert, deleteEdit);
addTrimPostfixes(completionItems, typedVar, identifierName, rangeToInsert, deleteEdit);
addScanAndMask(completionItems, typedVar, identifierName, rangeToInsert, deleteEdit);
}

if (variableInvokedOn.scope().isParameter() && variableInvokedOn.findDescendantToken(SyntaxKind.OPTIONAL) != null)
Expand All @@ -186,6 +187,35 @@ private static void addPostfixCompletionItems(
}
}

private static void addScanAndMask(
ArrayList<CompletionItem> completionItems, ITypedVariableNode typedVar,
String identifierName, Range rangeToInsert, TextEdit deleteEdit
)
{
if (!typedVar.type().isAlphaNumericFamily() || typedVar.isArray())
{
return;
}

var scanEdit = new TextEdit(rangeToInsert, "%s = SCAN ${1:'VALUE'}${0}".formatted(identifierName));
completionItems.add(
createSnippetPostfixCompletionItem(
"contains",
scanEdit,
deleteEdit
)
);

var maskEdit = new TextEdit(rangeToInsert, "%s = MASK (${1:*})${0}".formatted(identifierName));
completionItems.add(
createSnippetPostfixCompletionItem(
"matches",
maskEdit,
deleteEdit
)
);
}

private static void addIncrementDecrementPostfix(
ArrayList<CompletionItem> completionItems,
ITypedVariableNode typedVar, String identifierName, Range rangeToInsert, TextEdit deleteEdit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,86 @@ void createAValCall()
}
}

@Nested
class MaskAndScanSnippetsShould
{
@ParameterizedTest
@ValueSource(
strings =
{
"N2", "P4", "I4", "L", "C"
}
)
void notBeApplicableOnVariablesThatAreNotAlphanumericFamily(String type)
{
assertCompletions("LIBONE", "SUB.NSN", ".", """
DEFINE DATA
LOCAL 1 #VAR (%s)
END-DEFINE
#VAR.${}$
END
""".formatted(type))
.assertDoesNotContain("contains")
.assertDoesNotContain("matches");
}

@ParameterizedTest
@ValueSource(strings =
{
"A10", "U10", "B4"
})
void beApplicableOnVariablesThatAreAlphanumericFamily(String type)
{
assertCompletions("LIBONE", "SUB.NSN", ".", """
DEFINE DATA
LOCAL 1 #VAR (%s)
END-DEFINE
#VAR.${}$
END
""".formatted(type))
.assertContains("contains", CompletionItemKind.Snippet)
.assertContains("matches", CompletionItemKind.Snippet);
}

@Test
void createAScanExpression()
{
assertCompletions("LIBONE", "SUB.NSN", ".", """
DEFINE DATA
LOCAL 1 #VAR (A10)
END-DEFINE
#VAR.${}$
END
""")
.assertContainsCompletionResultingIn("contains", """
DEFINE DATA
LOCAL 1 #VAR (A10)
END-DEFINE
#VAR = SCAN ${1:'VALUE'}${0}
END
""");
}

@Test
void createAMaskExpression()
{
assertCompletions("LIBONE", "SUB.NSN", ".", """
DEFINE DATA
LOCAL 1 #VAR (A10)
END-DEFINE
#VAR.${}$
END
""")
.assertContainsCompletionResultingIn("matches", """
DEFINE DATA
LOCAL 1 #VAR (A10)
END-DEFINE
#VAR = MASK (${1:*})${0}
END
""");
}
}

@Nested
class TrimSnippetsShould
{
Expand Down