Skip to content

Commit 756bf47

Browse files
stephentoubCopilot
andcommitted
Fix Rust import generation and Python test import ordering
- Rust generator: merge crate::types imports in api_types.rs so the source matches what rustfmt produces on Linux (joining adjacent use crate::types::... lines). This unbreaks the Codegen Check on CI. - Python: sort the import block in test_event_forward_compatibility.py to satisfy ruff I001. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3daa147 commit 756bf47

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

python/test_event_forward_compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pytest
1414

1515
from copilot.generated.session_events import (
16+
AttachmentGithubReferenceType,
1617
Data,
1718
ElicitationCompletedAction,
1819
ElicitationRequestedMode,
@@ -23,7 +24,6 @@
2324
SessionEventType,
2425
SessionTaskCompleteData,
2526
UserMessageAgentMode,
26-
AttachmentGithubReferenceType,
2727
session_event_from_dict,
2828
session_event_to_dict,
2929
)

rust/src/generated/api_types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use super::session_events::{
1111
PermissionRule, ReasoningSummary, SessionMode, ShutdownType, SkillSource,
1212
UserToolSessionApproval,
1313
};
14-
use crate::types::SessionEvent;
15-
use crate::types::{RequestId, SessionId};
14+
use crate::types::{RequestId, SessionEvent, SessionId};
1615

1716
/// JSON-RPC method name constants.
1817
pub mod rpc_methods {

scripts/codegen/rust.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,12 +1561,22 @@ function generateApiTypesCode(
15611561
names.add(typeName);
15621562
}
15631563
}
1564+
// api_types.rs always needs RequestId/SessionId from crate::types. Merge them into
1565+
// the same import group as any other crate::types refs (e.g. SessionEvent) so the
1566+
// generator emits a single `use crate::types::{...};` line that matches what
1567+
// rustfmt would otherwise produce after merging adjacent imports.
1568+
let cratesTypesImports = externalImports.get("crate::types");
1569+
if (!cratesTypesImports) {
1570+
cratesTypesImports = new Set<string>();
1571+
externalImports.set("crate::types", cratesTypesImports);
1572+
}
1573+
cratesTypesImports.add("RequestId");
1574+
cratesTypesImports.add("SessionId");
15641575
for (const [module, typeNames] of [...externalImports].sort(([left], [right]) =>
15651576
left.localeCompare(right),
15661577
)) {
15671578
out.push(`use ${module}::{${[...typeNames].sort().join(", ")}};`);
15681579
}
1569-
out.push("use crate::types::{RequestId, SessionId};");
15701580
out.push("");
15711581

15721582
// Method constants

0 commit comments

Comments
 (0)