Skip to content

Commit

Permalink
Add tests for completion. (finos#130)
Browse files Browse the repository at this point in the history
* Basic code completion.

* Handle 'null' description in LegendCompletion.

* Limiting the function suggestions to just the core service-specific ones.

* Dummy commit for resolving conflicts.

* Changing ownership grammar in service boilerplate.

* Resolve conflicts.

* Address Kevin's PR comments: replace line separators, add @OVERRIDES markers, change type for getCompletions method from Iterable to List.

* Add tests for completion.

* Add grammar-specific tests for completion.

* Resolve conflicts

* Resolve conflicts.

* Remove unnecessary dependency, fix tests.
  • Loading branch information
renuccif authored Jan 18, 2024
1 parent b7a2ada commit 5eb2ab1
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.set.MutableSet;
import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.declaration.LegendDeclaration;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Kind;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Source;
import org.finos.legend.engine.ide.lsp.extension.text.TextInterval;
import org.finos.legend.engine.ide.lsp.extension.text.TextPosition;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -42,6 +44,26 @@ public void testGetKeywords()
Assertions.assertEquals(Sets.mutable.empty(), missingKeywords);
}

@Test
public void testCompletion()
{
String code = "\n" +
"###Mapping\n" +
"\n" +
"Mapping test::mapping::TestMapping\n" +
"(\n" +
"~mainTable [package::path::storeName]schemaName.TableName1\n" +
" )\n";
String boilerPlate = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 0)).iterator().next().getDescription();
Assertions.assertEquals("Mapping boilerplate", boilerPlate);

Iterable<? extends LegendCompletion> noCompletion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 1));
Assertions.assertFalse(noCompletion.iterator().hasNext());

String storeObjectSuggestion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(5, 1)).iterator().next().getDescription();
Assertions.assertEquals("Store object type", storeObjectSuggestion);
}

@Test
public void testGetDeclarations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.MutableMap;
import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.declaration.LegendDeclaration;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Kind;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Source;
import org.finos.legend.engine.ide.lsp.extension.text.TextInterval;
import org.finos.legend.engine.ide.lsp.extension.text.TextPosition;
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestPureLSPGrammarExtension extends AbstractLSPGrammarExtensionTest<PureLSPGrammarExtension>
Expand Down Expand Up @@ -211,6 +214,29 @@ public void testDiagnostics_multipleFiles_compilerError()
testDiagnostics(codeFiles, "vscodelsp::test::Employee1", LegendDiagnostic.newDiagnostic(TextInterval.newInterval(1, 0, 6, 0), "Can't find type 'vscodelsp::test::Employee2'", Kind.Error, Source.Compiler));
}

@Test
public void testCompletion()
{
String code = "###Pure\n" +
"Class vscodelsp::test::Employee\n" +
"{\n" +
"foobar1: Float [1];\n" +
"foobar2: Float [1];\n" +
"}";

String boilerPlate = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 0)).iterator().next().getDescription();
Assertions.assertEquals("Pure boilerplate", boilerPlate);

Iterable<? extends LegendCompletion> noCompletion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 1));
Assertions.assertFalse(noCompletion.iterator().hasNext());

String attributeTypesSuggestion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(3, 9)).iterator().next().getDescription();
Assertions.assertEquals("Attribute type", attributeTypesSuggestion);

String attributeMultiplicitiesSuggestion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(3, 15)).iterator().next().getDescription();
Assertions.assertEquals("Attribute multiplicity", attributeMultiplicitiesSuggestion);
}

@Override
protected PureLSPGrammarExtension newExtension()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@

package org.finos.legend.engine.ide.lsp.extension;

import java.util.Set;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.utility.Iterate;
import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.declaration.LegendDeclaration;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Kind;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Source;
import org.finos.legend.engine.ide.lsp.extension.execution.LegendExecutionResult;
import org.finos.legend.engine.ide.lsp.extension.text.TextInterval;
import org.finos.legend.engine.ide.lsp.extension.text.TextPosition;
import org.finos.legend.pure.m2.relational.M2RelationalPaths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.finos.legend.engine.ide.lsp.extension.RelationalLSPGrammarExtension.GENERATE_MODEL_MAPPING_COMMAND_ID;

public class TestRelationalLSPGrammarExtension extends AbstractLSPGrammarExtensionTest<RelationalLSPGrammarExtension>
Expand Down Expand Up @@ -273,6 +276,43 @@ void testGenerateSampleModelsCommand()
")\n", result.getMessage());
}

@Test
public void testCompletion()
{
String code = "###Relational" +
"Database package::path::storeName\n" +
"(\n" +
"Schema schemaName\n" +
"(\n" +
"Table TableName(column1 INT PRIMARY KEY, column2 DATE)\n" +
"View ViewName(column3 VARCHAR(10) PRIMARY KEY)\n" +
")\n" +
"Join \n" +
"Filter \n" +
")\n";

String boilerPlate = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 0)).iterator().next().getDescription();
Assertions.assertEquals("Relational boilerplate", boilerPlate);

Iterable<? extends LegendCompletion> noCompletion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 1));
Assertions.assertFalse(noCompletion.iterator().hasNext());

String schemaSuggestions = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 7)).iterator().next().getDescription();
Assertions.assertEquals("Schema definition", schemaSuggestions);

String tableSuggestions = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(4, 6)).iterator().next().getDescription();
Assertions.assertEquals("Table definition", tableSuggestions);

String viewSuggestions = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(5, 5)).iterator().next().getDescription();
Assertions.assertEquals("View definition", viewSuggestions);

String joinSuggestions = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(7, 5)).iterator().next().getDescription();
Assertions.assertEquals("Join definition", joinSuggestions);

String filterSuggestions = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(8, 7)).iterator().next().getDescription();
Assertions.assertEquals("Filter definition", filterSuggestions);
}

@Test
void testAntlrExpectedTokens()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

package org.finos.legend.engine.ide.lsp.extension;

import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.declaration.LegendDeclaration;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
import org.finos.legend.engine.ide.lsp.extension.text.TextInterval;
import org.finos.legend.engine.ide.lsp.extension.text.TextPosition;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestRuntimeLSPGrammarExtension extends AbstractLSPGrammarExtensionTest<RuntimeLSPGrammarExtension>
Expand Down Expand Up @@ -72,6 +75,20 @@ public void testDiagnostics_compilerWarning()
);
}

@Test
public void testCompletion()
{
String code = "\n" +
"###Runtime\n" +
"\n";

Iterable<? extends LegendCompletion> noCompletion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(1, 1));
Assertions.assertFalse(noCompletion.iterator().hasNext());

String boilerPlate = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(2, 0)).iterator().next().getDescription();
Assertions.assertEquals("Runtime boilerplate", boilerPlate);
}

@Override
protected RuntimeLSPGrammarExtension newExtension()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
package org.finos.legend.engine.ide.lsp.extension;

import java.util.Set;

import org.finos.legend.engine.ide.lsp.extension.completion.LegendCompletion;
import org.finos.legend.engine.ide.lsp.extension.declaration.LegendDeclaration;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Kind;
import org.finos.legend.engine.ide.lsp.extension.diagnostic.LegendDiagnostic.Source;
import org.finos.legend.engine.ide.lsp.extension.text.TextInterval;
import org.junit.jupiter.api.Assertions;
import org.finos.legend.engine.ide.lsp.extension.text.TextPosition;
import org.junit.jupiter.api.Test;

public class TestServiceLSPGrammarExtension extends AbstractLSPGrammarExtensionTest<ServiceLSPGrammarExtension>
Expand Down Expand Up @@ -113,6 +116,20 @@ public void testDiagnostics_compilerError()
);
}

@Test
public void testCompletion()
{
String code = "###Service\n" +
"Service package::path::serviceName\n" +
"\n";

Iterable<? extends LegendCompletion> noCompletion = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(0, 1));
Assertions.assertFalse(noCompletion.iterator().hasNext());

String boilerPlate = this.extension.getCompletions(newSectionState("", code), TextPosition.newPosition(1, 0)).iterator().next().getDescription();
Assertions.assertEquals("Service boilerplate", boilerPlate);
}

@Test
void testAntlrExpectedTokens()
{
Expand Down
Loading

0 comments on commit 5eb2ab1

Please sign in to comment.