Skip to content

Commit eac5766

Browse files
Myungho Jungmeta-codesync[bot]
authored andcommitted
Add Hack NamePrefix support
Summary: Add a new `hack.NamePrefix` structured annotation that allows Thrift definitions to prepend a configurable prefix to generated Hack type names. This enables namespace-like disambiguation for generated Hack code without renaming every type individually via `hack.Name`. The annotation supports both program-level and per-definition scoping, with an `apply_on_getName` flag to control whether the prefix also affects the `getName()` return value. The Hack code generator is updated to apply these prefixes during type name resolution. Reviewed By: rmakheja Differential Revision: D101434629 fbshipit-source-id: d22f4883a33003d7ec768c4fa187b5f06a1c161f
1 parent 5e9ed09 commit eac5766

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

thrift/annotation/hack.thrift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ struct Name {
119119
2: string reason;
120120
}
121121

122+
@scope.Program
123+
@scope.Structured
124+
@scope.Typedef
125+
@scope.Enum
126+
@scope.Const
127+
@scope.Service
128+
struct NamePrefix {
129+
/// Prepends a prefix to generated Hack type names.
130+
/// When both program-level and definition-level NamePrefix are present,
131+
/// the definition-level prefix wins instead of stacking with the
132+
/// program-level prefix.
133+
1: string prefix;
134+
/// Set to false when you want getName() to keep returning the IDL name.
135+
2: bool apply_on_getName = true;
136+
/// When true, types generated from services (interfaces, clients,
137+
/// processors, helper structs like args/result) are not prefixed.
138+
/// When false (default), all types including service-generated types
139+
/// are prefixed.
140+
3: bool skip_services = false;
141+
}
142+
122143
/// This annotation is for adding Hack attributes to union enums.
123144
@scope.Union
124145
struct UnionEnumAttributes {

0 commit comments

Comments
 (0)