diff --git a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/manager/IgContextManager.java b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/manager/IgContextManager.java index 025c66a..5af30f3 100644 --- a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/manager/IgContextManager.java +++ b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/manager/IgContextManager.java @@ -2,8 +2,10 @@ import java.io.InputStream; import java.net.URI; +import java.util.HashSet; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.cqframework.cql.cql2elm.LibraryManager; import org.cqframework.fhir.npm.ILibraryReader; @@ -15,7 +17,6 @@ import org.eclipse.lsp4j.FileEvent; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.hl7.cql.model.NamespaceInfo; import org.opencds.cqf.cql.ls.core.ContentService; import org.opencds.cqf.cql.ls.core.utility.Uris; import org.opencds.cqf.cql.ls.server.event.DidChangeWatchedFilesEvent; @@ -69,8 +70,20 @@ public synchronized void setupLibraryManager(URI uri, LibraryManager libraryMana .getModelInfoLoader() .registerModelInfoProvider(new NpmModelInfoProvider( npmProcessor.getPackageManager().getNpmList(), reader, adapter)); - for (NamespaceInfo ni : npmProcessor.getNamespaces()) { - namespaceManager.ensureNamespaceRegistered(ni); + + // TODO: This is a workaround for: a) multiple packages with the same package id will be in the dependency + // list, and b) there are packages with different package ids but the same base canonical (e.g. + // fhir.r4.examples has the same base canonical as fhir.r4) + // NOTE: Using ensureNamespaceRegistered works around a but not b + // NOTE: This logic is also used in org.opencds.cqf.fhir.cql.Engines.buildEnvironment() + Set keys = new HashSet(); + Set uris = new HashSet(); + for (var n : npmProcessor.getNamespaces()) { + if (!keys.contains(n.getName()) && !uris.contains(n.getUri())) { + libraryManager.getNamespaceManager().addNamespace(n); + keys.add(n.getName()); + uris.add(n.getUri()); + } } } }