mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add proper breakpoint positioning in IDEA
This commit is contained in:
parent
40e06a573c
commit
98efadc6fd
|
@ -114,10 +114,13 @@ class TeaVMBuild {
|
||||||
tool.setProgressListener(createProgressListener(context));
|
tool.setProgressListener(createProgressListener(context));
|
||||||
tool.setLog(new EmptyTeaVMToolLog());
|
tool.setLog(new EmptyTeaVMToolLog());
|
||||||
tool.setMainClass(config.getMainClass());
|
tool.setMainClass(config.getMainClass());
|
||||||
tool.setSourceMapsFileGenerated(config.isSourceMapsFileGenerated());
|
|
||||||
tool.setTargetDirectory(new File(config.getTargetDirectory()));
|
tool.setTargetDirectory(new File(config.getTargetDirectory()));
|
||||||
tool.setClassLoader(buildClassLoader());
|
tool.setClassLoader(buildClassLoader());
|
||||||
|
|
||||||
|
tool.setSourceMapsFileGenerated(config.isSourceMapsFileGenerated());
|
||||||
|
tool.setDebugInformationGenerated(config.isSourceMapsFileGenerated());
|
||||||
tool.setSourceFilesCopied(config.isSourceFilesCopied());
|
tool.setSourceFilesCopied(config.isSourceFilesCopied());
|
||||||
|
|
||||||
tool.setMinifying(config.isMinifying());
|
tool.setMinifying(config.isMinifying());
|
||||||
for (SourceFileProvider fileProvider : sourceFileProviders) {
|
for (SourceFileProvider fileProvider : sourceFileProviders) {
|
||||||
tool.addSourceFileProvider(fileProvider);
|
tool.addSourceFileProvider(fileProvider);
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class TeaVMDebugProcess extends XDebugProcess {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
breakpointHandler = new TeaVMLineBreakpointHandler(innerDebugger);
|
breakpointHandler = new TeaVMLineBreakpointHandler(session.getProject(), innerDebugger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Debugger initDebugger() {
|
private Debugger initDebugger() {
|
||||||
|
|
|
@ -16,29 +16,70 @@
|
||||||
package org.teavm.idea.debug;
|
package org.teavm.idea.debug;
|
||||||
|
|
||||||
import com.intellij.debugger.ui.breakpoints.JavaLineBreakpointType;
|
import com.intellij.debugger.ui.breakpoints.JavaLineBreakpointType;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||||
|
import com.intellij.openapi.roots.ProjectRootManager;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||||
import com.intellij.xdebugger.breakpoints.XBreakpointHandler;
|
import com.intellij.xdebugger.breakpoints.XBreakpointHandler;
|
||||||
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
|
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
|
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
|
||||||
import org.teavm.debugging.Breakpoint;
|
import org.teavm.debugging.Breakpoint;
|
||||||
import org.teavm.debugging.Debugger;
|
import org.teavm.debugging.Debugger;
|
||||||
|
|
||||||
public class TeaVMLineBreakpointHandler extends XBreakpointHandler<XLineBreakpoint<JavaLineBreakpointProperties>> {
|
public class TeaVMLineBreakpointHandler extends XBreakpointHandler<XLineBreakpoint<JavaLineBreakpointProperties>> {
|
||||||
private Debugger innerDebugger;
|
private Debugger innerDebugger;
|
||||||
|
private VirtualFileManager vfs;
|
||||||
|
private ProjectFileIndex fileIndex;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public TeaVMLineBreakpointHandler(Debugger innerDebugger) {
|
public TeaVMLineBreakpointHandler(Project project, Debugger innerDebugger) {
|
||||||
super(JavaLineBreakpointType.class);
|
super(JavaLineBreakpointType.class);
|
||||||
this.innerDebugger = innerDebugger;
|
this.innerDebugger = innerDebugger;
|
||||||
|
vfs = VirtualFileManager.getInstance();
|
||||||
|
fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint) {
|
public void registerBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint) {
|
||||||
Breakpoint innerBreakpoint = innerDebugger.createBreakpoint(breakpoint.getShortFilePath(),
|
VirtualFile virtualFile = vfs.findFileByUrl(breakpoint.getFileUrl());
|
||||||
breakpoint.getLine());
|
if (virtualFile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VirtualFile root = fileIndex.getSourceRootForFile(virtualFile);
|
||||||
|
if (root == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String path = relativePath(root, virtualFile);
|
||||||
|
if (path == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Breakpoint innerBreakpoint = innerDebugger.createBreakpoint(path, breakpoint.getLine());
|
||||||
breakpoint.putUserData(TeaVMDebugProcess.INNER_BREAKPOINT_KEY, innerBreakpoint);
|
breakpoint.putUserData(TeaVMDebugProcess.INNER_BREAKPOINT_KEY, innerBreakpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private String relativePath(@NotNull VirtualFile ancestor, @NotNull VirtualFile descendant) {
|
||||||
|
List<String> parts = new ArrayList<>();
|
||||||
|
while (!ancestor.equals(descendant)) {
|
||||||
|
if (descendant == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
parts.add(descendant.getName());
|
||||||
|
descendant = descendant.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.reverse(parts);
|
||||||
|
return StringUtil.join(parts, "/");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint,
|
public void unregisterBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint,
|
||||||
boolean temporary) {
|
boolean temporary) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user