Skip to content

Commit

Permalink
Allow navigating on class super types (finos#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey authored Jun 5, 2024
1 parent 79335fa commit 793379a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ private Stream<LegendReferenceResolver> toReferences(org.finos.legend.pure.m3.co
RichIterable<? extends CoreInstance> qualifiedProperties = clazz._qualifiedProperties();
Stream<LegendReferenceResolver> qualifiedPropertyReferences = StreamSupport.stream(qualifiedProperties.spliterator(), false)
.flatMap(qualifiedProperty -> FUNCTION_EXPRESSION_NAVIGATOR.findReferences(Optional.ofNullable(qualifiedProperty)));
return Stream.concat(constraintReferences, qualifiedPropertyReferences);

Stream<LegendReferenceResolver> superTypes = StreamSupport.stream(clazz._generalizations().spliterator(), false)
.map(generalization -> LegendReferenceResolver.newReferenceResolver(generalization.getSourceInformation(), generalization._general()._rawType()));

return Stream.concat(Stream.concat(constraintReferences, qualifiedPropertyReferences), superTypes);
}

private Stream<LegendReferenceResolver> toReferences(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association association)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void testDiagnostics_multipleFiles_compilerError()
" hireDate : Date[1];\n" +
" hireType : String[1];\n" +
"}");
testDiagnostics(codeFiles, "vscodelsp::test::Employee1", LegendDiagnostic.newDiagnostic(TextLocation.newTextSource("vscodelsp::test::Employee1",1, 0, 6, 0), "Can't find type 'vscodelsp::test::Employee2'", Kind.Error, Source.Compiler));
testDiagnostics(codeFiles, "vscodelsp::test::Employee1", LegendDiagnostic.newDiagnostic(TextLocation.newTextSource("vscodelsp::test::Employee1",1, 41, 1, 66), "Can't find type 'vscodelsp::test::Employee2'", Kind.Error, Source.Compiler));
}

@Test
Expand Down Expand Up @@ -587,6 +587,44 @@ void functionTestsExecution()
assertTestExecution("model::Hello_String_1__String_1_.testSuite_1.testPass", Set.of(), sectionState, location1, List.of(passResult));
}

@Test
void testGetReferenceResolversClass()
{
MutableMap<String, String> codeFiles = Maps.mutable.empty();

String docId = "classes.pure";
codeFiles.put(docId,
"###Pure\n" +
"Class showcase::model::Mammal\n" +
"{\n" +
" id: String[1];\n" +
"}\n" +
"Class showcase::model::Pet\n" +
"{\n" +
" name: String[1];\n" +
"}\n" +
"Class showcase::model::Dog extends showcase::model::Pet, showcase::model::Mammal\n" +
"{\n" +
"}\n"
);


LegendReference petReference = LegendReference.builder()
.withLocation(TextLocation.newTextSource(docId, 9, 35, 9, 54))
.withReferencedLocation(TextLocation.newTextSource(docId, 5, 0, 8, 0))
.build();

testReferenceLookup(codeFiles, docId, TextPosition.newPosition(9, 50), petReference, "Supertype linked to class");

LegendReference mammalReference = LegendReference.builder()
.withLocation(TextLocation.newTextSource(docId, 9, 57, 9, 79))
.withReferencedLocation(TextLocation.newTextSource(docId, 1, 0, 4, 0))
.build();

testReferenceLookup(codeFiles, docId, TextPosition.newPosition(9, 65), mammalReference, "Supertype linked to class");

}

@Test
void testGetReferenceResolversProfilesAndProperties()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void testWorkspaceDiagnostic() throws Exception
// report compile diagnostics on file
Set<Diagnostic> compileDiagnostic = Set.of(
new Diagnostic(
new Range(new Position(1, 0), new Position(4, 1)),
new Range(new Position(1, 23), new Position(1, 31)),
"Can't find type 'abc::abc'",
DiagnosticSeverity.Error,
"Compiler"
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

<properties>

<legend.engine.version>4.46.0</legend.engine.version>
<legend.sdlc.version>0.162.5</legend.sdlc.version>
<legend.engine.version>4.47.2</legend.engine.version>
<legend.sdlc.version>0.163.0</legend.sdlc.version>

<logback.version>1.4.14</logback.version>

Expand Down

0 comments on commit 793379a

Please sign in to comment.