Skip to content

Commit

Permalink
fix(ns browser): opens vars defined in external files. Fixes #800
Browse files Browse the repository at this point in the history
- works when var metadata contains absolute filesystem path
- works when corresponding REPL has no project attached
  • Loading branch information
laurentpetit committed Jul 3, 2015
1 parent 2ca1cad commit 8b950ef
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ In case you have already checked out a User Plugin in you `~/.ccw/` folder, your
=== Miscellaneous Enhancements
- Print maven coordinates of Counterclockwise dependencies at plugin startup in `.metadata/.log`. Fixes #741
- Launching REPLs from launch configurations now correctly opens up a `REPL View` if the process outputs an nrepl URL in the stdout Console
- Namespace Browser now opens external files correctly when double clicking on a var label (e.g. will open internal Eclipse files, user plugin files, etc.)

=== Counterclockwise embedded nREPL
Counterclockwise ships with an embedded nREPL server. The following enhancements have been applied:
Expand Down
59 changes: 54 additions & 5 deletions ccw.core/src/java/ccw/ClojureCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile;
Expand All @@ -42,7 +44,9 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage;
Expand Down Expand Up @@ -228,8 +232,41 @@ public static void openInEditor(String searchedNS, String searchedFileName, int
try {
REPLView replView = REPLView.activeREPL.get();
if (replView != null) {
String projectName = replView.getLaunch().getLaunchConfiguration().getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
openInEditor(searchedNS, searchedFileName, line, projectName, false);
String projectName;
if (replView.getLaunch() != null) {
// the repl view is consecutive to a launch
projectName = replView.getLaunch().getLaunchConfiguration().getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
openInEditor(searchedNS, searchedFileName, line, projectName, false);
} else {
// the repl view is not associated to a launch

// is direct filesystem path?
File f = new File(searchedFileName);
if (f.exists()) {
try {
f = f.getCanonicalFile(); // displaying canonical file to user is easier to read!
IFileStore store = EFS.getLocalFileSystem().getStore(f.toURI());
openExternalFileInEditor(searchedNS, searchedFileName, line, store);
} catch (IOException e) {
CCWPlugin.logError("unable to open file " + f.getAbsolutePath(), e);
}
return;
}

// Find in ccw.core classpath
URL resource = CCWPlugin.getDefault().getBundle().getResource(searchedFileName);

if (resource != null) {
try {
URL fileURL = FileLocator.toFileURL(resource);
IFileStore store = EFS.getLocalFileSystem().getStore(new Path(fileURL.getPath()));
openExternalFileInEditor(searchedNS, searchedFileName, line, store);
} catch (IOException e) {
CCWPlugin.logError("error while tryping to open editor for file " + resource, e);
}
}
}

}
} catch (CoreException e) {
CCWPlugin.logError("error while trying to obtain project's name from configuration, while trying to show source file of a symbol", e);
Expand Down Expand Up @@ -382,11 +419,11 @@ private static boolean openInEditor(final String searchedNS,
final IJavaProject javaProject = JavaCore.create(project);

try {
System.out.println("search file name : " + searchedFileName);
System.out.println("searched ns : " + searchedNS);
CCWPlugin.log("search file name : " + searchedFileName);
CCWPlugin.log("searched ns : " + searchedNS);

final String searchedPackage = namespaceToPackage(searchedNS);
System.out.println("searched package: " + searchedPackage);
CCWPlugin.log("searched package: " + searchedPackage);

for (IPackageFragmentRoot packageFragmentRoot: javaProject.getAllPackageFragmentRoots()) {

Expand All @@ -409,6 +446,18 @@ private static boolean openInEditor(final String searchedNS,
return false;
}

private static boolean openExternalFileInEditor(final String searchedNS, final String initialSearchedFileName, final int line,
IFileStore store) throws PartInitException {

if (initialSearchedFileName == null) {
return false;
}
CCWPlugin.log("searched ns : " + searchedNS);
IEditorPart editor = IDE.openInternalEditorOnFileStore(CCWPlugin.getActivePage(), store);
gotoEditorLine(editor, line);
return false;
}

private static String namespaceToPackage(final String searchedNS) {
String packagePart = (searchedNS.contains(".")) ? searchedNS.substring(0, searchedNS.lastIndexOf(".")) : "";

Expand Down

0 comments on commit 8b950ef

Please sign in to comment.