Search in sources :

Example 51 with ITypeKeeper

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);
}
Also used : Position(nl.ramsolutions.sw.magik.analysis.Position) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) Location(nl.ramsolutions.sw.magik.analysis.Location) Test(org.junit.jupiter.api.Test)

Example 52 with ITypeKeeper

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();
}
Also used : Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Test(org.junit.jupiter.api.Test)

Example 53 with ITypeKeeper

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);
}
Also used : CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) Collection(java.util.Collection) MagikTypedFile(nl.ramsolutions.sw.magik.MagikTypedFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) Collectors(java.util.stream.Collectors) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) CompletionItem(org.eclipse.lsp4j.CompletionItem) Test(org.junit.jupiter.api.Test) List(java.util.List) MagikKeyword(nl.ramsolutions.sw.magik.api.MagikKeyword) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) CompletionProvider(nl.ramsolutions.sw.magik.languageserver.completion.CompletionProvider) Position(org.eclipse.lsp4j.Position) URI(java.net.URI) Collections(java.util.Collections) EnumSet(java.util.EnumSet) ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Test(org.junit.jupiter.api.Test)

Example 54 with ITypeKeeper

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);
}
Also used : CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) Collection(java.util.Collection) MagikTypedFile(nl.ramsolutions.sw.magik.MagikTypedFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) Collectors(java.util.stream.Collectors) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) CompletionItem(org.eclipse.lsp4j.CompletionItem) Test(org.junit.jupiter.api.Test) List(java.util.List) MagikKeyword(nl.ramsolutions.sw.magik.api.MagikKeyword) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) CompletionProvider(nl.ramsolutions.sw.magik.languageserver.completion.CompletionProvider) Position(org.eclipse.lsp4j.Position) URI(java.net.URI) Collections(java.util.Collections) EnumSet(java.util.EnumSet) ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) Position(org.eclipse.lsp4j.Position) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) CompletionItem(org.eclipse.lsp4j.CompletionItem) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) Test(org.junit.jupiter.api.Test)

Example 55 with ITypeKeeper

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);
}
Also used : CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) Collection(java.util.Collection) MagikTypedFile(nl.ramsolutions.sw.magik.MagikTypedFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) Collectors(java.util.stream.Collectors) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) CompletionItem(org.eclipse.lsp4j.CompletionItem) Test(org.junit.jupiter.api.Test) List(java.util.List) MagikKeyword(nl.ramsolutions.sw.magik.api.MagikKeyword) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) CompletionProvider(nl.ramsolutions.sw.magik.languageserver.completion.CompletionProvider) Position(org.eclipse.lsp4j.Position) URI(java.net.URI) Collections(java.util.Collections) EnumSet(java.util.EnumSet) ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) TypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Test(org.junit.jupiter.api.Test)

Aggregations

ITypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)55 TypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper)38 Test (org.junit.jupiter.api.Test)34 AbstractType (nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType)20 MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)20 MagikTypedCheck (nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck)18 Position (org.eclipse.lsp4j.Position)17 AstNode (com.sonar.sslr.api.AstNode)14 GlobalReference (nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference)14 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)13 MagikIssue (nl.ramsolutions.sw.magik.checks.MagikIssue)13 Method (nl.ramsolutions.sw.magik.analysis.typing.types.Method)12 ExpressionResult (nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult)9 CompletionItem (org.eclipse.lsp4j.CompletionItem)9 URI (java.net.URI)8 List (java.util.List)8 MethodDefinitionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper)8 LocalTypeReasoner (nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner)8 UndefinedType (nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType)8 MagikGrammar (nl.ramsolutions.sw.magik.api.MagikGrammar)8