TypeFox / yang-lsp

A Language Server for YANG
http://www.yang-central.org
Apache License 2.0
51 stars 13 forks source link

incorrect serialization of yang namespace #207

Closed RimShao closed 3 years ago

RimShao commented 3 years ago

Hi yang lsp generates faulty namespace in below use case, Please use attached yang files yangTransform.zip to reproduce this problem.


deviation /me3gpp:ManagedElement/gnbdu3gpp:GNBDUFunction/nrcelldu3gpp:NRCellDU/nrcelldu3gpp:attributes/nrcelldu3gpp:bWPRef {
    deviate add {
        must 're-match(., concat("ManagedElement=", ../../../../me3gpp:id,",GNBDUFunction=", ../../../gnbdu3gpp:id,",BWP=[^,]+"))' {
             error-message
             "Must refer to a BWP in the same GNBDUFunction as the NRCellDU.";
        }
       }
     }

output:

deviation /me3gpp:ManagedElement/gnbdu3gpp:GNBDUFunction/nrcelldu3gpp:NRCellDU/nrcelldu3gpp:attributes/nrcelldu3gpp:bWPRef {
        deviate add {
            must 're-match(., concat("ManagedElement=", ../../../../me3gpp:id,",GNBDUFunction=", ../../../gnbdu3gpp:me3gpp:id,",BWP=[^,]+"))' {
                error-message^M
            "Must refer to a BWP in the same GNBDUFunction as the NRCellDU.";
            }
        }
    }

output gnbdu3gpp:id is expected instead of gnbdu3gpp:me3gpp:id .

dhuebner commented 3 years ago

@RimShao Thanks for providing an example model!

Unfortunately I can't reproduce the problem, maybe it is because of an error in module _3gpp-nr-nrm-nrcelldu

    list NRCellDU {
      description "Represents the information of a cell known by DU.";
      reference "3GPP TS 28.541";
      key id;  // <-- error here: Couldn't resolve reference to Leaf 'id'.

Could you please double check and verify the problem present with models from zip? If so, could you give me a hint on how to reproduce? In our test cases we load the model file as is and invoke the serialize with parsed module as input.

dhuebner commented 3 years ago

@RimShao Can reproduce it now. The problem was that we already have _3gpp-nr-nrm-gnbdufunction and some other in our test resources sub-folders, so the wrong one was loaded.

dhuebner commented 3 years ago

Note: The problem was that at ../../../gnbdu3gpp:id two elements with name id are accessible me3gpp:id and gnbdu3gpp:id. super.getCrossReferenceNameFromScope from YangCrossReferenceSerializer returned the first best element me3gpp:id. io.typefox.yang.resource.YangCrossReferenceSerializer.getCrossReferenceNameFromScope(EObject, CrossReference, EObject, IScope, Acceptor) tries to cut the first segment me3gpp: but it does so only if it matches the prefix (here gnbdu3gpp), otherwise it returns the full name me3gpp:id. That is later concatenated with existing prefix gnbdu3gpp which gives gnbdu3gpp:me3gpp:id which is even syntactically wrong. The fix is in CrossRef serializer, but could be fixed in e.g. SerializerScopeProvider

RimShao commented 3 years ago

@dhuebner

Great that the problem is reproduced and root cause is found.

dhuebner commented 3 years ago

@RimShao Are you able to test your case with current nightly?

RimShao commented 3 years ago

@dhuebner

Where is the night build you mentioned ? Thanks a lot.

dhuebner commented 3 years ago

@RimShao Maven snapshot should be deployed automatically, but I will double check that. Here is the build: https://github.com/theia-ide/yang-lsp/actions/runs/878685021

dhuebner commented 3 years ago

@RimShao yang-lsp 0.5.0-SNAPSHOT was published Wed May 26 2021 15:32:09 GMT+0200 (CEST)

RimShao commented 3 years ago

@dhuebner

Thanks a lot. the problem is fixed now.

Will you publish official 0.5.0 instead of 0.5.0-snapshot ?

dhuebner commented 3 years ago

@RimShao @andreasjakobik Maybe we can put some more fixes into 0.5.0 ?

if not, then maybe 0.4.1 would be a better version choice

RimShao commented 3 years ago

seems 0.4.1 is better

andreasjakobik commented 3 years ago

@dhuebner Thanks for quick fix. Here is another serialization issue, but it can wait until 0.5.0 release: https://github.com/theia-ide/yang-lsp/issues/209

dhuebner commented 3 years ago

released with v0.4.1