diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-09-15 11:56:32 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-09-15 11:56:32 +0000 |
commit | c69e067f24aa64a277ca4d6048a3165cbb23dbe7 (patch) | |
tree | 0625be338412328009b7aea93ca15b8ef18881ee /bindings | |
parent | bc57b108b2253e26b83768dba196c28564952f18 (diff) |
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
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/python/clang/cindex.py | 30 | ||||
-rw-r--r-- | bindings/python/tests/cindex/test_code_completion.py | 35 |
2 files changed, 63 insertions, 2 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index d265f7e520..770ff0e0fe 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -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), diff --git a/bindings/python/tests/cindex/test_code_completion.py b/bindings/python/tests/cindex/test_code_completion.py new file mode 100644 index 0000000000..b4678bd385 --- /dev/null +++ b/bindings/python/tests/cindex/test_code_completion.py @@ -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 + |