Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make moduleGraph(), listExposedModules(), definedNames() enforce a project scheduling rule #13

Merged
1 commit merged into from

1 participant

@bscottm

IFile parameter removed, make sure that the cabal project is built before executing the command.

Scott Michel Remove IFile from moduleGraph(), definedNames() and listExposedModule…
…s(),

since they only depend on a successfully loaded and built project.
269108a
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2010
  1. Remove IFile from moduleGraph(), definedNames() and listExposedModule…

    Scott Michel authored
    …s(),
    
    since they only depend on a successfully loaded and built project.
This page is out of date. Refresh to see the latest.
View
17 net.sf.eclipsefp.haskell-feature/compile.net.sf.eclipsefp.haskell.xml
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="Compile net.sf.eclipsefp.haskell" default="main">
- <target name="main">
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.doc.user" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.util" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.scion.client" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.core" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.debug.core" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.compat" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.ui" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.ghccompiler" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.debug.ui" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.hugs" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell.haddock" target="build.jars"/>
- <ant antfile="build.xml" dir="../net.sf.eclipsefp.haskell" target="build.jars"/>
- </target>
-</project>
View
241 ...lipsefp.haskell.scion.client/src/net/sf/eclipsefp/haskell/scion/client/ScionInstance.java
@@ -82,6 +82,9 @@
/** The currently loaded file */
private IFile loadedFile;
+ /** Flag that indicates that the project has been built successfully */
+ private boolean projectIsBuilt;
+ /** The Cabal project description */
private JSONObject cabalDescription;
private Map<String, CabalPackage[]> packagesByDB;
private List<Component> components;
@@ -110,6 +113,7 @@ public ScionInstance(ScionServer server, IProject project, CabalComponentResolve
this.project = project;
this.resolver = resolver;
+ this.projectIsBuilt = false;
this.lastLoadedComponent = null;
this.loadedFile = null;
this.components = new LinkedList<Component>();
@@ -376,6 +380,7 @@ private boolean buildProjectInternal(final IProgressMonitor monitor, final boole
}
}
+ projectIsBuilt = retval;
return retval;
}
@@ -468,6 +473,7 @@ private boolean loadComponents(IProgressMonitor monitor, final boolean output, f
/** Reset initial state. */
private void internalReset() {
+ projectIsBuilt = false;
cabalDescription = null;
synchronized (components) {
components.clear();
@@ -552,9 +558,8 @@ public void deleteProblems(IResource r) {
*/
private boolean runWithComponent( final IProgressMonitor monitor, final IFile file ) {
boolean loadOK = true;
- boolean projectBuilt = ( components.size() > 0 && packagesByDB != null );
- if ( projectBuilt || buildProjectInternal(monitor, false, true) ) {
+ if ( projectIsBuilt || buildProjectInternal(monitor, false, true) ) {
Set<String> componentNames = resolver.getComponents( file );
if (lastLoadedComponent == null || !componentNames.contains(lastLoadedComponent.toString())) {
@@ -736,8 +741,144 @@ public void outline(final IFile file, final IDocument doc, final OutlineHandler
handler);
}
}
+
+ /**
+ * Located the first definition of a name.
+ *
+ * @param name The name to located.
+ * @return The editor location where the name can be found.
+ */
+ public Location firstDefinitionLocation(String name) {
+ NameDefinitionsCommand command = new NameDefinitionsCommand(name);
+ server.sendCommand(command);
+ return command.getFirstLocation();
+ }
+
+ /**
+ * Generate the Cabal project file's name from the Eclipse project's name.
+ *
+ * @param project The Eclipse project
+ * @return The "&lt;project&gt;.cabal" string.
+ */
+ public static IFile getCabalFile(final IProject project) {
+ return project.getFile(new Path(project.getName()).addFileExtension(FileUtil.EXTENSION_CABAL));
+ }
+
+ public JSONObject getCabalDescription() {
+ // Never called... :-)
+ return cabalDescription;
+ }
/**
+ * Accessor for the Cabal dependencies map.
+ *
+ * @return The cabal dependencies map.
+ */
+ public Map<String, CabalPackage[]> getPackagesByDB() {
+ return packagesByDB;
+ }
+
+ /**
+ * Accessor for the Cabal project file's components.
+ *
+ * @return A list of the cabal project's components.
+ */
+ public List<Component> getComponents() {
+ return components;
+ }
+
+ /**
+ * Get the currently visible (defined) names, used for generating completions.
+ *
+ * @return A list of defined names.
+ */
+ public List<String> definedNames( ) {
+ final DefinedNamesCommand cmd = new DefinedNamesCommand();
+
+ withProject( cmd, NLS.bind(ScionText.definedNames_task_name, project.getName()));
+ return cmd.getNames();
+ }
+
+ public List<String> listExposedModules( ) {
+ if (exposedModulesCache == null) {
+ final ListExposedModulesCommand cmd = new ListExposedModulesCommand();
+
+ withProject( cmd, NLS.bind(ScionText.listExposedModules_task_name, project.getName()) );
+ exposedModulesCache = Collections.unmodifiableList(cmd.getNames());
+ }
+
+ return exposedModulesCache;
+ }
+
+ public List<String> moduleGraph( ) {
+ final ModuleGraphCommand cmd = new ModuleGraphCommand();
+
+ withProject( cmd, NLS.bind(ScionText.moduleGraph_task_name, project.getName()) );
+ return cmd.getNames();
+ }
+
+ public synchronized List<TokenDef> tokenTypes(final IFile file, final String contents) {
+ TokenTypesCommand command = new TokenTypesCommand(file, contents, FileUtil.hasLiterateExtension(file));
+ server.sendCommand(command);
+ return command.getTokens();
+ }
+
+ /**
+ * Set the scion-server's debug level to deafening (lots of output!)
+ */
+ public void setDeafening() {
+ server.sendCommand(new SetVerbosityCommand(3));
+ }
+
+ /**
+ * Predicate test for whether command groups need a project rule in addition to the file rule.
+ *
+ * @param file The file, used to query component names.
+ * @return true if a project rule is needed.
+ */
+ private boolean needsProjectRule( final IFile file ) {
+ Set<String> componentNames = resolver.getComponents( file );
+ boolean needsComponent = (lastLoadedComponent == null || !componentNames.contains(lastLoadedComponent.toString()) );
+
+ return !projectIsBuilt || needsComponent;
+ }
+
+ /**
+ * Ensure that the command sequence is executed using a project scheduling rule. The resulting Job
+ * is executed synchronously.
+ */
+ private boolean withProject( final ScionCommand command, final String jobName ) {
+ Job projJob = new Job ( jobName ) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ IStatus retval = Status.CANCEL_STATUS;
+ if ( projectIsBuilt || buildProjectInternal(monitor, false, true) ) {
+ retval = (server.sendCommand(command) ? Status.OK_STATUS : Status.CANCEL_STATUS);
+ }
+
+ return retval;
+ }
+ };
+
+ // Note: All of this code could go into a separate class, but this is only used
+ // once, so really no point.
+ projJob.setPriority( Job.INTERACTIVE );
+ projJob.setRule( project );
+ projJob.schedule();
+
+ while (projJob.getResult() == null) {
+ try {
+ projJob.join();
+ } catch (InterruptedException irq) {
+ // Return something reasonable.
+ return false;
+ }
+ }
+
+ return (projJob.getResult().equals(Status.OK_STATUS));
+ }
+
+ /**
* Ensure that the given file is the current file before executing a command.
* If a multi-command sequence must be executed, the command sequence is
* executed synchronously.
@@ -845,102 +986,6 @@ protected IStatus run(IProgressMonitor monitor) {
return (cmdGroup.runGroupSynchronously().equals(Status.OK_STATUS));
}
-
- /**
- * Located the first definition of a name.
- *
- * @param name The name to located.
- * @return The editor location where the name can be found.
- */
- public Location firstDefinitionLocation(String name) {
- NameDefinitionsCommand command = new NameDefinitionsCommand(name);
- server.sendCommand(command);
- return command.getFirstLocation();
- }
-
- /**
- * Generate the Cabal project file's name from the Eclipse project's name.
- *
- * @param project The Eclipse project
- * @return The "&lt;project&gt;.cabal" string.
- */
- public static IFile getCabalFile(final IProject project) {
- return project.getFile(new Path(project.getName()).addFileExtension(FileUtil.EXTENSION_CABAL));
- }
-
- public JSONObject getCabalDescription() {
- // Never called... :-)
- return cabalDescription;
- }
-
- /**
- * Accessor for the Cabal dependencies map.
- *
- * @return The cabal dependencies map.
- */
- public Map<String, CabalPackage[]> getPackagesByDB() {
- return packagesByDB;
- }
-
- /**
- * Accessor for the Cabal project file's components.
- *
- * @return A list of the cabal project's components.
- */
- public List<Component> getComponents() {
- return components;
- }
-
- /**
- * Get the currently visible (defined) names, used for generating completions.
- *
- * @return A list of defined names.
- */
- public List<String> definedNames( final IFile file ) {
- final DefinedNamesCommand cmd = new DefinedNamesCommand();
-
- withLoadedFile(file, cmd, NLS.bind(ScionText.definedNames_task_name, file.getName()));
- return cmd.getNames();
- }
-
- public List<String> listExposedModules( final IFile file ) {
- if (exposedModulesCache == null) {
- final ListExposedModulesCommand cmd = new ListExposedModulesCommand();
-
- withLoadedFile( file, cmd, NLS.bind(ScionText.listExposedModules_task_name, file.getName()) );
- exposedModulesCache = Collections.unmodifiableList(cmd.getNames());
- }
-
- return exposedModulesCache;
- }
-
- public List<String> moduleGraph( final IFile file ) {
- final ModuleGraphCommand cmd = new ModuleGraphCommand();
-
- withLoadedFile( file, cmd, NLS.bind(ScionText.moduleGraph_task_name, file.getName()) );
- return cmd.getNames();
- }
-
- public synchronized List<TokenDef> tokenTypes(final IFile file, final String contents) {
- TokenTypesCommand command = new TokenTypesCommand(file, contents, FileUtil.hasLiterateExtension(file));
- server.sendCommand(command);
- return command.getTokens();
- }
-
- /**
- * Set the scion-server's debug level to deafening (lots of output!)
- */
- public void setDeafening() {
- server.sendCommand(new SetVerbosityCommand(3));
- }
-
- private boolean needsProjectRule( final IFile file ) {
- boolean needsBuild = ( components.size() == 0 || packagesByDB == null );
- Set<String> componentNames = resolver.getComponents( file );
- boolean needsComponent = (lastLoadedComponent == null || !componentNames.contains(lastLoadedComponent.toString()) );
-
- return needsBuild || needsComponent;
- }
private synchronized LoadInfo getLoadInfo(IFile file) {
LoadInfo li = loadInfos.get(file);
View
2  ...fp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/HaskellEditor.java
@@ -98,7 +98,7 @@
private ScionInstance instance = null;
private final OutlineHandler outlineHandler = new OutlineHandler() {
-
+ @Override
public void handleOutline( final List<OutlineDef> defs ) {
outlinePage.setInput( defs );
foldingStructureProvider.updateFoldingRegions( defs );
View
6 ...sf/eclipsefp/haskell/ui/internal/editors/haskell/codeassist/HaskellCompletionContext.java
@@ -86,7 +86,7 @@ private void searchDefinedNames( final String prefix,
final ScionInstance si = ScionPlugin.getScionInstance( file );
// sync access
if( si != null ) {
- List<String> names = si.definedNames( file );
+ List<String> names = si.definedNames( );
searchStringList( prefix, names, result );
}
}
@@ -99,8 +99,8 @@ private void searchModulesNames( final String prefix, final List<ICompletionProp
final ScionInstance si = ScionPlugin.getScionInstance( file );
// sync access
if( si != null ) {
- searchStringList( prefix, si.moduleGraph( file ), result );
- searchStringList( prefix, si.listExposedModules( file ), result);
+ searchStringList( prefix, si.moduleGraph( ), result );
+ searchStringList( prefix, si.listExposedModules( ), result);
}
}
}
View
2  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
@@ -366,7 +366,7 @@ public boolean visit( final IResourceDelta delta )
}
return false;
} else if (f.equals( cabalF )){
- stopInstance( f);
+ stopInstance( f );
return false;
}
View
2  ...et/sf/eclipsefp/haskell/ui/internal/views/projectexplorer/HaskellResourceExtensionCP.java
@@ -55,7 +55,7 @@
// underneath
if( FileUtil.hasHaskellExtension( f ) && ResourceUtil.isInHaskellProject( f )) {
ScionInstance si = ScionPlugin.getScionInstance( f );
- if (si != null){
+ if (si != null) {
List<OutlineDef> outlineDefs = si.outline( f );
OutlineCP cp = new OutlineCP();
cp.inputChanged( null, null, outlineDefs );
View
8 ...f.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/wizards/CabalSDistOptionsPage.java
@@ -1,6 +1,7 @@
package net.sf.eclipsefp.haskell.ui.wizards;
import java.io.File;
+import java.util.Iterator;
import java.util.List;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
import org.eclipse.core.resources.IProject;
@@ -50,8 +51,9 @@ public void createControl( final Composite parent ) {
gd=new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
tFolder.setLayoutData( gd );
- //if (projects.size()>0){
- final IProject uniqueP=projects.iterator().next();
+ Iterator<IProject> projIter = projects.iterator();
+ if (projIter.hasNext()) {
+ final IProject uniqueP=projIter.next();
final String projectLocation=uniqueP.getLocation().toOSString();
fullPath=uniqueP.getLocation().append( "dist" ).toOSString();
Button bFolder=new Button(composite,SWT.PUSH);
@@ -72,7 +74,7 @@ public void widgetSelected( final SelectionEvent e ) {
tFolder.setText( toDisplay );
}
});
- //}
+ }
bSnapshot=new Button(composite,SWT.CHECK);
bSnapshot.setText( UITexts.exportSource_options_snapshot );
Something went wrong with that request. Please try again.