Search in sources :

Example 1 with HoverInfo

use of com.nedap.openehr.lsp.document.HoverInfo in project archetype-languageserver by nedap.

the class AQLStorage method extractHoverInfo.

private void extractHoverInfo(AQLDocument document) {
    HoverInfo hoverInfo = new HoverInfo("aql");
    MetaModels metaModels = BuiltinReferenceModels.getMetaModels();
    for (ArchetypePathReference reference : document.getArchetypePathReferences()) {
        if (reference.getArchetypeId() == null) {
            continue;
        }
        try {
            // TODO: get operational template here. I think that should be cached?
            ValidationResult validationResult = archetypeRepository.getValidationResult(reference.getArchetypeId());
            if (validationResult != null) {
                Archetype flattened = validationResult.getFlattened();
                metaModels.selectModel(flattened);
                if (flattened != null) {
                    PartialAOMPathQuery aomPathQuery = new PartialAOMPathQuery(reference.getPath());
                    PartialAOMPathQuery.PartialMatch partial = aomPathQuery.findLSPPartial(flattened.getDefinition());
                    if (partial.getMatches().size() > 0) {
                        ArchetypeModelObject archetypeModelObject = partial.getMatches().get(0);
                        String content = null;
                        String description = null;
                        String typeName = "";
                        if (archetypeModelObject instanceof CAttribute) {
                            CAttribute attribute = (CAttribute) archetypeModelObject;
                            content = findNearestText((CAttribute) archetypeModelObject);
                            description = findNearestDescription((CAttribute) archetypeModelObject);
                            CObject parent = attribute.getParent();
                            if (partial.getRemainingQuery().isEmpty()) {
                                // TODO: proper path lookup here
                                BmmClass classDefinition = metaModels.getSelectedBmmModel().getClassDefinition(BmmDefinitions.typeNameToClassKey(parent.getRmTypeName()));
                                if (classDefinition != null) {
                                    BmmProperty bmmProperty = classDefinition.getFlatProperties().get(attribute.getRmAttributeName());
                                    if (bmmProperty != null) {
                                        bmmProperty.getType().toDisplayString();
                                    }
                                }
                            }
                        } else if (archetypeModelObject instanceof CObject) {
                            content = findNearestText((CObject) archetypeModelObject);
                            description = findNearestDescription((CObject) archetypeModelObject);
                            if (partial.getRemainingQuery().isEmpty()) {
                                // TODO: proper path lookup here.
                                typeName = ((CObject) archetypeModelObject).getRmTypeName();
                            }
                        }
                        String text = content + partial.getRemainingQuery().stream().map(PathSegment::toString).collect(Collectors.joining("/"));
                        text += "\n\n" + typeName;
                        text += "\n\n" + description;
                        text += "\n\nIn Archetype " + flattened.getDefinition().getTerm().getText() + " (" + reference.getArchetypeId() + ")";
                        hoverInfo.getHoverRanges().addRange(reference.getRange(), new Hover(new MarkupContent(HoverInfo.MARKDOWN, text)));
                    } else {
                        hoverInfo.getHoverRanges().addRange(reference.getRange(), new Hover(new MarkupContent(HoverInfo.MARKDOWN, "path " + reference.getPath() + " not found")));
                    }
                } else {
                    hoverInfo.getHoverRanges().addRange(reference.getRange(), new Hover(new MarkupContent(HoverInfo.MARKDOWN, "flattened archetype not found")));
                }
            } else {
                hoverInfo.getHoverRanges().addRange(reference.getRange(), new Hover(new MarkupContent(HoverInfo.MARKDOWN, "archetype not found")));
            }
        } catch (Exception e) {
            // ok... report as diagnostics or log
            e.printStackTrace();
        }
    }
    document.setHoverInfo(hoverInfo);
}
Also used : BmmClass(org.openehr.bmm.core.BmmClass) MetaModels(com.nedap.archie.rminfo.MetaModels) Archetype(com.nedap.archie.aom.Archetype) CObject(com.nedap.archie.aom.CObject) HoverInfo(com.nedap.openehr.lsp.document.HoverInfo) ArchetypeModelObject(com.nedap.archie.aom.ArchetypeModelObject) CAttribute(com.nedap.archie.aom.CAttribute) PathSegment(com.nedap.archie.paths.PathSegment) ValidationResult(com.nedap.archie.archetypevalidator.ValidationResult) AQLValidationException(com.nedap.healthcare.aqlparser.exception.AQLValidationException) AQLRuntimeException(com.nedap.healthcare.aqlparser.exception.AQLRuntimeException) AQLUnsupportedFeatureException(com.nedap.healthcare.aqlparser.exception.AQLUnsupportedFeatureException) BmmProperty(org.openehr.bmm.core.BmmProperty)

Aggregations

Archetype (com.nedap.archie.aom.Archetype)1 ArchetypeModelObject (com.nedap.archie.aom.ArchetypeModelObject)1 CAttribute (com.nedap.archie.aom.CAttribute)1 CObject (com.nedap.archie.aom.CObject)1 ValidationResult (com.nedap.archie.archetypevalidator.ValidationResult)1 PathSegment (com.nedap.archie.paths.PathSegment)1 MetaModels (com.nedap.archie.rminfo.MetaModels)1 AQLRuntimeException (com.nedap.healthcare.aqlparser.exception.AQLRuntimeException)1 AQLUnsupportedFeatureException (com.nedap.healthcare.aqlparser.exception.AQLUnsupportedFeatureException)1 AQLValidationException (com.nedap.healthcare.aqlparser.exception.AQLValidationException)1 HoverInfo (com.nedap.openehr.lsp.document.HoverInfo)1 BmmClass (org.openehr.bmm.core.BmmClass)1 BmmProperty (org.openehr.bmm.core.BmmProperty)1