[clang] Use existing AvailabilityKind enum for code completion availability (PR #160296)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 17 01:15:01 PST 2026
================
@@ -3197,12 +3188,47 @@ def __repr__(self) -> str:
)
-availabilityKinds = {
- 0: CompletionChunk.Kind("Available"),
- 1: CompletionChunk.Kind("Deprecated"),
- 2: CompletionChunk.Kind("NotAvailable"),
- 3: CompletionChunk.Kind("NotAccessible"),
-}
+# AvailabilityKindCompat is an exact copy of AvailabilityKind, except for __str__
+# This is a temporary measure to keep the string representation the same
+# until we unify the return of CompletionString.availability to be AvailabilityKind
+# Note that deriving from AvailabilityKind directly is not possible
+class AvailabilityKindCompat(BaseEnumeration):
+ """
+ Describes the availability of an entity.
+ """
+
+ # Ensure AvailabilityKindCompat is comparable with AvailabilityKind
+ def __eq__(self, other: object) -> bool:
+ if isinstance(other, AvailabilityKind):
+ return self.value == other.value
+ else:
+ return NotImplemented
+
+ def __str__(self) -> str:
+ """
+ Returns the common enum names (full upper-case, underscore separated)
+ to the old format (separated by capitalization), e.g. NOT_ACCESSIBLE -> NotAccessible
+ This is a temporary measure and will be changed in a future release
+ to return the same format (full upper-case, underscore separated) like other Kinds
+ """
+
+ warnings.warn(
+ "The CompletionString.availability's return value will be changed in "
+ "a future release to be unified with other kinds. As a result, its string "
+ "representations will change to full upper-case, prefixed with the class name "
+ "(e.g. NotAvailable -> AvailabilityKind.NOT_AVAILABLE).",
----------------
Endilll wrote:
```
String representation of 'CompletionString.availability' will be changed in a future release from 'camelCase' to 'ALL_CAPS' to match other enums. 'CompletionString.availability' can be compared to 'AvailabilityKind' directly, without conversion to string.
```
(reflow as needed)
https://github.com/llvm/llvm-project/pull/160296
More information about the cfe-commits
mailing list