Skip to content
Open
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
@@ -1,7 +1,9 @@
package org.opencds.cqf.cql.ls.server.command;

import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import org.cqframework.cql.cql2elm.CqlTranslator;
Expand All @@ -13,6 +15,7 @@

public class ViewElmCommandContribution implements CommandContribution {
private static final String VIEW_ELM_COMMAND = "org.opencds.cqf.cql.ls.viewElm";
private static final String VIEW_ELM_JSON_COMMAND = "org.opencds.cqf.cql.ls.viewElmJson";

private final CqlTranslationManager cqlTranslationManager;

Expand All @@ -22,31 +25,32 @@ public ViewElmCommandContribution(CqlTranslationManager cqlTranslationManager) {

@Override
public Set<String> getCommands() {
return Collections.singleton(VIEW_ELM_COMMAND);
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(VIEW_ELM_COMMAND, VIEW_ELM_JSON_COMMAND)));
}

@Override
public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
switch (params.getCommand()) {
case VIEW_ELM_COMMAND:
return this.viewElm(params);
return this.viewElm(params, true);
case VIEW_ELM_JSON_COMMAND:
return this.viewElm(params, false);
default:
return CommandContribution.super.executeCommand(params);
}
}

// There's currently not a "show text file" or similar command in the LSP spec,
// So it's not client agnostic. The client has to know that the result of this
// command
// is XML and display it accordingly.
private CompletableFuture<Object> viewElm(ExecuteCommandParams params) {
// command is XML or JSON and display it accordingly.
private CompletableFuture<Object> viewElm(ExecuteCommandParams params, Boolean isXml) {
String uriString = ((JsonElement) params.getArguments().get(0)).getAsString();
try {

URI uri = Uris.parseOrNull(uriString);
CqlTranslator translator = this.cqlTranslationManager.translate(uri);
if (translator != null) {
return CompletableFuture.completedFuture(translator.toXml());
return CompletableFuture.completedFuture(isXml ? translator.toXml() : translator.toJson());
}

return CompletableFuture.completedFuture(null);
Expand Down