Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,16 @@ class _CXUnsavedFile(Structure):
}


# Converting the new enum names (full upper-case, underscore separated)
# to the old ones (separated by capitalization), e.g. RESULT_TYPE -> ResultType
def _kind_to_old_name(kind: BaseEnumeration):
# Remove underscores
components = kind.name.split("_")
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that this function has a new name, I found myself confused why it takes an enumerator and extracts a string out of it. I think it should just take a string instead.

# Upper-camel case each split component
components = [component.lower().capitalize() for component in components]
return "".join(components)


class CompletionChunk:
class Kind:
def __init__(self, name: str):
Expand Down Expand Up @@ -3165,9 +3175,9 @@ def priority(self) -> int:
return conf.lib.clang_getCompletionPriority(self.obj) # type: ignore [no-any-return]

@property
def availability(self) -> CompletionChunk.Kind:
def availability(self) -> AvailabilityKind:
res = conf.lib.clang_getCompletionAvailability(self.obj)
return availabilityKinds[res]
return AvailabilityKind.from_id(res)

@property
def briefComment(self) -> str:
Expand All @@ -3179,20 +3189,12 @@ def __repr__(self) -> str:
+ " || Priority: "
+ str(self.priority)
+ " || Availability: "
+ str(self.availability)
+ _kind_to_old_name(self.availability)
+ " || Brief comment: "
+ str(self.briefComment)
)


availabilityKinds = {
0: CompletionChunk.Kind("Available"),
1: CompletionChunk.Kind("Deprecated"),
2: CompletionChunk.Kind("NotAvailable"),
3: CompletionChunk.Kind("NotAccessible"),
}


class CodeCompletionResult(Structure):
_fields_ = [("cursorKind", c_int), ("completionString", c_object_p)]

Expand Down
Loading