[cfe-commits] r163966 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_code_completion.py

Dmitri Gribenko gribozavr at gmail.com
Sat Sep 15 04:56:33 PDT 2012


Author: gribozavr
Date: Sat Sep 15 06:56:32 2012
New Revision: 163966

URL: http://llvm.org/viewvc/llvm-project?rev=163966&view=rev
Log:
Add bindings for clang_getCompletionBriefComment to cindex.py.

Added:
    cfe/trunk/bindings/python/tests/cindex/test_code_completion.py
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=163966&r1=163965&r2=163966&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Sep 15 06:56:32 2012
@@ -1735,10 +1735,15 @@
         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 @@
     # 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 @@
             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 @@
         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 @@
    [c_void_p],
    c_int),
 
+  ("clang_getCompletionBriefComment",
+   [c_void_p],
+   _CXString),
+
   ("clang_getCompletionChunkCompletionString",
    [c_void_p, c_int],
    c_object_p),

Added: cfe/trunk/bindings/python/tests/cindex/test_code_completion.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_code_completion.py?rev=163966&view=auto
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_code_completion.py (added)
+++ cfe/trunk/bindings/python/tests/cindex/test_code_completion.py Sat Sep 15 06:56:32 2012
@@ -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
+





More information about the cfe-commits mailing list