Add bindings for clang_getCompletionBriefComment to cindex.py.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163966 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dmitri Gribenko 2012-09-15 11:56:32 +00:00
Родитель bc57b108b2
Коммит c69e067f24
2 изменённых файлов: 63 добавлений и 2 удалений

Просмотреть файл

@ -1735,10 +1735,15 @@ class CompletionString(ClangObject):
res = conf.lib.clang_getCompletionAvailability(self.obj)
return availabilityKinds[res]
@property
def briefComment(self):
return conf.lib.clang_getCompletionBriefComment(self.obj)
def __repr__(self):
return " | ".join([str(a) for a in self]) \
+ " || Priority: " + str(self.priority) \
+ " || Availability: " + str(self.availability)
+ " || Availability: " + str(self.availability) \
+ " || Brief comment: " + str(self.briefComment.spelling)
availabilityKinds = {
0: CompletionChunk.Kind("Available"),
@ -1877,6 +1882,10 @@ class TranslationUnit(ClangObject):
# searching for declarations/definitions.
PARSE_SKIP_FUNCTION_BODIES = 64
# Used to indicate that brief documentation comments should be included
# into the set of code completions returned from this translation unit.
PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION = 128
@classmethod
def from_source(cls, filename, args=None, unsaved_files=None, options=0,
index=None):
@ -2149,7 +2158,9 @@ class TranslationUnit(ClangObject):
raise TranslationUnitSaveError(result,
'Error saving TranslationUnit.')
def codeComplete(self, path, line, column, unsaved_files=None, options=0):
def codeComplete(self, path, line, column, unsaved_files=None,
include_macros=False, include_code_patterns=False,
include_brief_comments=False):
"""
Code complete in this translation unit.
@ -2158,6 +2169,17 @@ class TranslationUnit(ClangObject):
and the second should be the contents to be substituted for the
file. The contents may be passed as strings or file objects.
"""
options = 0
if include_macros:
options += 1
if include_code_patterns:
options += 2
if include_brief_comments:
options += 4
if unsaved_files is None:
unsaved_files = []
@ -2556,6 +2578,10 @@ functionList = [
[c_void_p],
c_int),
("clang_getCompletionBriefComment",
[c_void_p],
_CXString),
("clang_getCompletionChunkCompletionString",
[c_void_p, c_int],
c_object_p),

Просмотреть файл

@ -0,0 +1,35 @@
from clang.cindex import TranslationUnit
def test_code_complete():
files = [('fake.c', """
/// Aaa.
int test1;
/// Bbb.
void test2(void);
void f() {
}
""")]
tu = TranslationUnit.from_source('fake.c', ['-std=c99'], unsaved_files=files,
options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
cr = tu.codeComplete('fake.c', 9, 1, unsaved_files=files, include_brief_comments=True)
assert cr is not None
assert len(cr.diagnostics) == 0
completions = []
for c in cr.results:
completions.append(str(c))
expected = [
"{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
"{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
"{'return', TypedText} || Priority: 40 || Availability: Available || Brief comment: None"
]
for c in expected:
assert c in completions