Search in sources :

Example 1 with ArchetypeTerm

use of com.nedap.archie.aom.terminology.ArchetypeTerm in project archetype-languageserver by nedap.

the class ArchetypeHoverInfo method getHoverInfoForCObject.

private void getHoverInfoForCObject(DocumentInformation documentInformation, CObject definition, Archetype archetypeForTerms) {
    ArchetypeTerm term = archetypeForTerms.getTerm(definition, language);
    String content;
    if (term != null) {
        content = "### " + definition.getRmTypeName() + ": " + term.getText() + "\n\n\t" + term.getDescription();
    } else {
        content = "### No term found";
    }
    CObject flattenedObject = (definition instanceof CPrimitiveObject) ? definition : archetypeForTerms.itemAtPath(definition.getPath());
    if (flattenedObject == null) {
        // fallback if something went wrong
        flattenedObject = definition;
    }
    MultiplicityInterval occurrences = flattenedObject.effectiveOccurrences(metaModels::referenceModelPropMultiplicity);
    content += "\n occurrences: " + occurrences;
    content += "\n\n path: " + definition.getPath();
    Hover hover = new Hover();
    hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
    Range range = getHoverRange(documentInformation, definition);
    if (range != null) {
        hoverRanges.addRange(range, hover);
    }
}
Also used : TerminologyCodeWithArchetypeTerm(com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm) ArchetypeTerm(com.nedap.archie.aom.terminology.ArchetypeTerm) CObject(com.nedap.archie.aom.CObject) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range) CPrimitiveObject(com.nedap.archie.aom.CPrimitiveObject) MarkupContent(org.eclipse.lsp4j.MarkupContent) MultiplicityInterval(com.nedap.archie.base.MultiplicityInterval)

Example 2 with ArchetypeTerm

use of com.nedap.archie.aom.terminology.ArchetypeTerm in project archetype-languageserver by nedap.

the class ArchetypeHoverInfo method getTerms.

private List<TerminologyCodeWithArchetypeTerm> getTerms(CTerminologyCode cTermCode, DocumentSymbol terminologyCode, Archetype archetypeForTerms) {
    List<TerminologyCodeWithArchetypeTerm> result = new ArrayList();
    ArchetypeTerminology terminology = archetypeForTerms.getTerminology(cTermCode);
    String language = ArchieLanguageConfiguration.getMeaningAndDescriptionLanguage();
    String defaultLanguage = ArchieLanguageConfiguration.getDefaultMeaningAndDescriptionLanguage();
    String constraint = terminologyCode.getName();
    if (constraint.startsWith("at")) {
        ArchetypeTerm termDefinition = terminology.getTermDefinition(language, constraint);
        if (termDefinition == null) {
            termDefinition = terminology.getTermDefinition(defaultLanguage, constraint);
        }
        if (termDefinition != null) {
            result.add(new TerminologyCodeWithArchetypeTerm(constraint, termDefinition));
        }
    } else if (constraint.startsWith("ac")) {
        ValueSet acValueSet = terminology.getValueSets().get(constraint);
        if (acValueSet != null) {
            for (String atCode : acValueSet.getMembers()) {
                ArchetypeTerm termDefinition = terminology.getTermDefinition(language, atCode);
                if (termDefinition == null) {
                    termDefinition = terminology.getTermDefinition(defaultLanguage, atCode);
                }
                if (termDefinition != null) {
                    result.add(new TerminologyCodeWithArchetypeTerm(atCode, termDefinition));
                }
            }
        }
    }
    return result;
}
Also used : TerminologyCodeWithArchetypeTerm(com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm) ArchetypeTerm(com.nedap.archie.aom.terminology.ArchetypeTerm) ArchetypeTerminology(com.nedap.archie.aom.terminology.ArchetypeTerminology) ArrayList(java.util.ArrayList) TerminologyCodeWithArchetypeTerm(com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm) ValueSet(com.nedap.archie.aom.terminology.ValueSet)

Example 3 with ArchetypeTerm

use of com.nedap.archie.aom.terminology.ArchetypeTerm in project archetype-languageserver by nedap.

the class DocumentLinks method resolveLinkInternal.

/**
 * Re-resolve all document links.
 * TODO: add incremental compile?
 * @param repository
 * @param documentLink
 * @return
 */
private DocumentLink resolveLinkInternal(BroadcastingArchetypeRepository repository, DocumentLink documentLink) {
    if (documentLink.getData() != null) {
        String ref = (String) documentLink.getData();
        TextDocumentItem document = repository.getDocument(ref);
        if (document != null) {
            documentLink.setTarget(document.getUri());
            DocumentInformation information = repository.getDocumentInformation(document.getUri());
            if (information != null && information.getArchetypeId() != null) {
                Archetype archetype = repository.getArchetype(information.getArchetypeId());
                if (archetype != null && archetype.getOriginalLanguage() != null) {
                    ArchetypeTerm term = archetype.getTerm(archetype.getDefinition(), archetype.getOriginalLanguage().getCodeString());
                    if (term != null) {
                        documentLink.setTooltip(term.getText() + "\n" + term.getDescription());
                    }
                }
            }
        }
    }
    return documentLink;
}
Also used : TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) ArchetypeTerm(com.nedap.archie.aom.terminology.ArchetypeTerm) Archetype(com.nedap.archie.aom.Archetype)

Example 4 with ArchetypeTerm

use of com.nedap.archie.aom.terminology.ArchetypeTerm in project archetype-languageserver by nedap.

the class SymbolNameFromTerminologyHelper method processSymbol.

private static void processSymbol(DocumentSymbol documentSymbol, Archetype archetype, String language) {
    if (documentSymbol.getKind() == SymbolKind.Class) {
        Matcher matcher = cComplexobjectPattern.matcher(documentSymbol.getName());
        if (matcher.matches()) {
            String idCode = matcher.group("id");
            ArchetypeTerm term = archetype.getTerminology().getTermDefinition(language, idCode);
            if (term != null) {
                documentSymbol.setDetail(documentSymbol.getName());
                documentSymbol.setName(term.getText());
            // documentSymbol.setDetail(term.getText());
            }
        }
    }
    if (documentSymbol.getChildren() != null) {
        for (DocumentSymbol child : documentSymbol.getChildren()) {
            processSymbol(child, archetype, language);
        }
    }
}
Also used : ArchetypeTerm(com.nedap.archie.aom.terminology.ArchetypeTerm) Matcher(java.util.regex.Matcher) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol)

Example 5 with ArchetypeTerm

use of com.nedap.archie.aom.terminology.ArchetypeTerm in project archetype-languageserver by nedap.

the class ArchetypeHoverInfo method extractHoverInfo.

private void extractHoverInfo(DocumentInformation documentInformation, CTerminologyCode object, Archetype archetypeForTerms) {
    // get the closest to an actual location
    DocumentSymbol documentSymbol = documentInformation.lookupCObjectOrAttribute(object.path(), true);
    // the document symbol tree does not contain terminology codes. So use the separate index
    // perhaps better to add two versions of the tree, one for internal and one for external use?
    // anyway, this works and is fast.
    DocumentSymbol terminologyCodeSymbol = documentInformation.getcTerminologyCodes().getFirstMatchAfter(documentSymbol.getSelectionRange().getStart(), d -> object.getConstraint().contains(d.getName()));
    if (terminologyCodeSymbol == null) {
        System.err.println("COULD NOT FIND DOCUMENT SYMBOL FOR CTERMINOLOGY CODE");
        return;
    }
    List<TerminologyCodeWithArchetypeTerm> terms = getTerms(object, terminologyCodeSymbol, archetypeForTerms);
    if (terms != null) {
        StringBuilder content = new StringBuilder();
        if (object.getConstraint() != null && object.getConstraint().size() == 1 && AOMUtils.isValueSetCode(object.getConstraint().get(0))) {
            ArchetypeTerm valueSetTerm = archetypeForTerms.getTerm(object, object.getConstraint().get(0), language);
            if (valueSetTerm != null) {
                content.append("## ");
                content.append(valueSetTerm.getText());
                content.append("\n");
                content.append(valueSetTerm.getDescription());
                content.append("\n\n### Members:");
            }
        }
        for (TerminologyCodeWithArchetypeTerm term : terms) {
            content.append("\n\n");
            content.append(term.getCode());
            content.append(": ");
            if (term.getTerm() != null) {
                content.append("__");
                content.append(term.getTerm().getText());
                content.append("__");
                content.append("\n\t");
                content.append(term.getTerm().getDescription());
            }
        }
        Hover hover = new Hover();
        hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
        Range range = terminologyCodeSymbol.getRange();
        hoverRanges.addRange(range, hover);
    }
}
Also used : TerminologyCodeWithArchetypeTerm(com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm) ArchetypeTerm(com.nedap.archie.aom.terminology.ArchetypeTerm) Hover(org.eclipse.lsp4j.Hover) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) TerminologyCodeWithArchetypeTerm(com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent)

Aggregations

ArchetypeTerm (com.nedap.archie.aom.terminology.ArchetypeTerm)5 TerminologyCodeWithArchetypeTerm (com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm)3 DocumentSymbol (org.eclipse.lsp4j.DocumentSymbol)2 Hover (org.eclipse.lsp4j.Hover)2 MarkupContent (org.eclipse.lsp4j.MarkupContent)2 Range (org.eclipse.lsp4j.Range)2 Archetype (com.nedap.archie.aom.Archetype)1 CObject (com.nedap.archie.aom.CObject)1 CPrimitiveObject (com.nedap.archie.aom.CPrimitiveObject)1 ArchetypeTerminology (com.nedap.archie.aom.terminology.ArchetypeTerminology)1 ValueSet (com.nedap.archie.aom.terminology.ValueSet)1 MultiplicityInterval (com.nedap.archie.base.MultiplicityInterval)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 TextDocumentItem (org.eclipse.lsp4j.TextDocumentItem)1