Skip to content

Commit

Permalink
Continue modularization
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredebelen committed Feb 27, 2024
1 parent 7b4c0cc commit 1ae8b20
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,32 @@

<dependencies>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
</dependency>


<!-- Pure Language Parser / Compiler -->
<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-m4</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-m3-core</artifactId>
</dependency>

<!-- Pure Grammar -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-protocol</artifactId>
<artifactId>legend-engine-language-pure-grammar</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-protocol-pure</artifactId>
<artifactId>legend-engine-protocol</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-grammar</artifactId>
<artifactId>legend-engine-protocol-pure</artifactId>
</dependency>
<!-- Pure Grammar -->

<!-- Pure Compiler -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-compiler</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-shared-extensions</artifactId>
</dependency>
<!-- Pure Language Parser / Compiler -->
<!-- Pure Compiler -->

<!-- Java compiled code support -->
<dependency>
Expand Down Expand Up @@ -96,25 +86,12 @@
</dependency>
<!-- Pure Plan Generation / Execution -->

<!-- Relational -->
<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-m2-dsl-store-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-m2-store-relational-pure</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.finos.legend.engine</groupId>-->
<!-- <artifactId>legend-engine-xt-relationalStore-executionPlan</artifactId>-->
<!-- </dependency>-->
<!-- Extensions (use by Ext) -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-relationalStore-grammar</artifactId>
<scope>Runtime</scope>
<artifactId>legend-engine-shared-extensions</artifactId>
</dependency>
<!-- Relational -->
<!-- Extensions (use by Ext) -->

<dependency>
<groupId>org.eclipse.collections</groupId>
Expand All @@ -125,6 +102,11 @@
<artifactId>eclipse-collections-api</artifactId>
</dependency>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand All @@ -140,7 +122,6 @@
<artifactId>junit</artifactId>
</dependency>


<!-- TODO -> Itemize... Only using ErrorManagement import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.*;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.classInstance.relation.ColSpec;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.classInstance.relation.ColSpecArray;
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.classInstance.relation.RelationStoreAccessor;
import org.finos.legend.engine.repl.autocomplete.handlers.*;
import org.finos.legend.engine.repl.autocomplete.parser.ParserFixer;
import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionAccessor;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation.RelationType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType;
import org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store;
import org.finos.legend.pure.m3.navigation.M3Paths;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;

Expand All @@ -60,8 +57,16 @@ public class Completer
private final int lineOffset;
private final MutableMap<String, FunctionHandler> handlers;

private MutableList<CompleterExtension> extensions;

public Completer(String buildCodeContext)
{
this(buildCodeContext, Lists.mutable.empty());
}

public Completer(String buildCodeContext, MutableList<CompleterExtension> extensions)
{
this.extensions = extensions;
this.buildCodeContext = buildCodeContext;
this.header =
buildCodeContext +
Expand Down Expand Up @@ -180,30 +185,10 @@ else if (topExpression instanceof AppliedProperty)
private CompletionResult processClassInstance(ClassInstance topExpression, PureModel pureModel)
{
Object islandExpr = topExpression.value;
if (islandExpr instanceof RelationStoreAccessor)
CompletionResult result = this.extensions.collect(x -> x.extraClassInstanceProcessor(islandExpr, pureModel)).getFirst();
if (result != null)
{
MutableList<String> path = Lists.mutable.withAll(((RelationStoreAccessor) islandExpr).path);
String writtenPath = path.makeString("::").replace(ParserFixer.magicToken, "");
MutableList<Store> elements = pureModel.getAllStores().select(c -> nameMatch(c, writtenPath)).toList();
if (elements.size() == 1 &&
writtenPath.startsWith(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(elements.get(0))) &&
!writtenPath.equals(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(elements.get(0)))
)
{
org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database db = (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) elements.get(0);
String writtenTableName = writtenPath.replace(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(db), "").replace("::", "");
MutableList<? extends org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Table> tables = db._schemas().isEmpty() ? Lists.mutable.empty() : db._schemas().getFirst()._tables().toList();
MutableList<? extends org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Table> foundTables = tables.select(c -> c._name().startsWith(writtenTableName));
if ((foundTables.size() == 1 && foundTables.get(0)._name().equals(path.getLast())))
{
return new CompletionResult(Lists.mutable.empty());
}
else
{
return new CompletionResult(foundTables.collect(c -> new CompletionItem(c._name(), c._name() + "}")));
}
}
return new CompletionResult(ListIterate.collect(elements, c -> new CompletionItem(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c), ">{" + org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c))).toList());
return result;
}
return new CompletionResult(Lists.mutable.empty());
}
Expand Down Expand Up @@ -239,19 +224,6 @@ public static MutableList<CompletionItem> proposeColumnNamesForEditColSpec(ColSp
//--------------------------------------------------------------------


private static boolean nameMatch(PackageableElement c, String writtenPath)
{
String path = org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c);
if (path.length() > writtenPath.length())
{
return path.startsWith(writtenPath);
}
else
{
return writtenPath.startsWith(path);
}
}

private ValueSpecification parseValueSpecification(String value)
{
String code = header + value + "\n" + "\n}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.repl.autocomplete;

import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;

public interface CompleterExtension
{
CompletionResult extraClassInstanceProcessor(Object islandExpr, PureModel pureModel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.block.predicate.checked.CheckedPredicate;
import org.finos.legend.engine.repl.autocomplete.CompleterExtension;
import org.finos.legend.engine.repl.core.Command;
import org.finos.legend.engine.repl.core.ReplExtension;
import org.finos.legend.engine.repl.core.commands.*;
Expand All @@ -39,18 +40,22 @@ public class Client
private final Terminal terminal;
private final LineReader reader;
private boolean debug = false;

private MutableList<ReplExtension> replExtensions = Lists.mutable.empty();
private MutableList<CompleterExtension> completerExtensions = Lists.mutable.empty();

public static void main(String[] args) throws Exception
{
new Client().loop();
new Client(Lists.mutable.empty(), Lists.mutable.empty()).loop();
}

public MutableList<Command> commands;

public Client() throws Exception
public Client(MutableList<ReplExtension> replExtensions, MutableList<CompleterExtension> completerExtensions) throws Exception
{
replExtensions.forEach(c -> c.setClient(this));
this.replExtensions = replExtensions;
this.completerExtensions = completerExtensions;

this.terminal = TerminalBuilder.terminal();

this.terminal.writer().println("\n" + Logos.logos.get((int) (Logos.logos.size() * Math.random())) + "\n");
Expand Down Expand Up @@ -157,7 +162,12 @@ public void setDebug(boolean debug)

public MutableList<ReplExtension> getReplExtensions()
{
return replExtensions;
return this.replExtensions;
}

public MutableList<CompleterExtension> getCompleterExtensions()
{
return this.completerExtensions;
}

public MutableList<String> buildState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.factory.Lists;
import org.finos.legend.engine.plan.execution.result.Result;
import org.finos.legend.engine.repl.client.Client;
import org.finos.legend.engine.shared.core.extension.LegendExtension;

public interface ReplExtension extends LegendExtension
Expand Down Expand Up @@ -46,4 +47,6 @@ default MutableList<String> typeGroup()
boolean supports(Result res);

String print(Result res);

void setClient(Client client);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public MutableList<Candidate> complete(String inScope, LineReader lineReader, Pa
try
{
MutableList<Candidate> list = Lists.mutable.empty();
CompletionResult result = new org.finos.legend.engine.repl.autocomplete.Completer(this.client.buildState().makeString("\n")).complete(inScope);
CompletionResult result = new org.finos.legend.engine.repl.autocomplete.Completer(this.client.buildState().makeString("\n"), this.client.getCompleterExtensions()).complete(inScope);
if (result.getEngineException() == null)
{
list.addAll(result.getCompletion().collect(this::buildCandidate));
Expand Down
Loading

0 comments on commit 1ae8b20

Please sign in to comment.