Skip to content

Commit a768cee

Browse files
committed
Attempting to stabilize the tests.
1 parent 61a31c3 commit a768cee

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/RunOnceFactory.java

+37-14
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import java.util.Collections;
2323
import java.util.LinkedList;
2424
import java.util.List;
25+
import java.util.concurrent.atomic.AtomicReference;
2526
import java.util.logging.Level;
2627
import java.util.logging.Logger;
2728
import org.netbeans.api.java.source.CancellableTask;
2829
import org.netbeans.api.java.source.CompilationInfo;
2930
import org.netbeans.api.java.source.JavaSource.Phase;
3031
import org.netbeans.api.java.source.JavaSource.Priority;
3132
import org.netbeans.api.java.source.JavaSourceTaskFactory;
33+
import org.netbeans.modules.parsing.spi.TaskIndexingMode;
3234
import org.openide.filesystems.FileObject;
3335
import org.openide.filesystems.FileUtil;
3436
import org.openide.util.Lookup;
@@ -49,18 +51,34 @@ public class RunOnceFactory extends JavaSourceTaskFactory {
4951
private CancellableTask<CompilationInfo> task;
5052

5153
public RunOnceFactory() {
52-
super(Phase.RESOLVED, Priority.BELOW_NORMAL);
54+
super(Phase.RESOLVED, Priority.BELOW_NORMAL, TaskIndexingMode.ALLOWED_DURING_SCAN);
5355
// INSTANCE = this;
5456
}
5557

56-
protected synchronized CancellableTask<CompilationInfo> createTask(FileObject file) {
57-
final CancellableTask<CompilationInfo> task = this.task;
58+
protected CancellableTask<CompilationInfo> createTask(FileObject file) {
5859
return new CancellableTask<CompilationInfo>() {
60+
private final AtomicReference<CancellableTask<CompilationInfo>> currentTask =
61+
new AtomicReference<>();
62+
5963
public void cancel() {
60-
task.cancel();
64+
CancellableTask<CompilationInfo> task = currentTask.get();
65+
66+
if (task != null) {
67+
task.cancel();
68+
}
6169
}
6270
public void run(CompilationInfo parameter) throws Exception {
71+
CancellableTask<CompilationInfo> task;
72+
73+
synchronized (RunOnceFactory.this) {
74+
task = RunOnceFactory.this.task;
75+
}
76+
77+
currentTask.set(task);
78+
6379
task.run(parameter);
80+
81+
currentTask.set(null);
6482
next();
6583
}
6684
};
@@ -87,25 +105,30 @@ private synchronized void addImpl(FileObject file, CancellableTask<CompilationIn
87105
private synchronized void next() {
88106
LOG.fine("next, phase 1");
89107

90-
if (currentFile != null) {
91-
currentFile = null;
92-
task = null;
93-
fileObjectsChanged();
94-
}
95-
96-
LOG.fine("next, phase 1 done");
108+
if (work.isEmpty()) {
109+
if (currentFile != null) {
110+
LOG.fine("clearing current file");
111+
currentFile = null;
112+
task = null;
113+
fileObjectsChanged();
114+
}
97115

98-
if (work.isEmpty())
116+
LOG.fine("work is empty");
99117
return ;
118+
}
100119

101120
LOG.fine("next, phase 2");
102121

103122
Pair<FileObject, CancellableTask<CompilationInfo>> p = work.remove(0);
104123

105-
currentFile = p.first();
106124
task = p.second();
107125

108-
fileObjectsChanged();
126+
if (currentFile == p.first()) {
127+
reschedule(currentFile);
128+
} else {
129+
currentFile = p.first();
130+
fileObjectsChanged();
131+
}
109132

110133
LOG.fine("next, phase 2 done");
111134
}

java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ private void runDiagnosticTasks(String uri, boolean force) {
19501950
}
19511951

19521952
private List<Diagnostic> doRunComputeDiagsOnBackground(String uri, ErrorProvider.Kind kind, long originalVersion, AtomicReference<Document> docHolder) {
1953-
return computeCancallablyOnBackground(uri, new CancellableTask<List<Diagnostic>>() {
1953+
return computeCancellablyOnBackground(uri, new CancellableTask<List<Diagnostic>>() {
19541954
private final AtomicBoolean cancelled = new AtomicBoolean();
19551955
private final AtomicReference<Runnable> cancelCallback = new AtomicReference<>();
19561956
@Override
@@ -2389,7 +2389,7 @@ private static void reportNotificationDone(String s, Object parameter) {
23892389
@Override
23902390
public CompletableFuture<SemanticTokens> semanticTokensFull(SemanticTokensParams params) {
23912391
String uri = params.getTextDocument().getUri();
2392-
return computeCancallablyOnBackground(uri, new CancellableTask<SemanticTokens>() {
2392+
return computeCancellablyOnBackground(uri, new CancellableTask<SemanticTokens>() {
23932393
private final AtomicBoolean cancel = new AtomicBoolean();
23942394
private final AtomicReference<SemanticHighlighterBase> computeTask = new AtomicReference<>();
23952395
@Override
@@ -2684,7 +2684,8 @@ protected CallHierarchyOutgoingCall createResultItem(CallHierarchyItem item, Lis
26842684
}
26852685

26862686
private static final RequestProcessor DELAYED_RESCHEDULE = new RequestProcessor(TextDocumentServiceImpl.class.getName(), 1, false, false);
2687-
private <T> CompletableFuture<T> computeCancallablyOnBackground(String uri, CancellableTask<T> task, T defaultValue, int priority) {
2687+
private static final RequestProcessor EDITOR_BRACKGROUND = new RequestProcessor(TextDocumentServiceImpl.class.getName() + "-editor-background", 1, false, false);
2688+
private <T> CompletableFuture<T> computeCancellablyOnBackground(String uri, CancellableTask<T> task, T defaultValue, int priority) {
26882689
CompletableFuture<T> result = new CompletableFuture<T>() {
26892690
@Override
26902691
public boolean cancel(boolean mayInterruptIfRunning) {
@@ -2722,7 +2723,7 @@ public void run(CompilationInfo parameter) throws Exception {
27222723
}
27232724
});
27242725
} else {
2725-
BACKGROUND_TASKS.post(() -> {
2726+
EDITOR_BRACKGROUND.post(() -> {
27262727
result.complete(task.compute());
27272728
});
27282729
}

0 commit comments

Comments
 (0)