|
|
|
@@ -9,6 +9,8 @@ import org.eclipse.lsp4j.services.*;
|
|
|
|
|
import p.studio.api.automation.*;
|
|
|
|
|
import p.studio.api.project.ProjectCatalog;
|
|
|
|
|
import p.studio.core.language.LanguageQueryPort;
|
|
|
|
|
import p.studio.core.language.LanguageQueryExecution;
|
|
|
|
|
import p.studio.utilities.json.*;
|
|
|
|
|
import p.studio.lsp.api.LspServerLifecycle;
|
|
|
|
|
import p.studio.lsp.services.protocol.ExternalSourceLanguageServer;
|
|
|
|
|
import org.eclipse.lsp4j.jsonrpc.Launcher;
|
|
|
|
@@ -41,7 +43,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
|
|
|
|
|
@Override public void endTask(TaskIdentity task) {
|
|
|
|
|
items.remove(task);
|
|
|
|
|
final var state = externalTasks.remove(task);
|
|
|
|
|
final var state = externalTasks.get(task);
|
|
|
|
|
if (state == null) return;
|
|
|
|
|
final var workers = Executors.newCachedThreadPool();
|
|
|
|
|
try (var socket = new Socket()) {
|
|
|
|
@@ -60,13 +62,15 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
init.setInitializationOptions(Map.of("prometeuExternalConsumerId", state.consumer()));
|
|
|
|
|
server.initialize(init).get(2, TimeUnit.SECONDS);
|
|
|
|
|
server.releaseExternalSource(new ExternalSourceLanguageServer.Request(state.consumer(), null)).get(2, TimeUnit.SECONDS);
|
|
|
|
|
externalTasks.remove(task, state);
|
|
|
|
|
} finally { listening.cancel(true); }
|
|
|
|
|
} catch (Exception failure) {
|
|
|
|
|
// A closed project host has already released its registry. Other cleanup
|
|
|
|
|
// failures are surfaced instead of silently reporting a successful task end.
|
|
|
|
|
if (lifecycle.endpoint(state.binding()).isPresent())
|
|
|
|
|
throw new IllegalStateException("Could not release task external sources", failure);
|
|
|
|
|
} finally { workers.shutdownNow(); }
|
|
|
|
|
externalTasks.remove(task, state);
|
|
|
|
|
} finally { new LanguageQueryExecution("endTask", 10_000, 2_000).finishWorkers(workers); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class QuietClient implements LanguageClient {
|
|
|
|
@@ -78,6 +82,24 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters) throws Exception {
|
|
|
|
|
return query(task, operation, parameters, new LanguageQueryExecution(operation, 10_000, 2_000));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters,
|
|
|
|
|
LanguageQueryExecution execution) throws Exception {
|
|
|
|
|
try {
|
|
|
|
|
var result = performQuery(task, operation, parameters, execution);
|
|
|
|
|
if (execution.hasFailure()) throw execution.exception(AutomationFailure.Code.LANGUAGE_QUERY_CLEANUP_FAILED, "Language query cleanup failed", true);
|
|
|
|
|
return result;
|
|
|
|
|
} catch (IllegalArgumentException | ControlDeniedException failure) { throw failure; }
|
|
|
|
|
catch (Exception failure) {
|
|
|
|
|
recordFailure(execution, failure);
|
|
|
|
|
throw execution.exception(AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE, "Language query failed", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> performQuery(TaskIdentity task, String operation, Map<String, Object> parameters,
|
|
|
|
|
LanguageQueryExecution execution) throws Exception {
|
|
|
|
|
if (!OPERATIONS.contains(operation)) throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, "Unsupported language operation: " + operation);
|
|
|
|
|
var context = knowledge.context(task.projectRoot());
|
|
|
|
|
var primary = context.languages().stream().filter(ProjectKnowledge.Language::primary).findFirst().orElseThrow();
|
|
|
|
@@ -85,7 +107,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
throw failure(AutomationFailure.Code.UNSUPPORTED_LANGUAGE, "Project language has no available LSP");
|
|
|
|
|
var project = projects.openProject(context.projectRoot());
|
|
|
|
|
var binding = LspLifecycleAdapter.context(project);
|
|
|
|
|
var endpoint = lifecycle.endpoint(binding).orElseThrow(() -> failure(AutomationFailure.Code.INFRASTRUCTURE_FAILURE, "Project LSP is not running; reopen the project if its language changed"));
|
|
|
|
|
var endpoint = lifecycle.endpoint(binding).orElseThrow(() -> failure(AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE, "Project LSP is not running; reopen the project if its language changed"));
|
|
|
|
|
var params = mapper.valueToTree(parameters);
|
|
|
|
|
CallHierarchyItem item = null;
|
|
|
|
|
String uri = null;
|
|
|
|
@@ -116,11 +138,14 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
}
|
|
|
|
|
uri = document.toUri().toString();
|
|
|
|
|
}
|
|
|
|
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
|
|
|
|
|
long deadline = execution.deadlineNanos();
|
|
|
|
|
if (System.nanoTime() >= deadline) throw new TimeoutException("Language query admission budget expired");
|
|
|
|
|
var workers = Executors.newCachedThreadPool(r -> { var thread = new Thread(r, "studio-automation-lsp"); thread.setDaemon(true); return thread; });
|
|
|
|
|
try (var socket = new Socket()) {
|
|
|
|
|
if (!InetAddress.getByName(endpoint.host()).isLoopbackAddress()) throw failure(AutomationFailure.Code.INFRASTRUCTURE_FAILURE, "Project LSP endpoint is not local");
|
|
|
|
|
socket.connect(new InetSocketAddress(endpoint.host(), endpoint.port()), 2000);
|
|
|
|
|
execution.own(() -> { try { socket.close(); } catch (java.io.IOException ignored) {} });
|
|
|
|
|
execution.own(workers::shutdownNow);
|
|
|
|
|
if (!InetAddress.getByName(endpoint.host()).isLoopbackAddress()) throw failure(AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE, "Project LSP endpoint is not local");
|
|
|
|
|
socket.connect(new InetSocketAddress(endpoint.host(), endpoint.port()), (int)Math.max(1, Math.min(2000, TimeUnit.NANOSECONDS.toMillis(deadline - System.nanoTime()))));
|
|
|
|
|
var diagnostics = new CompletableFuture<List<Diagnostic>>();
|
|
|
|
|
String expectedUri = uri;
|
|
|
|
|
LanguageClient client = new LanguageClient() {
|
|
|
|
@@ -137,6 +162,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
.setRemoteInterface(ExternalSourceLanguageServer.class).setInput(socket.getInputStream())
|
|
|
|
|
.setOutput(socket.getOutputStream()).setExecutorService(workers).create();
|
|
|
|
|
var listening = launcher.startListening();
|
|
|
|
|
execution.own(() -> listening.cancel(true));
|
|
|
|
|
final var server = launcher.getRemoteProxy();
|
|
|
|
|
final var acquired = new HashSet<String>();
|
|
|
|
|
boolean succeeded = false;
|
|
|
|
@@ -144,12 +170,14 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
var initialize = new InitializeParams();
|
|
|
|
|
initialize.setRootUri(binding.projectRoot().toUri().toString());
|
|
|
|
|
initialize.setCapabilities(new ClientCapabilities());
|
|
|
|
|
initialize.getCapabilities().setExperimental(Map.of("prometeuExternalSources", true));
|
|
|
|
|
initialize.getCapabilities().setExperimental(Map.of("prometeuExternalSources", true,
|
|
|
|
|
"prometeuDiagnosticAnalysis", Map.of("version", 1)));
|
|
|
|
|
final var previous = externalTasks.get(task);
|
|
|
|
|
initialize.setInitializationOptions(previous == null
|
|
|
|
|
? Map.of("prometeuExternalPersistentConsumer", true)
|
|
|
|
|
: Map.of("prometeuExternalConsumerId", previous.consumer(), "prometeuExternalPersistentConsumer", true));
|
|
|
|
|
var capabilities = await(server.initialize(initialize), deadline).getCapabilities();
|
|
|
|
|
execution.method("initialize");
|
|
|
|
|
var capabilities = await(server.initialize(initialize), deadline, execution).getCapabilities();
|
|
|
|
|
final var experimental = gson.toJsonTree(capabilities.getExperimental());
|
|
|
|
|
if (experimental.isJsonObject() && experimental.getAsJsonObject().has("prometeuExternalConsumerId")) {
|
|
|
|
|
final String consumer = experimental.getAsJsonObject().get("prometeuExternalConsumerId").getAsString();
|
|
|
|
@@ -158,52 +186,69 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
server.initialized(new InitializedParams());
|
|
|
|
|
requireCapability(operation, capabilities);
|
|
|
|
|
List<Diagnostic> currentDiagnostics = List.of();
|
|
|
|
|
Map<String, Object> analysis = Map.of();
|
|
|
|
|
var rich = experimental.isJsonObject() ? experimental.getAsJsonObject().get("prometeuDiagnosticAnalysis") : null;
|
|
|
|
|
boolean richAnalysis = rich != null && rich.isJsonObject() && rich.getAsJsonObject().has("version")
|
|
|
|
|
&& rich.getAsJsonObject().get("version").getAsInt() == 1;
|
|
|
|
|
String digest = source == null ? null : sha256(source);
|
|
|
|
|
if (document != null) {
|
|
|
|
|
// Fresh client overlay contains exactly the saved UTF-8 file. Wait for analysis before querying.
|
|
|
|
|
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, primary.id(), 1, source)));
|
|
|
|
|
currentDiagnostics = await(diagnostics, deadline);
|
|
|
|
|
if (richAnalysis) {
|
|
|
|
|
execution.method("prometeu/documentAnalysis");
|
|
|
|
|
var retained = await(server.documentAnalysis(new ExternalSourceLanguageServer.DiagnosticAnalysisRequest(
|
|
|
|
|
new VersionedTextDocumentIdentifier(uri, 1), digest)), deadline, execution);
|
|
|
|
|
analysis = mapper.convertValue(mapper.readTree(gson.toJson(retained)), Map.class);
|
|
|
|
|
}
|
|
|
|
|
currentDiagnostics = await(diagnostics, deadline, execution);
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> externalRevision = Map.of();
|
|
|
|
|
if (external) {
|
|
|
|
|
final var request = new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri);
|
|
|
|
|
source = await(server.revalidateExternalSource(request), deadline).text();
|
|
|
|
|
var content = await(server.revalidateExternalSource(request), deadline, execution);
|
|
|
|
|
source = content.text();
|
|
|
|
|
externalRevision = mapper.convertValue(mapper.readTree(gson.toJson(content)), Map.class);
|
|
|
|
|
externalRevision = new LinkedHashMap<>(externalRevision);
|
|
|
|
|
externalRevision.remove("text");
|
|
|
|
|
if (source.getBytes(java.nio.charset.StandardCharsets.UTF_8).length > 4 * 1024 * 1024)
|
|
|
|
|
throw failure(AutomationFailure.Code.LIMIT_EXCEEDED, "External source exceeds 4 MiB");
|
|
|
|
|
}
|
|
|
|
|
execution.method(operation);
|
|
|
|
|
var text = server.getTextDocumentService();
|
|
|
|
|
var id = uri == null ? null : new TextDocumentIdentifier(uri);
|
|
|
|
|
Object result = switch (operation) {
|
|
|
|
|
case "readExternalSource" -> await(server.readExternalSource(
|
|
|
|
|
new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri)), deadline);
|
|
|
|
|
new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri)), deadline, execution);
|
|
|
|
|
case "diagnostics" -> currentDiagnostics;
|
|
|
|
|
case "hover" -> await(text.hover(new HoverParams(id, position(params.path("position"), source))), deadline);
|
|
|
|
|
case "completion" -> await(text.completion(new CompletionParams(id, position(params.path("position"), source))), deadline);
|
|
|
|
|
case "signatureHelp" -> await(text.signatureHelp(new SignatureHelpParams(id, position(params.path("position"), source))), deadline);
|
|
|
|
|
case "definition" -> await(text.definition(new DefinitionParams(id, position(params.path("position"), source))), deadline);
|
|
|
|
|
case "references" -> await(text.references(new ReferenceParams(id, position(params.path("position"), source), new ReferenceContext(params.path("includeDeclaration").asBoolean(false)))), deadline);
|
|
|
|
|
case "documentSymbols" -> await(text.documentSymbol(new DocumentSymbolParams(id)), deadline);
|
|
|
|
|
case "workspaceSymbols" -> await(server.getWorkspaceService().symbol(new WorkspaceSymbolParams(params.path("query").asText(""))), deadline);
|
|
|
|
|
case "prepareRename" -> await(text.prepareRename(new PrepareRenameParams(id, position(params.path("position"), source))), deadline);
|
|
|
|
|
case "hover" -> await(text.hover(new HoverParams(id, position(params.path("position"), source))), deadline, execution);
|
|
|
|
|
case "completion" -> await(text.completion(new CompletionParams(id, position(params.path("position"), source))), deadline, execution);
|
|
|
|
|
case "signatureHelp" -> await(text.signatureHelp(new SignatureHelpParams(id, position(params.path("position"), source))), deadline, execution);
|
|
|
|
|
case "definition" -> await(text.definition(new DefinitionParams(id, position(params.path("position"), source))), deadline, execution);
|
|
|
|
|
case "references" -> await(text.references(new ReferenceParams(id, position(params.path("position"), source), new ReferenceContext(params.path("includeDeclaration").asBoolean(false)))), deadline, execution);
|
|
|
|
|
case "documentSymbols" -> await(text.documentSymbol(new DocumentSymbolParams(id)), deadline, execution);
|
|
|
|
|
case "workspaceSymbols" -> await(server.getWorkspaceService().symbol(new WorkspaceSymbolParams(params.path("query").asText(""))), deadline, execution);
|
|
|
|
|
case "prepareRename" -> await(text.prepareRename(new PrepareRenameParams(id, position(params.path("position"), source))), deadline, execution);
|
|
|
|
|
case "rename" -> {
|
|
|
|
|
String name = params.path("newName").asText("");
|
|
|
|
|
if (name.isBlank()) throw new IllegalArgumentException("newName is required");
|
|
|
|
|
yield await(text.rename(new RenameParams(id, position(params.path("position"), source), name)), deadline);
|
|
|
|
|
yield await(text.rename(new RenameParams(id, position(params.path("position"), source), name)), deadline, execution);
|
|
|
|
|
}
|
|
|
|
|
case "formatting" -> await(text.formatting(new DocumentFormattingParams(id, new FormattingOptions(4, true))), deadline);
|
|
|
|
|
case "formatting" -> await(text.formatting(new DocumentFormattingParams(id, new FormattingOptions(4, true))), deadline, execution);
|
|
|
|
|
case "codeActions" -> await(text.codeAction(new CodeActionParams(id,
|
|
|
|
|
range(params.path("range"), source),
|
|
|
|
|
new CodeActionContext(currentDiagnostics))), deadline);
|
|
|
|
|
case "documentLinks" -> await(text.documentLink(new DocumentLinkParams(id)), deadline);
|
|
|
|
|
case "foldingRanges" -> await(text.foldingRange(new FoldingRangeRequestParams(id)), deadline);
|
|
|
|
|
new CodeActionContext(currentDiagnostics))), deadline, execution);
|
|
|
|
|
case "documentLinks" -> await(text.documentLink(new DocumentLinkParams(id)), deadline, execution);
|
|
|
|
|
case "foldingRanges" -> await(text.foldingRange(new FoldingRangeRequestParams(id)), deadline, execution);
|
|
|
|
|
case "selectionRanges" -> {
|
|
|
|
|
if (!params.path("positions").isArray() || params.path("positions").isEmpty()) throw new IllegalArgumentException("positions are required");
|
|
|
|
|
var positions = new ArrayList<Position>();
|
|
|
|
|
for (var p : params.path("positions")) positions.add(position(p, source));
|
|
|
|
|
yield await(text.selectionRange(new SelectionRangeParams(id, positions)), deadline);
|
|
|
|
|
yield await(text.selectionRange(new SelectionRangeParams(id, positions)), deadline, execution);
|
|
|
|
|
}
|
|
|
|
|
case "prepareCallHierarchy" -> await(text.prepareCallHierarchy(new CallHierarchyPrepareParams(id, position(params.path("position"), source))), deadline);
|
|
|
|
|
case "incomingCalls" -> await(text.callHierarchyIncomingCalls(new CallHierarchyIncomingCallsParams(item)), deadline);
|
|
|
|
|
case "outgoingCalls" -> await(text.callHierarchyOutgoingCalls(new CallHierarchyOutgoingCallsParams(item)), deadline);
|
|
|
|
|
case "semanticTokens" -> await(text.semanticTokensFull(new SemanticTokensParams(id)), deadline);
|
|
|
|
|
case "prepareCallHierarchy" -> await(text.prepareCallHierarchy(new CallHierarchyPrepareParams(id, position(params.path("position"), source))), deadline, execution);
|
|
|
|
|
case "incomingCalls" -> await(text.callHierarchyIncomingCalls(new CallHierarchyIncomingCallsParams(item)), deadline, execution);
|
|
|
|
|
case "outgoingCalls" -> await(text.callHierarchyOutgoingCalls(new CallHierarchyOutgoingCallsParams(item)), deadline, execution);
|
|
|
|
|
case "semanticTokens" -> await(text.semanticTokensFull(new SemanticTokensParams(id)), deadline, execution);
|
|
|
|
|
default -> throw new IllegalArgumentException("Unsupported operation");
|
|
|
|
|
};
|
|
|
|
|
var wire = mapper.readTree(gson.toJson(result));
|
|
|
|
@@ -215,7 +260,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
acquired.removeAll(externalTasks.get(task).uris());
|
|
|
|
|
for (String externalUri : returned) {
|
|
|
|
|
await(server.retainExternalSource(new ExternalSourceLanguageServer.Request(
|
|
|
|
|
externalTasks.get(task).consumer(), externalUri)), deadline);
|
|
|
|
|
externalTasks.get(task).consumer(), externalUri)), deadline, execution);
|
|
|
|
|
externalTasks.get(task).uris().add(externalUri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -229,9 +274,23 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
if (operation.equals("prepareCallHierarchy") || operation.equals("incomingCalls") || operation.equals("outgoingCalls")) addItemIds(task, wire);
|
|
|
|
|
var output = new LinkedHashMap<String, Object>();
|
|
|
|
|
output.put("operation", operation); output.put("result", mapper.convertValue(wire, Object.class));
|
|
|
|
|
if (document != null && !richAnalysis) {
|
|
|
|
|
limitations.add("ANALYSIS_DETAILS_UNAVAILABLE");
|
|
|
|
|
analysis = ImmutableJson.fields("analysisId", null, "issues", List.of(), "summary",
|
|
|
|
|
DiagnosticPayloads.legacySummary("document"));
|
|
|
|
|
}
|
|
|
|
|
output.put("limitations", limitations);
|
|
|
|
|
output.put("analysis", analysis);
|
|
|
|
|
output.put("context", ImmutableJson.fields("projectRoot", context.projectRoot().toString(),
|
|
|
|
|
"taskId", task.value(), "clientRequestId", null, "buildId", null, "queryId", execution.queryId(), "analysisId", analysis.get("analysisId"),
|
|
|
|
|
"document", document == null ? null : ImmutableJson.fields("uri", uri, "version", 1, "sha256", digest),
|
|
|
|
|
"inputs", analysis.getOrDefault("inputs", List.of()), "externalRevision", externalRevision,
|
|
|
|
|
"inputCoverage", "partial", "configuration", analysis.getOrDefault("configuration", Map.of())));
|
|
|
|
|
succeeded = true;
|
|
|
|
|
return Collections.unmodifiableMap(output);
|
|
|
|
|
} catch (Exception failure) {
|
|
|
|
|
recordFailure(execution, failure);
|
|
|
|
|
throw failure;
|
|
|
|
|
} finally {
|
|
|
|
|
if (!succeeded && !acquired.isEmpty() && externalTasks.containsKey(task)) {
|
|
|
|
|
final var state = externalTasks.get(task);
|
|
|
|
@@ -242,11 +301,39 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
server.releaseExternalSource(new ExternalSourceLanguageServer.Request(state.consumer(), acquiredUri))
|
|
|
|
|
.get(500, TimeUnit.MILLISECONDS);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception cleanupFailure) {
|
|
|
|
|
execution.record(AutomationFailure.Code.LANGUAGE_QUERY_CLEANUP_FAILED, "Could not release query external sources", Map.of());
|
|
|
|
|
} finally { if (interrupted) Thread.currentThread().interrupt(); }
|
|
|
|
|
}
|
|
|
|
|
listening.cancel(true);
|
|
|
|
|
}
|
|
|
|
|
} finally { workers.shutdownNow(); }
|
|
|
|
|
} finally { execution.finishWorkers(workers); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String sha256(String text) throws java.security.NoSuchAlgorithmException {
|
|
|
|
|
return HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256")
|
|
|
|
|
.digest(text.getBytes(java.nio.charset.StandardCharsets.UTF_8)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void recordFailure(LanguageQueryExecution execution, Exception failure) {
|
|
|
|
|
if (failure instanceof AutomationException domain) { execution.record(domain.failure()); return; }
|
|
|
|
|
if (failure instanceof IllegalArgumentException || failure instanceof ControlDeniedException) return;
|
|
|
|
|
var cause = failure instanceof ExecutionException && failure.getCause() != null ? failure.getCause() : failure;
|
|
|
|
|
AutomationFailure.Code code;
|
|
|
|
|
Map<String, Object> details = Map.of();
|
|
|
|
|
if (cause instanceof TimeoutException || cause instanceof SocketTimeoutException) code = AutomationFailure.Code.LANGUAGE_QUERY_TIMEOUT;
|
|
|
|
|
else if (cause instanceof InterruptedException || cause instanceof CancellationException) code = AutomationFailure.Code.LANGUAGE_QUERY_CANCELLED;
|
|
|
|
|
else if (cause instanceof ConnectException || cause instanceof SocketException) code = AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE;
|
|
|
|
|
else if (cause instanceof org.eclipse.lsp4j.jsonrpc.ResponseErrorException response) {
|
|
|
|
|
int rpc = response.getResponseError().getCode();
|
|
|
|
|
details = ImmutableJson.fields("protocolCode", rpc, "reason", rpc == -32020 ? "ANALYSIS_REVISION_MISMATCH" : rpc == -32021 ? "ANALYSIS_UNAVAILABLE" : null);
|
|
|
|
|
code = rpc == -32020 ? AutomationFailure.Code.LANGUAGE_QUERY_REVISION_MISMATCH
|
|
|
|
|
: rpc == -32021 || rpc == -32603 ? AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE
|
|
|
|
|
: AutomationFailure.Code.LANGUAGE_QUERY_PROTOCOL_FAILURE;
|
|
|
|
|
} else if (cause instanceof org.eclipse.lsp4j.jsonrpc.JsonRpcException || cause instanceof com.google.gson.JsonParseException
|
|
|
|
|
|| cause instanceof com.fasterxml.jackson.core.JsonProcessingException) code = AutomationFailure.Code.LANGUAGE_QUERY_PROTOCOL_FAILURE;
|
|
|
|
|
else code = AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE;
|
|
|
|
|
execution.record(code, "Language query failed: " + code.name(), details);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rememberExternalUris(Set<String> uris, com.fasterxml.jackson.databind.JsonNode node) {
|
|
|
|
@@ -336,7 +423,8 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|
|
|
|
if (node.isContainerNode()) for (var child : node) validateEdits(context, child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static <T> T await(CompletableFuture<T> future, long deadline) throws Exception {
|
|
|
|
|
private static <T> T await(CompletableFuture<T> future, long deadline, LanguageQueryExecution execution) throws Exception {
|
|
|
|
|
execution.own(() -> future.cancel(true));
|
|
|
|
|
try { return future.get(Math.max(1, deadline - System.nanoTime()), TimeUnit.NANOSECONDS); }
|
|
|
|
|
catch (ExecutionException failure) {
|
|
|
|
|
if (failure.getCause() instanceof org.eclipse.lsp4j.jsonrpc.ResponseErrorException response) {
|
|
|
|
|