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"),
# 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):
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.
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 = []
[c_void_p],
c_int),
+ ("clang_getCompletionBriefComment",
+ [c_void_p],
+ _CXString),
+
("clang_getCompletionChunkCompletionString",
[c_void_p, c_int],
c_object_p),
--- /dev/null
+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
+