mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Add proper breakpoint positioning in IDEA
This commit is contained in:
parent
40e06a573c
commit
98efadc6fd
|
@ -93,7 +93,7 @@ class TeaVMBuild {
|
|||
this.assistant = assistant;
|
||||
}
|
||||
|
||||
boolean perform(JpsModule module, ModuleBuildTarget target) throws IOException {
|
||||
boolean perform(JpsModule module, ModuleBuildTarget target) throws IOException {
|
||||
storage = context.getProjectDescriptor().dataManager.getStorage(target, storageProvider);
|
||||
|
||||
TeaVMJpsConfiguration config = TeaVMJpsConfiguration.get(module);
|
||||
|
@ -114,10 +114,13 @@ class TeaVMBuild {
|
|||
tool.setProgressListener(createProgressListener(context));
|
||||
tool.setLog(new EmptyTeaVMToolLog());
|
||||
tool.setMainClass(config.getMainClass());
|
||||
tool.setSourceMapsFileGenerated(config.isSourceMapsFileGenerated());
|
||||
tool.setTargetDirectory(new File(config.getTargetDirectory()));
|
||||
tool.setClassLoader(buildClassLoader());
|
||||
|
||||
tool.setSourceMapsFileGenerated(config.isSourceMapsFileGenerated());
|
||||
tool.setDebugInformationGenerated(config.isSourceMapsFileGenerated());
|
||||
tool.setSourceFilesCopied(config.isSourceFilesCopied());
|
||||
|
||||
tool.setMinifying(config.isMinifying());
|
||||
for (SourceFileProvider fileProvider : sourceFileProviders) {
|
||||
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() {
|
||||
|
|
|
@ -16,29 +16,70 @@
|
|||
package org.teavm.idea.debug;
|
||||
|
||||
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.XLineBreakpoint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.java.debugger.breakpoints.properties.JavaLineBreakpointProperties;
|
||||
import org.teavm.debugging.Breakpoint;
|
||||
import org.teavm.debugging.Debugger;
|
||||
|
||||
public class TeaVMLineBreakpointHandler extends XBreakpointHandler<XLineBreakpoint<JavaLineBreakpointProperties>> {
|
||||
private Debugger innerDebugger;
|
||||
private VirtualFileManager vfs;
|
||||
private ProjectFileIndex fileIndex;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public TeaVMLineBreakpointHandler(Debugger innerDebugger) {
|
||||
public TeaVMLineBreakpointHandler(Project project, Debugger innerDebugger) {
|
||||
super(JavaLineBreakpointType.class);
|
||||
this.innerDebugger = innerDebugger;
|
||||
vfs = VirtualFileManager.getInstance();
|
||||
fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint) {
|
||||
Breakpoint innerBreakpoint = innerDebugger.createBreakpoint(breakpoint.getShortFilePath(),
|
||||
breakpoint.getLine());
|
||||
VirtualFile virtualFile = vfs.findFileByUrl(breakpoint.getFileUrl());
|
||||
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);
|
||||
}
|
||||
|
||||
@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
|
||||
public void unregisterBreakpoint(@NotNull XLineBreakpoint<JavaLineBreakpointProperties> breakpoint,
|
||||
boolean temporary) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user