Skip to content

Commit

Permalink
Add auto-completion for batch imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ngallagher committed Aug 12, 2018
1 parent fca39a1 commit 60625f8
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.snapscript.studio.index.tree.EnumDefinitionIndex;
import org.snapscript.studio.index.tree.GenericReferenceIndex;
import org.snapscript.studio.index.tree.ImportIndex;
import org.snapscript.studio.index.tree.ImportListIndex;
import org.snapscript.studio.index.tree.ImportStaticIndex;
import org.snapscript.studio.index.tree.MemberFieldDeclarationIndex;
import org.snapscript.studio.index.tree.MemberFunctionIndex;
Expand Down Expand Up @@ -56,6 +57,7 @@ public enum IndexInstruction {
MODULE_FUNCTION(ModuleFunctionIndex.class, "module-function"),
MODULE_PROPERTY(ModulePropertyIndex.class, "module-property"),
IMPORT(ImportIndex.class, "import"),
IMPORT_LIST(ImportListIndex.class, "import-list"),
IMPORT_STATIC(ImportStaticIndex.class, "import-static"),
SCRIPT(ScriptIndex.class, "script");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.snapscript.compile.assemble.OperationBuilder;
import org.snapscript.core.Context;
import org.snapscript.core.NoStatement;
import org.snapscript.core.type.Type;
import org.snapscript.parse.Line;
import org.snapscript.studio.index.Index;
Expand All @@ -29,6 +30,17 @@ public Object create(Type type, Object[] arguments, Line line) throws Exception
listener.update(index);
return operation;
}
if(Index[].class.isInstance(result)) {
Index[] indexes = (Index[])result;

for(Index index : indexes) {
listener.update(index);
}
if(indexes.length > 0) {
return indexes[0].getOperation();
}
return new NoStatement();
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.snapscript.studio.index.tree;

import org.snapscript.core.Compilation;
import org.snapscript.core.NoStatement;
import org.snapscript.core.Statement;
import org.snapscript.core.module.Module;
import org.snapscript.core.module.Path;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.variable.Value;
import org.snapscript.studio.index.IndexResult;
import org.snapscript.tree.Qualifier;

import static org.snapscript.studio.index.IndexType.IMPORT;

public class ImportListIndex implements Compilation {

private final Qualifier qualifier;
private final Qualifier[] names;
private final IndexResult[] results;
private final Statement statement;

public ImportListIndex(Qualifier qualifier, Qualifier... names) {
this.statement = new NoStatement();
this.results = new IndexResult[names.length];
this.qualifier = qualifier;
this.names = names;
}

@Override
public Object compile(Module module, Path path, int line) throws Exception {
String prefix = qualifier.getQualifier();

for(int i = 0; i < names.length; i++) {
String name = names[i].getQualifier();
results[i] = new IndexResult(IMPORT, statement, null, prefix + "." + name, name, path, line);
}
return results;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.snapscript.studio.service;

import java.io.File;
import java.util.concurrent.atomic.AtomicReference;

import lombok.SneakyThrows;

import org.snapscript.studio.project.HomeDirectory;
import org.snapscript.studio.project.Workspace;
import org.snapscript.ui.ClientContext;
import org.snapscript.ui.ClientControl;
import org.snapscript.ui.ClientEngine;
import org.snapscript.ui.ClientProvider;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -18,6 +20,7 @@ public class StudioClientLauncher {
public static final String CLIENT_LOG = "client.log";
public static final String CLIENT_CACHE = "cache";

private final AtomicReference<ClientControl> reference;
private final Workspace workspace;
private final File directory;
private final boolean disabled;
Expand All @@ -29,12 +32,13 @@ public StudioClientLauncher(
@Value("${server-only}") boolean disabled,
@Value("${client-debug}") boolean debug)
{
this.reference = new AtomicReference<ClientControl>();
this.workspace = workspace;
this.directory = directory;
this.disabled = disabled;
this.debug = debug;
}

@SneakyThrows
public void launch(final ClientEngine engine, final String host, final int port) {
if(!disabled) {
Expand All @@ -58,10 +62,20 @@ public void launch(final ClientEngine engine, final String host, final int port)
final Thread thread = new Thread(new Runnable() {
@Override
public void run() {
ClientProvider.provide(engine).show(context);
ClientControl control = ClientProvider.provide(engine).show(context);
reference.set(control);
}
});
thread.start();
}
}

public void debug() {
ClientControl control = reference.get();

if(control != null) {
control.showDebugger();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.snapscript.studio.service;

import lombok.AllArgsConstructor;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.Status;
import org.snapscript.studio.common.resource.Resource;
import org.snapscript.studio.common.resource.ResourcePath;
import org.springframework.stereotype.Component;

@Component
@AllArgsConstructor
@ResourcePath("/debugger")
public class StudioClientResource implements Resource {

private final StudioClientLauncher launcher;

@Override
public void handle(Request request, Response response) throws Throwable {
response.setStatus(Status.OK);
launcher.debug();
}
}
2 changes: 1 addition & 1 deletion snap-studio/work/demo/games/src/mario/MarioGame.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ func start(scale) {
}
}

start(2);
start(4);

0 comments on commit 60625f8

Please sign in to comment.