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

Fixes the error 'duplicate namespace' attempting to translate in an I… #80

Merged
merged 2 commits into from
Sep 30, 2024
Merged
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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> keys = new HashSet<String>();
Set<String> uris = new HashSet<String>();
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());
}
}
}
}
Expand Down