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

LSP: Block call for workspace symbols until projects get opened #6183

Merged
merged 3 commits into from
Jul 14, 2023
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 @@ -47,6 +47,7 @@
import com.google.gson.JsonObject;
import java.util.prefs.Preferences;
import java.util.LinkedHashSet;
import java.util.WeakHashMap;
import java.util.concurrent.CompletionException;
import org.eclipse.lsp4j.CallHierarchyRegistrationOptions;
import org.eclipse.lsp4j.CodeActionKind;
Expand Down Expand Up @@ -99,6 +100,7 @@
import org.eclipse.lsp4j.services.TextDocumentService;
import org.eclipse.lsp4j.services.WorkspaceService;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.source.ClasspathInfo;
import org.netbeans.api.java.source.JavaSource;
Expand All @@ -124,6 +126,10 @@
import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
import org.netbeans.modules.java.lsp.server.progress.OperationContext;
import org.netbeans.modules.parsing.spi.indexing.Context;
import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
import org.netbeans.modules.parsing.spi.indexing.Indexable;
import org.netbeans.modules.progress.spi.InternalHandle;
import org.netbeans.spi.project.ActionProgress;
import org.netbeans.spi.project.ActionProvider;
Expand Down Expand Up @@ -167,6 +173,7 @@ public static NbLspServer launchServer(Pair<InputStream, OutputStream> io, LspSe
((LanguageClientAware) server).connect(remote);
msgProcessor.attachClient(server.client);
Future<Void> runningServer = serverLauncher.startListening();
LSPServerTelemetryFactory.getDefault().connect(server.client, runningServer);
return new NbLspServer(server, runningServer);
}

Expand Down Expand Up @@ -1185,4 +1192,90 @@ private static void hackNoReuseOfOutputsForAntProjects() {
}
}
}

public static class LSPServerTelemetryFactory extends CustomIndexerFactory {

private static LSPServerTelemetryFactory INSTANCE;

private final WeakHashMap<LanguageClient, Future<Void>> clients = new WeakHashMap<>();
private final CustomIndexer noOp = new CustomIndexer() {
@Override
protected void index(Iterable<? extends Indexable> files, Context context) {
}
};

@MimeRegistration(mimeType="", service=CustomIndexerFactory.class)
public static LSPServerTelemetryFactory getDefault() {
if (INSTANCE == null) {
INSTANCE = new LSPServerTelemetryFactory();
}
return INSTANCE;
}

private LSPServerTelemetryFactory() {
}

public synchronized void connect(LanguageClient client, Future<Void> future) {
clients.put(client, future);
}

@Override
public synchronized boolean scanStarted(Context context) {
Set<LanguageClient> toRemove = new HashSet<>();
for (Map.Entry<LanguageClient, Future<Void>> entry : clients.entrySet()) {
if (entry.getValue().isDone()) {
toRemove.add(entry.getKey());
} else {
entry.getKey().telemetryEvent("nbls.scanStarted");
}
}
for (LanguageClient lc : toRemove) {
clients.remove(lc);
}
return true;
}

@Override
public synchronized void scanFinished(Context context) {
Set<LanguageClient> toRemove = new HashSet<>();
for (Map.Entry<LanguageClient, Future<Void>> entry : clients.entrySet()) {
if (entry.getValue().isDone()) {
toRemove.add(entry.getKey());
} else {
entry.getKey().telemetryEvent("nbls.scanFinished");
}
}
for (LanguageClient lc : toRemove) {
clients.remove(lc);
}
}

@Override
public void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
}

@Override
public void filesDirty(Iterable<? extends Indexable> dirty, Context context) {
}

@Override
public String getIndexerName() {
return "LSPServerTelemetry";
}

@Override
public int getIndexVersion() {
return 1;
}

@Override
public CustomIndexer createIndexer() {
return noOp;
}

@Override
public boolean supportsEmbeddedIndexers() {
return false;
}
}
}
Loading