TypeFox / yang-lsp

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

Deviation of SchemaNode from external module doesn't apply with correct scope #156

Closed huyuwen closed 4 years ago

huyuwen commented 5 years ago

Previously, there is a bug #114, which fixed schema node identifier in deviation resolving from the same module. But recently, we found when a deviation reference is point to a schema node from another module, then the resolving in deviation failed again.

module yang-test {
    yang-version 1.1;
    namespace urn:rdns:org:yangster:model:yang-test;
    prefix ygtest;
    list l1 {
        leaf lf1 {
            type string;
        }
    }
}
module bug_114_ext {
    yang-version 1.1;
    prefix bug_114_ext;
    namespace bug_114_ext;
    import yang-test {
        prefix ygtest;
    }
    deviation ygtest:l1 {
        deviate add {
            unique lf1;
        }
    }
}

When loading above test data, 'lf1' will be reported as an error, due to failed to find 'lf1' schema node. If we change 'unique lf1' to 'unique ygtest:lf1', then there will be no error. It indicates that it was trying to find 'lf1' in current local module 'bug_114_ext'. But that is not right.

  1. Here in deviation/deviate, the prefix is not mandatory needed. See Example in RFC 7950
    deviation /base:system {
    deviate delete {
      must "daytime or time";
    }
    }

    Personally, I also prefer to have a prefix, that would be much clear and better.

  2. In deviation/deviate, the correct scope should inherit from the same scope of the deviation reference target (some schema node, whatever in the same module of deviation or some other modules)

My proposal is to enhance ScopeContextProvider when computeScope of Deviation and its children. Meanwhile, it might need to force to resolve some SchemaNodeIdentifier's container ScopeContext during getEObject(String uriFragement, ...) in YangResource