diff --git a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java index b048b29..6313941 100644 --- a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java +++ b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java @@ -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; @@ -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; @@ -22,14 +25,16 @@ public ViewElmCommandContribution(CqlTranslationManager cqlTranslationManager) { @Override public Set getCommands() { - return Collections.singleton(VIEW_ELM_COMMAND); + return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(VIEW_ELM_COMMAND, VIEW_ELM_JSON_COMMAND))); } @Override public CompletableFuture 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); } @@ -37,16 +42,15 @@ public CompletableFuture executeCommand(ExecuteCommandParams 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 viewElm(ExecuteCommandParams params) { + // command is XML or JSON and display it accordingly. + private CompletableFuture 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);