summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2011-02-05 17:54:07 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2011-02-05 17:54:07 +0000
commit6d2a40c191f6029dd95f32eb355a345ffdc30352 (patch)
treea00db207fafa3594dfbaf06e1f4e967d0e385914 /bindings
parent0a16680067df298affe5da21dc7ea10c235f6e8d (diff)
python bindings: Get the string representation of a CompletionChunk
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124958 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py93
1 files changed, 84 insertions, 9 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 1982f6c1c4..ae4432831c 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -720,13 +720,78 @@ _clang_getDiagnosticFixIt.errcheck = _CXString.from_result
###
+class CodeCompletionChunk:
+ def __init__(self, completionString, key):
+ self.cs = completionString
+ self.key = key
+
+ def __repr__(self):
+ return self.spelling
+
+ @property
+ def spelling(self):
+ return _clang_getCompletionChunkText(self.cs, self.key).spelling
+
+ @property
+ def kind(self):
+ return _clang_getCompletionChunkKind(self.cs, self.key)
+
+ @property
+ def string(self):
+ res = _clang_getCompletionChunkCompletionString(self.cs, self.key)
+
+ if (res):
+ return CompletionString(res)
+ else:
+ None
+
+class CompletionString(ClangObject):
+ def __len__(self):
+ return _clang_getNumCompletionChunks(self.obj)
+
+ def __getitem__(self, key):
+ if len(self) <= key:
+ raise IndexError
+ return CodeCompletionChunk(self.obj, key)
+
+ @property
+ def priority(self):
+ return _clang_getCompletionPriority(self.obj)
+
+ @property
+ def availability(self):
+ return _clang_getCompletionAvailability(self.obj)
+
+ def __repr__(self):
+ return "".join([str(a) for a in self])
+
class CodeCompletionResult(Structure):
- _fields_ = [('cursorKind', c_int), ('completionString', c_void_p)]
+ _fields_ = [('cursorKind', c_int), ('completionString', c_object_p)]
+
+ def __repr__(self):
+ return str(CompletionString(self.completionString))
+
+ @property
+ def kind(self):
+ return CursorKind.from_id(self.cursorKind)
+
+ @property
+ def string(self):
+ return CompletionString(self.completionString)
class CCRStructure(Structure):
_fields_ = [('results', POINTER(CodeCompletionResult)),
('numResults', c_int)]
+ def __len__(self):
+ return self.numResults
+
+ def __getitem__(self, key):
+ if len(self) <= key:
+ raise IndexError
+
+ return self.results[key]
+
class CodeCompletionResults(ClangObject):
def __init__(self, ptr):
assert isinstance(ptr, POINTER(CCRStructure)) and ptr
@@ -740,14 +805,7 @@ class CodeCompletionResults(ClangObject):
@property
def results(self):
- class ResultsItr:
- def __init__(self, ccr):
- self.ccr = ccr
-
- def __len__(self):
- return self.ccr.ptr.contents.numResults
-
- return ResultsItr(self)
+ return self.ptr.contents
@property
def diagnostics(self):
@@ -1147,6 +1205,23 @@ _clang_codeCompleteGetDiagnostic = lib.clang_codeCompleteGetDiagnostic
_clang_codeCompleteGetDiagnostic.argtypes = [CodeCompletionResults, c_int]
_clang_codeCompleteGetDiagnostic.restype = Diagnostic
+_clang_getCompletionChunkText = lib.clang_getCompletionChunkText
+_clang_getCompletionChunkText.argtypes = [c_void_p, c_int]
+_clang_getCompletionChunkText.restype = _CXString
+
+_clang_getNumCompletionChunks = lib.clang_getNumCompletionChunks
+_clang_getNumCompletionChunks.argtypes = [c_void_p]
+_clang_getNumCompletionChunks.restype = c_int
+
+_clang_getCompletionAvailability = lib.clang_getCompletionAvailability
+_clang_getCompletionAvailability.argtypes = [c_void_p]
+_clang_getCompletionAvailability.restype = c_int
+
+_clang_getCompletionPriority = lib.clang_getCompletionPriority
+_clang_getCompletionPriority.argtypes = [c_void_p]
+_clang_getCompletionPriority.restype = c_int
+
+
###
__all__ = ['Index', 'TranslationUnit', 'Cursor', 'CursorKind',