tree schema BUGFIX resolve parsed exts for main module only

Submodules may reference the main module and need
to wait for it to be fully parsed before resolving.

Fixes #1943
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 522aae4..e8e130a 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -61,7 +61,7 @@
 /**
  * @brief Loop through all substatements. Starts a for loop and ::YANG_READ_SUBSTMT_NEXT_ITER must be used at its end.
  *
- * @param[in] CTX yang parser context for logging.
+ * @param[in] CTX yang parser context.
  * @param[out] KW YANG keyword read.
  * @param[out] WORD Pointer to the keyword itself.
  * @param[out] WORD_LEN Length of the keyword.
@@ -87,7 +87,7 @@
 /**
  * @brief Next iteration of ::YANG_READ_SUBSTMT_FOR_GOTO loop.
  *
- * @param[in] CTX yang parser context for logging.
+ * @param[in] CTX yang parser context.
  * @param[out] KW YANG keyword read.
  * @param[out] WORD Pointer to the keyword itself.
  * @param[out] WORD_LEN Length of the keyword.
@@ -100,7 +100,7 @@
         goto ERR_LABEL; \
     } \
     if (KW == LY_STMT_SYNTAX_RIGHT_BRACE) { \
-        if (EXTS && (RET = ly_set_add(&(CTX)->ext_inst, (EXTS), 1, NULL))) { \
+        if (EXTS && (RET = ly_set_add(&(CTX)->main_ctx->ext_inst, (EXTS), 1, NULL))) { \
             goto ERR_LABEL; \
         } \
         __loop_end = 1; \
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 582befb..6b5ff77 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -646,7 +646,7 @@
         return LY_SUCCESS;
     }
 
-    return ly_set_add(&ctx->ext_inst, exts, 1, NULL);
+    return ly_set_add(&ctx->main_ctx->ext_inst, exts, 1, NULL);
 }
 
 /**
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 9c0d876..49ec92c 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -1423,9 +1423,6 @@
     /* resolve imports and includes */
     LY_CHECK_GOTO(ret = lysp_resolve_import_include(pctx, (struct lysp_module *)submod, new_mods), error);
 
-    /* resolve extension instance plugin records */
-    LY_CHECK_GOTO(ret = lysp_resolve_ext_instance_records(pctx), error);
-
     if (format == LYS_IN_YANG) {
         lysp_yang_ctx_free(yangctx);
     } else {
@@ -1604,6 +1601,7 @@
 
     if (LY_ARRAY_COUNT(mod->exts) == 3) {
         /* first extension instances */
+        assert(pctx->main_ctx == pctx);
         LY_CHECK_RET(ly_set_add(&pctx->ext_inst, mod->exts, 1, NULL));
     }
 
@@ -1658,6 +1656,7 @@
 
     if (LY_ARRAY_COUNT(mod->exts) == 1) {
         /* first extension instance */
+        assert(pctx->main_ctx == pctx);
         LY_CHECK_RET(ly_set_add(&pctx->ext_inst, mod->exts, 1, NULL));
     }