[cfe-commits] r124959 - /cfe/trunk/bindings/python/clang/cindex.py

Tobias Grosser grosser at fim.uni-passau.de
Sat Feb 5 09:54:10 PST 2011


Author: grosser
Date: Sat Feb  5 11:54:10 2011
New Revision: 124959

URL: http://llvm.org/viewvc/llvm-project?rev=124959&view=rev
Log:
python bindings: Add support for different kind of completion chunks

Modified:
    cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=124959&r1=124958&r2=124959&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Feb  5 11:54:10 2011
@@ -720,13 +720,23 @@
 
 ###
 
-class CodeCompletionChunk:
+class CompletionChunk:
+    class Kind:
+        def __init__(self, name):
+            self.name = name
+
+        def __str__(self):
+            return self.name
+
+        def __repr__(self):
+            return "<ChunkKind: %s>" % self
+
     def __init__(self, completionString, key):
         self.cs = completionString
         self.key = key
 
     def __repr__(self):
-        return self.spelling
+        return "{'" + self.spelling + "', " + str(self.kind) + "}"
 
     @property
     def spelling(self):
@@ -734,7 +744,8 @@
 
     @property
     def kind(self):
-        return _clang_getCompletionChunkKind(self.cs, self.key)
+        res = _clang_getCompletionChunkKind(self.cs, self.key)
+        return completionChunkKindMap[res]
 
     @property
     def string(self):
@@ -745,14 +756,62 @@
         else:
           None
 
+    def isKindOptional(self):
+      return self.kind == completionChunkKindMap[0]
+
+    def isKindTypedText(self):
+      return self.kind == completionChunkKindMap[1]
+
+    def isKindPlaceHolder(self):
+      return self.kind == completionChunkKindMap[3]
+
+    def isKindInformative(self):
+      return self.kind == completionChunkKindMap[4]
+
+    def isKindResultType(self):
+      return self.kind == completionChunkKindMap[15]
+
+completionChunkKindMap = {
+            0: CompletionChunk.Kind("Optional"),
+            1: CompletionChunk.Kind("TypedText"),
+            2: CompletionChunk.Kind("Text"),
+            3: CompletionChunk.Kind("Placeholder"),
+            4: CompletionChunk.Kind("Informative"),
+            5: CompletionChunk.Kind("CurrentParameter"),
+            6: CompletionChunk.Kind("LeftParen"),
+            7: CompletionChunk.Kind("RightParen"),
+            8: CompletionChunk.Kind("LeftBracket"),
+            9: CompletionChunk.Kind("RightBracket"),
+            10: CompletionChunk.Kind("LeftBrace"),
+            11: CompletionChunk.Kind("RightBrace"),
+            12: CompletionChunk.Kind("LeftAngle"),
+            13: CompletionChunk.Kind("RightAngle"),
+            14: CompletionChunk.Kind("Comma"),
+            15: CompletionChunk.Kind("ResultType"),
+            16: CompletionChunk.Kind("Colon"),
+            17: CompletionChunk.Kind("SemiColon"),
+            18: CompletionChunk.Kind("Equal"),
+            19: CompletionChunk.Kind("HorizontalSpace"),
+            20: CompletionChunk.Kind("VerticalSpace")}
+
 class CompletionString(ClangObject):
+    class Availability:
+        def __init__(self, name):
+            self.name = name
+
+        def __str__(self):
+            return self.name
+
+        def __repr__(self):
+            return "<Availability: %s>" % self
+
     def __len__(self):
         return _clang_getNumCompletionChunks(self.obj)
 
     def __getitem__(self, key):
         if len(self) <= key:
             raise IndexError
-        return CodeCompletionChunk(self.obj, key)
+        return CompletionChunk(self.obj, key)
 
     @property
     def priority(self):
@@ -760,10 +819,18 @@
 
     @property
     def availability(self):
-        return _clang_getCompletionAvailability(self.obj)
+        res = _clang_getCompletionAvailability(self.obj)
+        return availabilityKinds[res]
 
     def __repr__(self):
-        return "".join([str(a) for a in self])
+        return " | ".join([str(a) for a in self]) \
+               + " || Priority: " + str(self.priority) \
+               + " || Availability: " + str(self.availability)
+
+availabilityKinds = {
+            0: CompletionChunk.Kind("Available"),
+            1: CompletionChunk.Kind("Deprecated"),
+            2: CompletionChunk.Kind("NotAvailable")}
 
 class CodeCompletionResult(Structure):
     _fields_ = [('cursorKind', c_int), ('completionString', c_object_p)]
@@ -1209,6 +1276,14 @@
 _clang_getCompletionChunkText.argtypes = [c_void_p, c_int]
 _clang_getCompletionChunkText.restype = _CXString
 
+_clang_getCompletionChunkKind = lib.clang_getCompletionChunkKind
+_clang_getCompletionChunkKind.argtypes = [c_void_p, c_int]
+_clang_getCompletionChunkKind.restype = c_int
+
+_clang_getCompletionChunkCompletionString = lib.clang_getCompletionChunkCompletionString
+_clang_getCompletionChunkCompletionString.argtypes = [c_void_p, c_int]
+_clang_getCompletionChunkCompletionString.restype = c_object_p
+
 _clang_getNumCompletionChunks = lib.clang_getNumCompletionChunks
 _clang_getNumCompletionChunks.argtypes = [c_void_p]
 _clang_getNumCompletionChunks.restype = c_int





More information about the cfe-commits mailing list