Skip to content

Commit

Permalink
Double click on Tern Explorer open the declared variable, function. See
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Aug 10, 2015
1 parent f2026f0 commit d835e06
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 13 deletions.
Expand Up @@ -24,4 +24,5 @@ public interface IJSONObjectHelper {

boolean getBoolean(Object jsonObj, String name, boolean defaultValue);

Long getLong(Object jsonObject, String name);
}
2 changes: 1 addition & 1 deletion core/tern.core/src/tern/server/protocol/JsonHelper.java
Expand Up @@ -58,7 +58,7 @@ public static Long getLong(JsonObject json, String name) {
JsonValue value = json.get(name);
return value == null ? null : value.asLong();
}

public static Object getValue(JsonValue value) {
if (value == null) {
return null;
Expand Down
Expand Up @@ -63,4 +63,8 @@ public boolean getBoolean(Object jsonObject, String name, boolean defaultValue)
return JsonHelper.getBoolean((JsonObject) jsonObject, name, defaultValue);
}

@Override
public Long getLong(Object jsonObject, String name) {
return JsonHelper.getLong((JsonObject) jsonObject, name);
}
}
17 changes: 15 additions & 2 deletions core/tern.core/src/tern/server/protocol/outline/JSNode.java
Expand Up @@ -7,16 +7,22 @@ public class JSNode {

private final String name;
private final String type;
private JSNode parent;
private final Long start;
private final Long end;
private final JSNode parent;
private final List<JSNode> children;

public JSNode(String name, String type, JSNode parent) {
public JSNode(String name, String type, Long start, Long end, JSNode parent) {
this.name = name;
this.type = type;
this.start = start;
this.end = end;
this.children = new ArrayList<JSNode>();
if (parent != null) {
this.parent = parent;
parent.addChild(this);
} else {
this.parent = null;
}
}

Expand Down Expand Up @@ -44,4 +50,11 @@ public void addChild(JSNode node) {
children.add(node);
}

public Long getStart() {
return start;
}

public Long getEnd() {
return end;
}
}
Expand Up @@ -3,7 +3,7 @@
public class JSNodeRoot extends JSNode {

public JSNodeRoot() {
super("#Root", null, null);
super("#Root", null, null, null, null);
}

}
Expand Up @@ -35,12 +35,16 @@ public void process(TernDoc doc, IJSONObjectHelper jsonObjectHelper, Object json
protected void addChildren(Iterable<Object> jsonNodes, JSNode parent, IJSONObjectHelper helper) {
String name = null;
String type = null;
Long start = null;
Long end = null;
JSNode node = null;
Iterable<Object> jsonChildren;
for (Object jsonNode : jsonNodes) {
name = helper.getText(jsonNode, "name");
type = helper.getText(jsonNode, "type");
node = new JSNode(name, type, parent);
start = helper.getLong(jsonNode, "start");
end = helper.getLong(jsonNode, "end");
node = new JSNode(name, type, start, end, parent);
jsonChildren = helper.getList(jsonNode, CHILDREN_FIELD_NAME); // $NON-NLS-1$
if (jsonChildren != null) {
addChildren(jsonChildren, node, helper);
Expand Down
Expand Up @@ -259,6 +259,11 @@ public String getText(Object jsonObj, String property) {
}
return text.toString();
}

@Override
public Long getLong(Object jsonObject, String name) {
return null;
}

@Override
public boolean isString(Object value) {
Expand Down
31 changes: 24 additions & 7 deletions core/ternjs/node_modules/tern/node_modules/tern-outline/outline.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,10 +1,14 @@
package tern.eclipse.ide.internal.ui.views;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
Expand All @@ -15,7 +19,9 @@
import tern.eclipse.ide.core.TernCorePlugin;
import tern.eclipse.ide.core.resources.TernDocumentFile;
import tern.eclipse.ide.internal.ui.TernUIMessages;
import tern.eclipse.ide.ui.utils.EditorUtils;
import tern.server.TernPlugin;
import tern.server.protocol.outline.JSNode;
import tern.server.protocol.outline.TernOutlineQuery;

public class TernContentOutlinePage extends ContentOutlinePage {
Expand All @@ -37,6 +43,27 @@ public void createControl(Composite parent) {
super.createControl(parent);
getTreeViewer().setContentProvider(new TernExplorerContentProvider(this));
getTreeViewer().setLabelProvider(new DelegatingStyledCellLabelProvider(new TernExplorerLabelProvider()));
getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {

@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
if (selection.getFirstElement() instanceof JSNode) {
JSNode node = (JSNode) selection.getFirstElement();
IFile file = outline.getTernFile().getFile();
Long start = node.getStart();
Long end = node.getEnd();
EditorUtils.openInEditor(
file,
start != null ? start.intValue() : -1,
start != null && end != null ? end.intValue()
- start.intValue() : -1, true);

}
}
}
});
getTreeViewer().setAutoExpandLevel(TreeViewer.ALL_LEVELS);
refreshOutline();
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public Image getImage(Object element) {
public StyledString getStyledText(Object element) {
if (element instanceof JSNode) {
JSNode node = ((JSNode) element);
StyledString buff = new StyledString(node.getName());
StyledString buff = new StyledString(StringUtils.isEmpty(node.getName()) ? "" : node.getName());
String type = node.getType();
if (!StringUtils.isEmpty(type)) {
buff.append(" : ", StyledString.DECORATIONS_STYLER);
Expand Down

0 comments on commit d835e06

Please sign in to comment.