Search in sources :

Example 6 with DocumentInformation

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

the class BroadcastingArchetypeRepository method extractADL14Info.

private void extractADL14Info(TextDocumentItem textDocumentItem) {
    adl14Storage.addFile(textDocumentItem);
    // make sure any ADL 2 things get removed here!
    ADL14SymbolExtractor adlSymbolExtractor = new ADL14SymbolExtractor();
    try {
        DocumentInformation documentInformation = adlSymbolExtractor.extractSymbols(textDocumentItem.getUri(), textDocumentItem.getText());
        symbolsByUri.put(textDocumentItem.getUri(), documentInformation);
        if (documentInformation.getArchetypeId() != null) {
            documentsByArchetypeId.put(documentInformation.getArchetypeId(), textDocumentItem);
        }
        resolveDocumentLinks();
        Archetype archetype = adl14Storage.getArchetype(new TextDocumentIdentifier(textDocumentItem.getUri()));
        if (archetype != null) {
            String language = archetype.getOriginalLanguage() != null ? archetype.getOriginalLanguage().getCodeString() : null;
            if (language == null) {
                language = "en";
            }
            SymbolNameFromTerminologyHelper.giveNames(documentInformation.getSymbols(), archetype, language);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return;
}
Also used : ADL14SymbolExtractor(com.nedap.openehr.lsp.symbolextractor.adl14.ADL14SymbolExtractor) Archetype(com.nedap.archie.aom.Archetype) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) IOException(java.io.IOException)

Example 7 with DocumentInformation

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

the class BroadcastingArchetypeRepository method extractADL2Info.

private void extractADL2Info(TextDocumentItem textDocumentItem) {
    try {
        ADL2SymbolExtractor adl2SymbolExtractor = new ADL2SymbolExtractor();
        DocumentInformation documentInformation = adl2SymbolExtractor.extractSymbols(textDocumentItem.getUri(), textDocumentItem.getText());
        symbolsByUri.put(textDocumentItem.getUri(), documentInformation);
        if (documentInformation.getArchetypeId() != null) {
            documentsByArchetypeId.put(documentInformation.getArchetypeId(), textDocumentItem);
        }
        if (documentInformation.getErrors().hasNoErrors()) {
            ADLParser adlParser = new ADLParser(BuiltinReferenceModels.getMetaModels());
            // no console output please :)
            adlParser.setLogEnabled(false);
            Archetype archetype = null;
            try {
                archetype = adlParser.parse(textDocumentItem.getText());
                addArchetype(archetype);
                // perform incremental compilation here
                invalidateAndRecompileArchetypes(archetype);
                ValidationResult result = getValidationResult(archetype.getArchetypeId().toString());
                Archetype archetypeForTerms = archetype;
                if (result != null && result.getFlattened() != null) {
                    archetypeForTerms = result.getFlattened();
                }
                String language = archetype.getOriginalLanguage() != null ? archetype.getOriginalLanguage().getCodeString() : null;
                if (language == null) {
                    language = "en";
                }
                documentInformation.setHoverInfo(new ArchetypeHoverInfo(documentInformation, archetype, archetypeForTerms, language));
                SymbolNameFromTerminologyHelper.giveNames(documentInformation.getSymbols(), archetypeForTerms, language);
            // diagnostics will now be pushed from within the invalidateArchetypesAndRecompile method
            } catch (ADLParseException e) {
                // this should have been checked in the previous step. But still, it could happen.
                textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), e.getErrors());
            } catch (Exception ex) {
                // this particular exce[tion is a parse error, usually when extracting JSON. be sure to post taht
                textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), ex);
            }
        } else {
            textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), documentInformation.getErrors());
        }
    } catch (IOException e) {
        // shouldn't happen, ever, just in memory processing
        throw new RuntimeException(e);
    }
}
Also used : ADLParser(com.nedap.archie.adlparser.ADLParser) ADL2SymbolExtractor(com.nedap.openehr.lsp.symbolextractor.ADL2SymbolExtractor) Archetype(com.nedap.archie.aom.Archetype) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) IOException(java.io.IOException) ValidationResult(com.nedap.archie.archetypevalidator.ValidationResult) ArchetypeHoverInfo(com.nedap.openehr.lsp.document.ArchetypeHoverInfo) ADLParseException(com.nedap.archie.adlparser.ADLParseException) IOException(java.io.IOException) ADLParseException(com.nedap.archie.adlparser.ADLParseException)

Example 8 with DocumentInformation

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

the class BroadcastingArchetypeRepository method setValidationResult.

@Override
public void setValidationResult(ValidationResult result) {
    super.setValidationResult(result);
    TextDocumentItem textDocumentItem = documentsByArchetypeId.get(result.getArchetypeId());
    DocumentInformation documentInformation = getDocumentInformation(textDocumentItem.getUri());
    textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), documentInformation, result);
// new validation result received! Broadcast it :)
}
Also used : DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation)

Example 9 with DocumentInformation

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

the class BroadcastingArchetypeRepository method getDocumentLinks.

public List<DocumentLink> getDocumentLinks(DocumentLinkParams params) {
    DocumentInformation documentInformation = this.symbolsByUri.get(params.getTextDocument().getUri());
    if (documentInformation == null) {
        return new ArrayList<>();
    }
    List<DocumentLink> result = documentInformation.getAllDocumentLinks();
    return result;
}
Also used : DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) ArrayList(java.util.ArrayList)

Example 10 with DocumentInformation

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

the class ADL2SymbolExtractor method extractSymbols.

public DocumentInformation extractSymbols(String uri, String text) throws IOException {
    AdlLexer lexer = new AdlLexer(CharStreams.fromString(text));
    AdlParser parser = new AdlParser(new CommonTokenStream(lexer));
    ArchieErrorListener listener = new ArchieErrorListener();
    parser.addErrorListener(listener);
    SymbolInformationExtractingListener symbolExtractingListener = new SymbolInformationExtractingListener(uri, lexer);
    // DocumentSymbolExtractingListener symbolExtractingListener = new DocumentSymbolExtractingListener();
    try {
        new ParseTreeWalker().walk(symbolExtractingListener, parser.adl());
    } catch (Exception e) {
        // this is fine. for now
        e.printStackTrace();
    }
    archetypeId = symbolExtractingListener.getArchetypeId();
    return new DocumentInformation(archetypeId, ADLVersion.VERSION_2, listener.getErrors(), symbolExtractingListener.getSymbols(), symbolExtractingListener.getFoldingRanges(), symbolExtractingListener.getDocumentLinks(), symbolExtractingListener.getCTerminologyCodes());
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ArchieErrorListener(com.nedap.archie.antlr.errors.ArchieErrorListener) AdlLexer(com.nedap.archie.adlparser.antlr.AdlLexer) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) AdlParser(com.nedap.archie.adlparser.antlr.AdlParser) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) IOException(java.io.IOException)

Aggregations

DocumentInformation (com.nedap.openehr.lsp.document.DocumentInformation)11 JsonPrimitive (com.google.gson.JsonPrimitive)4 Archetype (com.nedap.archie.aom.Archetype)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Lists (com.google.common.collect.Lists)2 ArchieErrorListener (com.nedap.archie.antlr.errors.ArchieErrorListener)2 OperationalTemplate (com.nedap.archie.aom.OperationalTemplate)2 ValidationResult (com.nedap.archie.archetypevalidator.ValidationResult)2 Flattener (com.nedap.archie.flattener.Flattener)2 BroadcastingArchetypeRepository (com.nedap.openehr.lsp.repository.BroadcastingArchetypeRepository)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)2 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ADLParseException (com.nedap.archie.adlparser.ADLParseException)1