Fix a race condition in quickfix/moveCursor
This commit is contained in:
@@ -291,7 +291,6 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
|
||||
System.err.println("moveCursor request received: "+cursorMovement);
|
||||
Utils.getActiveEditors().forEach(_editor -> {
|
||||
try {
|
||||
if (_editor instanceof AbstractTextEditor) {
|
||||
@@ -300,26 +299,11 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
|
||||
if (doc!=null) {
|
||||
URI uri = Utils.findDocUri(doc);
|
||||
if (cursorMovement.getUri().equals(uri.toString())) {
|
||||
new UIJob("Move cursor") {
|
||||
{
|
||||
setSystem(true);
|
||||
}
|
||||
@Override
|
||||
public IStatus runInUIThread(IProgressMonitor arg0) {
|
||||
try {
|
||||
org.eclipse.lsp4j.Position pos = cursorMovement.getPosition();
|
||||
//Careful, it seems like the computation of offset only works correctly
|
||||
// when called from UIJob. Otherwise it is likely to be using stale data
|
||||
// not yet accounting for the most recent edits that may have been applied
|
||||
// to the document.
|
||||
int offset = LSPEclipseUtils.toOffset(pos, doc);
|
||||
editor.getSelectionProvider().setSelection(new TextSelection(offset, 0));
|
||||
} catch (Exception e) {
|
||||
LanguageServerCommonsActivator.logError(e, "sts/moveCursor failed");
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}.schedule();
|
||||
org.eclipse.lsp4j.Position pos = cursorMovement.getPosition();
|
||||
int offset = LSPEclipseUtils.toOffset(pos, doc);
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
editor.getSelectionProvider().setSelection(new TextSelection(offset, 0));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,10 +199,14 @@ public final class SimpleLanguageServer implements Sts4LanguageServer, LanguageC
|
||||
return quickfixResolve(quickfixParams)
|
||||
.flatMap((QuickfixEdit edit) -> {
|
||||
Mono<ApplyWorkspaceEditResponse> applyEdit = Mono.fromFuture(client.applyEdit(new ApplyWorkspaceEditParams(edit.workspaceEdit)));
|
||||
Mono<Object> moveCursor = edit.cursorMovement==null
|
||||
? Mono.just(new ApplyWorkspaceEditResponse(true))
|
||||
: Mono.fromFuture(client.moveCursor(edit.cursorMovement));
|
||||
return applyEdit.flatMap(r -> r.isApplied() ? moveCursor : Mono.just(new ApplyWorkspaceEditResponse(true)));
|
||||
return applyEdit.flatMap(r -> {
|
||||
if (r.isApplied()) {
|
||||
if (edit.cursorMovement!=null) {
|
||||
return Mono.fromFuture(client.moveCursor(edit.cursorMovement));
|
||||
}
|
||||
}
|
||||
return Mono.just(r);
|
||||
});
|
||||
})
|
||||
.toFuture();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user