Skip to content

Commit

Permalink
Refactorings of the Scion client code.
Browse files Browse the repository at this point in the history
Now uses the Eclipse job scheduler to run commands.
This is a lot cleaner than using our own command queue;
moreover, it gives us more flexibility such as job priorities and cancellation.

Also, made parts of ...scion.client internal for
a cleaner separation of interface and implementation.
  • Loading branch information
Thomas ten Cate committed Jul 18, 2009
1 parent f385d2b commit a28871e
Show file tree
Hide file tree
Showing 47 changed files with 1,057 additions and 776 deletions.
1 change: 0 additions & 1 deletion net.sf.eclipsefp.haskell-feature/feature.xml
Expand Up @@ -24,7 +24,6 @@ available at http://www.eclipse.org/legal/epl-v10.html.
<import plugin="org.eclipse.ui.cheatsheets" version="3.2.0" match="compatible"/>
<import plugin="net.sf.eclipsefp.haskell.ui"/>
<import plugin="net.sf.eclipsefp.haskell.haddock"/>
<import plugin="de.leiffrenzel.cohatoe.server.core"/>
<import plugin="org.eclipse.core.expressions" version="3.2.0" match="compatible"/>
<import plugin="org.eclipse.core.runtime" version="3.2.0" match="compatible"/>
<import plugin="org.eclipse.debug.core" version="3.2.0" match="compatible"/>
Expand Down
3 changes: 2 additions & 1 deletion net.sf.eclipsefp.haskell.core/META-INF/MANIFEST.MF
Expand Up @@ -7,7 +7,8 @@ Bundle-Vendor: %bundleVendor
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)"
org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
net.sf.eclipsefp.haskell.scion.client;bundle-version="0.13.0"
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Expand Down
1 change: 0 additions & 1 deletion net.sf.eclipsefp.haskell.scion.client/META-INF/MANIFEST.MF
Expand Up @@ -13,5 +13,4 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
org.eclipse.text
Bundle-Vendor: Thomas ten Cate <ttencate@gmail.com>
Export-Package: net.sf.eclipsefp.haskell.scion.client,
net.sf.eclipsefp.haskell.scion.commands,
net.sf.eclipsefp.haskell.scion.types
6 changes: 3 additions & 3 deletions net.sf.eclipsefp.haskell.scion.client/build.properties
@@ -1,9 +1,9 @@
source.. = src/
source.. = src/,\
lib/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
about.html,\
plugin.xml
about.html
src.includes = src/,\
lib/
13 changes: 0 additions & 13 deletions net.sf.eclipsefp.haskell.scion.client/plugin.properties
Expand Up @@ -5,16 +5,3 @@
# bundle manifest
bundleVendor = Thomas ten Cate <ttencate@gmail.com>
bundleName = Scion Client for EclipseFP

# Preferences
ScionPP.name = Scion
ScionServerExecutable.label = &Server executable (%1$s):
AutodetectButton.label = Try to find the server executable in common directories:
AutodetectButton.text = &Autodetect
AutodetectButton.errorTitle = Server executable not found
AutodetectButton.errorMessage = The Scion server executable, %1$s, could not be found.\n\nMake sure that Scion is installed on your system. If Scion is installed, try specifying the location of %1$s by hand.

# ExecutableFileFieldEditor
ExecutableFileFieldEditor.errorDoesNotExist = The specified file must exist
ExecutableFileFieldEditor.errorNotAbsolute = Path must be absolute
ExecutableFileFieldEditor.errorNotExecutable = The specified file must be executable
20 changes: 0 additions & 20 deletions net.sf.eclipsefp.haskell.scion.client/plugin.xml

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,119 @@
package net.sf.eclipsefp.haskell.scion.client;

import net.sf.eclipsefp.haskell.scion.internal.client.ScionThreadManager;
import net.sf.eclipsefp.haskell.scion.internal.commands.BackgroundTypecheckFileCommand;
import net.sf.eclipsefp.haskell.scion.internal.commands.ConnectionInfoCommand;
import net.sf.eclipsefp.haskell.scion.internal.commands.LoadCommand;
import net.sf.eclipsefp.haskell.scion.internal.commands.NameDefinitionsCommand;
import net.sf.eclipsefp.haskell.scion.internal.commands.ThingAtPointCommand;
import net.sf.eclipsefp.haskell.scion.internal.util.Multiset;
import net.sf.eclipsefp.haskell.scion.types.Location;

/**
* Manages a single instance of the Scion server.
*
* This is one level above {@link ScionThreadManager}, in the sense that it is concerned
* with the semantics of the commands, instead of the mechanics of sending and receiving.
*
* Objects from this class keep track of the state of the Scion server, so that the server
* can be put into the same state after a restart (either of the server, or of the entire
* workbench).
*
* @author Thomas ten Cate
*/
public class ScionInstance {

private String serverExecutable;
private ScionThreadManager threadManager;
private Multiset<String> loadedFiles = new Multiset<String>();

public ScionInstance(String serverExecutable) {
this.serverExecutable = serverExecutable;
createThreadManager();
}

public String getServerExecutable() {
return serverExecutable;
}

public void setServerExecutable(String serverExecutable) {
if (!this.serverExecutable.equals(serverExecutable)) {
destroyThreadManager();
this.serverExecutable = serverExecutable;
createThreadManager();
}
}

public void stop() {
destroyThreadManager();
}

////////////////////////////
// Thread manager handling

private void createThreadManager() {
threadManager = new ScionThreadManager(serverExecutable);
}

private void destroyThreadManager() {
threadManager.dispose();
threadManager = null;
}

////////////////
// State stuff


//////////////////////
// Specific commands

private void checkProtocol() {
ConnectionInfoCommand command = new ConnectionInfoCommand(threadManager);
if (command.runSync().isOK()) {
// TODO
}
}

public void backgroundTypecheckFile(String fileName) {
BackgroundTypecheckFileCommand command = new BackgroundTypecheckFileCommand(threadManager, fileName);
command.runAsync();
}

public void loadFile(String fileName) {
loadedFiles.add(fileName);
reloadFile(fileName);
}

public void reloadFile(String fileName) {
LoadCommand loadCommand = new LoadCommand(threadManager, fileName);
BackgroundTypecheckFileCommand typecheckCommand = new BackgroundTypecheckFileCommand(threadManager, fileName);
typecheckCommand.runAsyncAfter(loadCommand);
loadCommand.runAsync();
}

public void unloadFile(String fileName) {
// TODO Scion has no command for unloading yet!
loadedFiles.remove(fileName);
}

public String thingAtPoint(Location location) {
ThingAtPointCommand command = new ThingAtPointCommand(threadManager, location);
command.runSync();
if (command.getResult().isOK()) {
return command.getThing();
} else {
return null;
}
}

public Location firstDefinitionLocation(String name) {
NameDefinitionsCommand command = new NameDefinitionsCommand(threadManager, name);
command.runSync();
if (command.getResult().isOK() && command.isFound()) {
return command.getFirstLocation();
} else {
return null;
}
}

}
Expand Up @@ -24,21 +24,15 @@ public ScionPlugin() {
@Override
public void start(BundleContext context) throws Exception {
super.start(context);

resourceBundle = ResourceBundle.getBundle("plugin");

// Preload the server in anticipation of its use
Scion.initializeClient();
}

@Override
public void stop(BundleContext context) throws Exception {
Scion.dispose();

super.stop(context);
}

private static String getPluginId() {
public static String getPluginId() {
if (instance != null) {
return instance.getBundle().getSymbolicName();
} else {
Expand Down

0 comments on commit a28871e

Please sign in to comment.