Author: Jannick Kremer
Date: 2026-10-08T08:52:59+09:00
New Revision: 3991c3d79144c40e0f33ffe1b1ba5dc2b08b3d2a

URL: 
https://github.com/llvm/llvm-project/commit/3991c3d79144c40e0f33ffe1b1ba5dc2b08b3d2a
DIFF: 
https://github.com/llvm/llvm-project/commit/3991c3d79144c40e0f33ffe1b1ba5dc2b08b3d2a.diff

LOG: [libclang/python] Fold CCRStructure into CodeCompletionResults (#224678)

This completes the fifth and last step of
https://github.com/llvm/llvm-project/issues/156680
This change is a follow-up to
https://github.com/llvm/llvm-project/pull/177764, following the release
branching, to ensure a one release-cycle deprecation period.

Added: 
    

Modified: 
    clang/bindings/python/clang/cindex.py
    clang/bindings/python/tests/cindex/test_code_completion.py
    clang/docs/ReleaseNotes.md

Removed: 
    


################################################################################
diff  --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 27216a5703d5f..0a3e7de7a884a 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3233,11 +3233,11 @@ def string(self) -> CompletionString:
         return CompletionString(self.completionString)
 
 
-class CCRStructure(Structure):
+class CodeCompletionResults(Structure):
     _fields_ = [("results", POINTER(CodeCompletionResult)), ("numResults", 
c_uint)]
 
-    results: NoSliceSequence[CodeCompletionResult]
-    numResults: int
+    def __del__(self) -> None:
+        conf.lib.clang_disposeCodeCompleteResults(byref(self))
 
     def __len__(self) -> int:
         return self.numResults
@@ -3248,40 +3248,6 @@ def __getitem__(self, key: int) -> CodeCompletionResult:
 
         return self.results[key]
 
-
-class CodeCompletionResults(OpaqueClangObject):
-    def __init__(self, ptr: _Pointer[CCRStructure]):
-        assert isinstance(ptr, POINTER(CCRStructure)) and ptr
-        self.ptr = self._as_parameter_ = ptr
-
-    def from_param(self) -> _Pointer[CCRStructure]:
-        return self._as_parameter_
-
-    def __del__(self) -> None:
-        conf.lib.clang_disposeCodeCompleteResults(self)
-
-    def __len__(self) -> int:
-        return self.ptr.contents.numResults
-
-    def __getitem__(self, key: int) -> CodeCompletionResult:
-        if len(self) <= key:
-            raise IndexError
-
-        return self.ptr.contents.results[key]
-
-    @property
-    def results(self) -> CCRStructure:
-        warnings.warn(
-            "'CodeCompletionResults.results' will become an implementation 
detail "
-            "with changed behavior in a future release and should not be used 
directly. "
-            "Existing uses of 'CodeCompletionResults.results' should be 
changed "
-            "to directly use 'CodeCompletionResults': it nows supports 
'__len__' "
-            "and '__getitem__', so it can be used the same as "
-            "'CodeCompletionResults.results'.",
-            DeprecationWarning,
-        )
-        return self.ptr.contents
-
     @property
     def diagnostics(self) -> NoSliceSequence[Diagnostic]:
         class DiagnosticsItr:
@@ -3289,10 +3255,12 @@ def __init__(self, ccr: CodeCompletionResults):
                 self.ccr = ccr
 
             def __len__(self) -> int:
-                return 
int(conf.lib.clang_codeCompleteGetNumDiagnostics(self.ccr))
+                return int(
+                    
conf.lib.clang_codeCompleteGetNumDiagnostics(byref(self.ccr))
+                )
 
             def __getitem__(self, key: int) -> Diagnostic:
-                return conf.lib.clang_codeCompleteGetDiagnostic(self.ccr, key) 
 # type: ignore [no-any-return]
+                return 
conf.lib.clang_codeCompleteGetDiagnostic(byref(self.ccr), key)  # type: ignore 
[no-any-return]
 
         return DiagnosticsItr(self)
 
@@ -3730,7 +3698,7 @@ def codeComplete(
             options,
         )
         if ptr:
-            return CodeCompletionResults(ptr)
+            return ptr.contents
         return None
 
     def get_tokens(
@@ -4184,10 +4152,14 @@ def set_property(self, property, value):
     (
         "clang_codeCompleteAt",
         [TranslationUnit, c_interop_string, c_int, c_int, c_void_p, c_int, 
c_int],
-        POINTER(CCRStructure),
+        POINTER(CodeCompletionResults),
+    ),
+    (
+        "clang_codeCompleteGetDiagnostic",
+        [POINTER(CodeCompletionResults), c_int],
+        Diagnostic,
     ),
-    ("clang_codeCompleteGetDiagnostic", [CodeCompletionResults, c_int], 
Diagnostic),
-    ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
+    ("clang_codeCompleteGetNumDiagnostics", [POINTER(CodeCompletionResults)], 
c_int),
     ("clang_createIndex", [c_int, c_int], c_object_p),
     ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
     ("clang_CXRewriter_create", [TranslationUnit], c_object_p),
@@ -4215,7 +4187,7 @@ def set_property(self, property, value):
     ("clang_EnumDecl_isScoped", [Cursor], c_uint),
     ("clang_defaultDiagnosticDisplayOptions", [], c_uint),
     ("clang_defaultSaveOptions", [TranslationUnit], c_uint),
-    ("clang_disposeCodeCompleteResults", [CodeCompletionResults]),
+    ("clang_disposeCodeCompleteResults", [POINTER(CodeCompletionResults)]),
     # ("clang_disposeCXTUResourceUsage",
     #  [CXTUResourceUsage]),
     ("clang_disposeDiagnostic", [Diagnostic]),

diff  --git a/clang/bindings/python/tests/cindex/test_code_completion.py 
b/clang/bindings/python/tests/cindex/test_code_completion.py
index f89927e50ab0a..672c96f57a5b7 100644
--- a/clang/bindings/python/tests/cindex/test_code_completion.py
+++ b/clang/bindings/python/tests/cindex/test_code_completion.py
@@ -2,13 +2,11 @@
     AvailabilityKind,
     CompletionChunk,
     CompletionChunkKind,
-    CompletionString,
     TranslationUnit,
 )
 
 import unittest
 from pathlib import Path
-import warnings
 
 
 class TestCodeCompletion(unittest.TestCase):

diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index bac1ce6dc4553..3fa6102b6ec72 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -148,6 +148,11 @@ features cannot lower the translation-unit ABI level;
   As a result, the `__str__` representation of its return values changed.
   Like other libclang enums, it now follows the 
`CompletionChunkKind.VARIANT_NAME` scheme instead of `VariantName`.
 
+- Change the behavior of the deprecated `CodeCompletionResults.results` 
property.
+  It is used as an implementation detail now and should not be accessed 
directly.
+  Existing uses of it should be changed to use `CodeCompletionResults` 
directly:
+  it nows supports `__len__` and `__getitem__`, so it can be used the same as 
`CodeCompletionResults.results` previously.
+
 - `Cursor` instance's `enum_value` method now returns 1 instead of -1 for 
`true` bool enumeration values
 
 ### OpenCL Potentially Breaking Changes


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to