use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class ReferencesProviderTest method testProvideMethodReferenceFromMethodInvocation.
@Test
void testProvideMethodReferenceFromMethodInvocation() {
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
final Method referingMethod = integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), EMPTY_LOCATION, "refering", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
referingMethod.addCalledMethod("refering");
final String code = "" + "_method integer.refering\n" + " _self.refering\n" + "_endmethod\n";
// On `refering`.
final org.eclipse.lsp4j.Position position = new org.eclipse.lsp4j.Position(1, 12);
final List<org.eclipse.lsp4j.Location> references = this.getReferences(code, position, typeKeeper);
assertThat(references).hasSize(1);
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class CompletionProviderTest method testNoCompletionInComment.
@Test
void testNoCompletionInComment() {
final String code = "" + "abc # ";
final ITypeKeeper typeKeeper = new TypeKeeper();
// On ' ', in comment.
final Position position = new Position(0, 5);
final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
assertThat(completions).isEmpty();
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class CompletionProviderTest method testGlobalCompletionVariable.
@Test
void testGlobalCompletionVariable() {
final String code = "" + "_method a.b\n" + " _local x << 10\n" + " \n" + "_endmethod";
final ITypeKeeper typeKeeper = new TypeKeeper();
// On ''.
final Position position = new Position(2, 2);
final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
final Collection<AbstractType> defaultTypes = typeKeeper.getTypes();
assertThat(completions).hasSize(defaultTypes.size() + MagikKeyword.values().length + // local variable.
1);
final Set<CompletionItemKind> itemKinds = completions.stream().map(item -> item.getKind()).collect(Collectors.toSet());
assertThat(itemKinds).containsExactlyInAnyOrder(CompletionItemKind.Class, CompletionItemKind.Keyword, CompletionItemKind.Variable);
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class CompletionProviderTest method testGlobalCompletionSlot.
@Test
void testGlobalCompletionSlot() {
final String code = "" + "_method a.b\n" + " \n" + "_endmethod";
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType aType = new SlottedType(GlobalReference.of("user", "a"));
aType.addSlot(null, "slot1");
typeKeeper.addType(aType);
// On ''.
final Position position = new Position(1, 2);
final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
final Collection<AbstractType> defaultTypes = typeKeeper.getTypes();
assertThat(completions).hasSize(defaultTypes.size() + MagikKeyword.values().length + // slot.
1);
final Set<CompletionItemKind> itemKinds = completions.stream().map(item -> item.getKind()).collect(Collectors.toSet());
assertThat(itemKinds).containsExactlyInAnyOrder(CompletionItemKind.Class, CompletionItemKind.Keyword, CompletionItemKind.Property);
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class CompletionProviderTest method testGlobalCompletion.
@Test
void testGlobalCompletion() {
final String code = "" + "_method a.b\n" + " \n" + "_endmethod";
final ITypeKeeper typeKeeper = new TypeKeeper();
// On ''.
final Position position = new Position(1, 2);
final List<CompletionItem> completions = this.getCompletions(code, typeKeeper, position);
final Collection<AbstractType> defaultTypes = typeKeeper.getTypes();
assertThat(completions).hasSize(defaultTypes.size() + MagikKeyword.values().length);
final Set<CompletionItemKind> itemKinds = completions.stream().map(item -> item.getKind()).collect(Collectors.toSet());
assertThat(itemKinds).containsExactlyInAnyOrder(CompletionItemKind.Class, CompletionItemKind.Keyword);
}
Aggregations