python bindings: Get the string representation of a CompletionChunk

llvm-svn: 124958
This commit is contained in:
Tobias Grosser 2011-02-05 17:54:07 +00:00
parent 85bb48fce7
commit b0949a17a0
1 changed files with 84 additions and 9 deletions

View File

@ -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',