Adds UI for viewing JavaScript file in debugger

This commit is contained in:
konsoletyper 2014-08-31 11:48:09 +04:00
parent 238cb69fb9
commit 94855d04d0
4 changed files with 57 additions and 7 deletions

View File

@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.8.0,4.0)",
org.eclipse.jdt.launching;bundle-version="[3.6.1,4.0.0)", org.eclipse.jdt.launching;bundle-version="[3.6.1,4.0.0)",
org.eclipse.ui.editors;bundle-version="[3.8.0,4.0.0)", org.eclipse.ui.editors;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.8.2,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.8.2,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.8.2,4.0.0)" org.eclipse.jdt.ui;bundle-version="[3.8.2,4.0.0)",
org.eclipse.core.filesystem;bundle-version="1.4.0"
Bundle-ClassPath: ., Bundle-ClassPath: .,
lib/asm-5.0.1.jar, lib/asm-5.0.1.jar,
lib/asm-commons-5.0.1.jar, lib/asm-commons-5.0.1.jar,

View File

@ -136,12 +136,12 @@ public class TeaVMJSStackFrame implements IStackFrame {
@Override @Override
public int getCharEnd() throws DebugException { public int getCharEnd() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getColumn() + 2 : -1; return -1;
} }
@Override @Override
public int getCharStart() throws DebugException { public int getCharStart() throws DebugException {
return callFrame.getLocation() != null ? callFrame.getLocation().getColumn() + 1 : -1; return -1;
} }
@Override @Override

View File

@ -15,9 +15,13 @@
*/ */
package org.teavm.eclipse.debugger; package org.teavm.eclipse.debugger;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
import org.teavm.debugging.information.SourceLocation; import org.teavm.debugging.information.SourceLocation;
import org.teavm.debugging.javascript.JavaScriptLocation;
/** /**
* *
@ -26,11 +30,38 @@ import org.teavm.debugging.information.SourceLocation;
public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipant { public class TeaVMSourceLookupParticipant extends AbstractSourceLookupParticipant {
@Override @Override
public String getSourceName(Object object) throws CoreException { public String getSourceName(Object object) throws CoreException {
if (!(object instanceof TeaVMStackFrame)) { if (object instanceof TeaVMStackFrame) {
TeaVMStackFrame stackFrame = (TeaVMStackFrame)object;
SourceLocation location = stackFrame.callFrame.getLocation();
return location != null ? location.getFileName() : null;
} else if (object instanceof TeaVMJSStackFrame) {
TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object;
JavaScriptLocation location = stackFrame.callFrame.getLocation();
return location != null ? location.getScript() : null;
} else {
return null; return null;
} }
TeaVMStackFrame stackFrame = (TeaVMStackFrame)object; }
SourceLocation location = stackFrame.callFrame.getLocation();
return location != null ? location.getFileName() : null; @Override
public Object[] findSourceElements(Object object) throws CoreException {
Object[] result = super.findSourceElements(object);
if (object instanceof TeaVMJSStackFrame) {
TeaVMJSStackFrame stackFrame = (TeaVMJSStackFrame)object;
JavaScriptLocation location = stackFrame.getCallFrame().getLocation();
if (location != null) {
URL url;
try {
url = new URL(location.getScript());
} catch (MalformedURLException e) {
url = null;
}
if (url != null) {
result = Arrays.copyOf(result, result.length + 1);
result[result.length - 1] = url;
}
}
}
return result;
} }
} }

View File

@ -15,6 +15,11 @@
*/ */
package org.teavm.eclipse.debugger.ui; package org.teavm.eclipse.debugger.ui;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.debug.core.model.ILineBreakpoint; import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IValue;
@ -23,6 +28,8 @@ import org.eclipse.debug.ui.IValueDetailListener;
import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.part.FileEditorInput;
import org.teavm.debugging.CallFrame; import org.teavm.debugging.CallFrame;
import org.teavm.debugging.javascript.JavaScriptCallFrame; import org.teavm.debugging.javascript.JavaScriptCallFrame;
@ -41,6 +48,8 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug
public String getEditorId(IEditorInput input, Object element) { public String getEditorId(IEditorInput input, Object element) {
if (element instanceof IFile || element instanceof ILineBreakpoint) { if (element instanceof IFile || element instanceof ILineBreakpoint) {
return JavaUI.ID_CU_EDITOR; return JavaUI.ID_CU_EDITOR;
} else if (element instanceof URL) {
return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
} }
return null; return null;
} }
@ -53,6 +62,15 @@ public class TeaVMDebugModelPresentation extends LabelProvider implements IDebug
if (element instanceof ILineBreakpoint) { if (element instanceof ILineBreakpoint) {
return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource()); return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
} }
if (element instanceof URL) {
try {
URI uri = new URI(element.toString());
IFileStore store = EFS.getLocalFileSystem().getStore(uri);
return new FileStoreEditorInput(store);
} catch (URISyntaxException e) {
return null;
}
}
return null; return null;
} }