forked from OSchip/llvm-project
Python bindings: Add missing availability kind.
Patch by Leo Liu, test case by me. llvm-svn: 165374
This commit is contained in:
parent
be7c6f23a2
commit
7c52cc4c77
|
@ -1750,7 +1750,8 @@ class CompletionString(ClangObject):
|
||||||
availabilityKinds = {
|
availabilityKinds = {
|
||||||
0: CompletionChunk.Kind("Available"),
|
0: CompletionChunk.Kind("Available"),
|
||||||
1: CompletionChunk.Kind("Deprecated"),
|
1: CompletionChunk.Kind("Deprecated"),
|
||||||
2: CompletionChunk.Kind("NotAvailable")}
|
2: CompletionChunk.Kind("NotAvailable"),
|
||||||
|
3: CompletionChunk.Kind("NotAccessible")}
|
||||||
|
|
||||||
class CodeCompletionResult(Structure):
|
class CodeCompletionResult(Structure):
|
||||||
_fields_ = [('cursorKind', c_int), ('completionString', c_object_p)]
|
_fields_ = [('cursorKind', c_int), ('completionString', c_object_p)]
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
from clang.cindex import TranslationUnit
|
from clang.cindex import TranslationUnit
|
||||||
|
|
||||||
|
def check_completion_results(cr, expected):
|
||||||
|
assert cr is not None
|
||||||
|
assert len(cr.diagnostics) == 0
|
||||||
|
|
||||||
|
completions = [str(c) for c in cr.results]
|
||||||
|
|
||||||
|
for c in expected:
|
||||||
|
assert c in completions
|
||||||
|
|
||||||
def test_code_complete():
|
def test_code_complete():
|
||||||
files = [('fake.c', """
|
files = [('fake.c', """
|
||||||
/// Aaa.
|
/// Aaa.
|
||||||
|
@ -17,19 +26,50 @@ void f() {
|
||||||
options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
|
options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
|
||||||
|
|
||||||
cr = tu.codeComplete('fake.c', 9, 1, unsaved_files=files, include_brief_comments=True)
|
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 = [
|
expected = [
|
||||||
"{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
|
"{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
|
||||||
"{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
|
"{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
|
||||||
"{'return', TypedText} || Priority: 40 || Availability: Available || Brief comment: None"
|
"{'return', TypedText} || Priority: 40 || Availability: Available || Brief comment: None"
|
||||||
]
|
]
|
||||||
|
check_completion_results(cr, expected)
|
||||||
|
|
||||||
for c in expected:
|
def test_code_complete_availability():
|
||||||
assert c in completions
|
files = [('fake.cpp', """
|
||||||
|
class P {
|
||||||
|
protected:
|
||||||
|
int member;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Q : public P {
|
||||||
|
public:
|
||||||
|
using P::member;
|
||||||
|
};
|
||||||
|
|
||||||
|
void f(P x, Q y) {
|
||||||
|
x.; // member is inaccessible
|
||||||
|
y.; // member is accessible
|
||||||
|
}
|
||||||
|
""")]
|
||||||
|
|
||||||
|
tu = TranslationUnit.from_source('fake.cpp', ['-std=c++98'], unsaved_files=files)
|
||||||
|
|
||||||
|
cr = tu.codeComplete('fake.cpp', 12, 5, unsaved_files=files)
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
"{'const', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
|
||||||
|
"{'volatile', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
|
||||||
|
"{'operator', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
|
||||||
|
"{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None",
|
||||||
|
"{'Q', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None"
|
||||||
|
]
|
||||||
|
check_completion_results(cr, expected)
|
||||||
|
|
||||||
|
cr = tu.codeComplete('fake.cpp', 13, 5, unsaved_files=files)
|
||||||
|
expected = [
|
||||||
|
"{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None",
|
||||||
|
"{'P &', ResultType} | {'operator=', TypedText} | {'(', LeftParen} | {'const P &', Placeholder} | {')', RightParen} || Priority: 34 || Availability: Available || Brief comment: None",
|
||||||
|
"{'int', ResultType} | {'member', TypedText} || Priority: 35 || Availability: NotAccessible || Brief comment: None",
|
||||||
|
"{'void', ResultType} | {'~P', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 34 || Availability: Available || Brief comment: None"
|
||||||
|
]
|
||||||
|
check_completion_results(cr, expected)
|
||||||
|
|
Loading…
Reference in New Issue