Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-5236 Java debugger didn't highlight line in decompiled class #5808

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public interface TextEditor extends EditorPartPresenter {
*/
TextPosition getCursorPosition();

/**
* Sets the new cursor position.
*/
void setCursorPosition(TextPosition textPosition);

/**
* Returns the cursor model for the editor.
* @return the cursor model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
*******************************************************************************/
package org.eclipse.che.ide.debug;

import com.google.gwt.user.client.Timer;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.debug.Breakpoint;
import org.eclipse.che.ide.api.debug.Breakpoint.Type;
import org.eclipse.che.ide.api.debug.BreakpointManager;
import org.eclipse.che.ide.api.debug.BreakpointManagerObservable;
import org.eclipse.che.ide.api.debug.BreakpointManagerObserver;
Expand All @@ -29,7 +29,10 @@
import org.eclipse.che.ide.api.editor.EditorOpenedEvent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
import org.eclipse.che.ide.api.event.project.DeleteProjectEvent;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.resources.ResourceChangedEvent;
Expand Down Expand Up @@ -231,6 +234,7 @@ public List<Breakpoint> getBreakpointList() {

private void setCurrentBreakpoint(String filePath, int lineNumber) {
deleteCurrentBreakpoint();
currentBreakpoint = new Breakpoint(Breakpoint.Type.CURRENT, lineNumber, filePath, null, true);

EditorPartPresenter editor = getEditorForFile(filePath);
if (editor != null) {
Expand All @@ -241,8 +245,6 @@ private void setCurrentBreakpoint(String filePath, int lineNumber) {
}

private void doSetCurrentBreakpoint(VirtualFile activeFile, int lineNumber) {
currentBreakpoint = new Breakpoint(Type.CURRENT, lineNumber, activeFile.getLocation().toString(), activeFile, true);

BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(activeFile.getLocation().toString());
if (breakpointRenderer != null) {
breakpointRenderer.setLineActive(lineNumber, true);
Expand Down Expand Up @@ -371,7 +373,7 @@ public void onWorkspaceReady(WorkspaceReadyEvent event) {
});

eventBus.addHandler(EditorOpenedEvent.TYPE, event -> onOpenEditor(event.getFile().getLocation().toString(), event.getEditor()));

eventBus.addHandler(FileContentUpdateEvent.TYPE, this::onFileContentUpdate);
eventBus.addHandler(DeleteProjectEvent.TYPE, event -> {
if (breakpoints.isEmpty()) {
return;
Expand Down Expand Up @@ -403,6 +405,45 @@ public void onWorkspaceReady(WorkspaceReadyEvent event) {
});
}

/**
* When source is downloaded then {@link FileContentUpdateEvent} will be generated.
* After that we have to wait {@link DocumentChangedEvent} to know when {@link TextEditor} will be updated.
*/
private void onFileContentUpdate(FileContentUpdateEvent event) {
String filePath = event.getFilePath();
if (currentBreakpoint != null && currentBreakpoint.getPath().equals(filePath)) {

EditorPartPresenter editor = getEditorForFile(filePath);
if (editor instanceof TextEditor) {

final TextEditor textEditor = (TextEditor)editor;
textEditor.getDocument()
.getDocumentHandle()
.getDocEventBus()
.addHandler(DocumentChangedEvent.TYPE, docChangedEvent -> {

String changedFilePath = docChangedEvent.getDocument().getDocument().getFile().getLocation().toString();
if (currentBreakpoint == null || !currentBreakpoint.getPath().equals(changedFilePath)) {
return;
}

BreakpointRenderer breakpointRenderer = getBreakpointRendererForEditor(editor);
if (breakpointRenderer != null) {
breakpointRenderer.setLineActive(currentBreakpoint.getLineNumber(), false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line really necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, can be omitted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid multiple annotations it is better to remove active line at first.

breakpointRenderer.setLineActive(currentBreakpoint.getLineNumber(), true);

new Timer() {
@Override
public void run() {
textEditor.setCursorPosition(new TextPosition(currentBreakpoint.getLineNumber() + 1, 0));
}
}.schedule(300);
}
});
}
}
}

/**
* @param pathToFind
* examples: "/test-spring/", "/test-spring/src/", "/test-spring/src/main/java/Test.java"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ public TextPosition getCursorPosition() {
return getDocument().getCursorPosition();
}

@Override
public void setCursorPosition(TextPosition textPosition) {
if (document != null) {
document.setCursorPosition(textPosition);
}
}

@Override
public int getCursorOffset() {
final TextPosition textPosition = getDocument().getCursorPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,35 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) {
}

private void openCurrentFile() {
// Handle the situation when resource isn't found in the workspace
// It means that it is impossible to open it.
if (currentLocation.getResourcePath() == null) {
//todo we need add possibility to handle few files
try {
activeFileHandler.openFile(currentLocation,
new AsyncCallback<VirtualFile>() {
@Override
public void onFailure(Throwable caught) {
for (DebuggerObserver observer : observers) {
observer.onBreakpointStopped(currentLocation.getTarget(),
currentLocation.getTarget(),
currentLocation.getLineNumber());
}
}

@Override
public void onSuccess(VirtualFile result) {
for (DebuggerObserver observer : observers) {
observer.onBreakpointStopped(result.getLocation().toString(),
currentLocation.getTarget(),
currentLocation.getLineNumber());
}
}
});
} catch (Exception e) {
for (DebuggerObserver observer : observers) {
observer.onBreakpointStopped(currentLocation.getTarget(),
currentLocation.getTarget(),
currentLocation.getLineNumber());
}

return;
}

//todo we need add possibility to handle few files
activeFileHandler.openFile(currentLocation,
new AsyncCallback<VirtualFile>() {
@Override
public void onFailure(Throwable caught) {
for (DebuggerObserver observer : observers) {
observer.onBreakpointStopped(currentLocation.getTarget(),
currentLocation.getTarget(),
currentLocation.getLineNumber());
}
}

@Override
public void onSuccess(VirtualFile result) {
for (DebuggerObserver observer : observers) {
observer.onBreakpointStopped(result.getLocation().toString(),
currentLocation.getTarget(),
currentLocation.getLineNumber());
}
}
});
}

/**
Expand Down
Loading