Skip to content

Implement package ID inheritance and cross-package type resolution - #93

Merged
rijesha merged 6 commits into
mainfrom
copilot/update-pkg-import-proto-code
Dec 18, 2025
Merged

Implement package ID inheritance and cross-package type resolution#93
rijesha merged 6 commits into
mainfrom
copilot/update-pkg-import-proto-code

Conversation

Copilot AI commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Proto files can now import other proto files without explicit package IDs - imported packages inherit the ID from their importer. Cross-package type references are now supported with automatic namespace resolution.

Core Changes

  • Package ID inheritance: Imported packages without option pkgid inherit from importing package
  • Cross-package type resolution: Fields can reference types (enums, messages) from any imported package
  • Import tracking: package_imports dict tracks import relationships; Field.type_package tracks type origins
  • Validation: Inheritance applied pre-validation; detects same package name with conflicting IDs

Code Generation

  • Per-file output: Each .proto generates own .sf.{h,hpp,ts,py,cs} regardless of import relationships
  • C# namespace handling: Auto-generates using directives for imported packages; uses correct package names for cross-package types

Example

// common_types.proto - no pkgid defined
package common_types;
message Timestamp { ... }

// my_app.proto
package my_app;
option pkgid = 1;  // common_types inherits pkgid=1

import "common_types.proto";

message MyMessage {
  Timestamp created_at = 1;  // Cross-package reference works
}

Generated C#:

using StructFrame.CommonTypes;  // Auto-added

namespace StructFrame.MyApp {
    public struct MyAppMyMessage {
        public CommonTypesTimestamp CreatedAt;  // Correct type reference
    }
}

Test Files

  • pkg_test_messages.proto: pkgid=1, imports common_types.proto (inherits ID) and pkg_test_a.proto (pkgid=2)
  • test_packaging.py: Validates inheritance and cross-package references
  • Updated test_config.json to include packaging tests
  • Integrated packaging tests into test runner: Added standalone test execution to automatically run test_packaging.py when test_all is called
Original prompt

This section details on the original issue you should resolve

<issue_title>Update pkg import code</issue_title>
<issue_description>Rework the proto files used for the pkg tests.

Test_messages.proto is good, but also have it import common_types.proto and use the message in there. expected values.json should be updated for the added message type. remove pkg_id from common_types.proto

Now make pkg_test_messages.proto. This should have a pkg_id of 1.
This will import common_types.proto. When it does that common_types will have the same pkg_id as pkg_test_messages for any messages defined in common_types.

have pkg_test_messages.proto also import pkg_test_a. pkg_test_a will have a package name and package id.

All .proto files should compile and generate into there own .h/ts/.py files. With cpp and other relevant languages each .proto file will have the namespace of there package name.

If a proto file is imported with a package_name that has the same as another but no pkg_id that is ok it will use that pkg_id. If two pkgs have the same name but different ids then the generation should fail and error should be displayed to the user specifying the .proto files containing the problem.

The test_all should also add tests for packaging.

Update documentation as requried</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits December 18, 2025 18:05
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>
Copilot AI changed the title [WIP] Update pkg import code for proto files Implement package ID inheritance and cross-package type resolution Dec 18, 2025
Copilot AI requested a review from rijesha December 18, 2025 18:22
@rijesha

rijesha commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

@copilot
The package test is not showing in the test suit output. It should run when test_all is called

@rijesha rijesha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The package test is not showing in the test suit output. It should run when test_all is called

Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com>

Copilot AI commented Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

@copilot
The package test is not showing in the test suit output. It should run when test_all is called

Fixed in commit f475af5. The packaging test now runs automatically as part of test_all and appears in the "PACKAGE IMPORT TESTS" section of the output.

@copilot The package test is not showing in the test suit output. It should run when test_all is called

Fixed in commit f475af5. Added run_standalone_tests() method to the test runner that discovers and executes all test_*.py files in the tests directory. The packaging test now appears in the test suite output under "PACKAGE IMPORT TESTS".

Copilot AI requested a review from rijesha December 18, 2025 18:52
@rijesha
rijesha marked this pull request as ready for review December 18, 2025 18:53
@rijesha
rijesha merged commit 3c858d0 into main Dec 18, 2025
1 check passed
@rijesha
rijesha deleted the copilot/update-pkg-import-proto-code branch January 5, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update pkg import code

2 participants