Commit d324e78c authored by Francis Herne's avatar Francis Herne
Browse files

Shorten class context range by one line.

Class contexts behave in some ways (tooltips, completion) as if they're
 one line longer than they ought to be:
```
a = 2
class M:
  a = "text"
b = a # tooltip of `a` says 'str', should be 'int'
a # 'int'
```
Expression-visitor doesn't have that problem, i.e. `b` is 'int' in the
 example above.

Shortening the class context range by one line fixes tooltips, uses and
 completions, and doesn't seem to break the expression visitor.

Test case "class_scope_end_outside" is fixed by this patch, the others
 are unchanged.

BUG: 309817
parent 1344f00a
......@@ -579,6 +579,23 @@ void PyCompletionTest::testFunctionDeclarationCompletion_data()
<< "Foo()";
}
void PyCompletionTest::testCompletionScopes()
{
QFETCH(QString, invokeCode);
QFETCH(QString, completionCode);
QFETCH(QString, expectedDeclaration);
QVERIFY(declarationInCompletionList(invokeCode, completionCode, expectedDeclaration));
}
void PyCompletionTest::testCompletionScopes_data()
{
QTest::addColumn<QString>("invokeCode");
QTest::addColumn<QString>("completionCode");
QTest::addColumn<QString>("expectedDeclaration");
QTest::newRow("class_scope_end_inside") << "class A:\n test1=1\nclass B:\n test2=1\nf = A()\nclass T:\n f = B()\n f%INVOKE" << ".%CURSOR" << "test2";
QTest::newRow("class_scope_end_outside") << "class A:\n test1=1\nclass B:\n test2=1\nf = A()\nclass T:\n f = B()\nf%INVOKE" << ".%CURSOR" << "test1";
}
void PyCompletionTest::testStringFormattingCompletion()
{
QFETCH(QString, completionCode);
......
......@@ -84,6 +84,8 @@ class PyCompletionTest : public QObject
void testAddImportCompletion_data();
void testFunctionDeclarationCompletion();
void testFunctionDeclarationCompletion_data();
void testCompletionScopes();
void testCompletionScopes_data();
void testStringFormattingCompletion();
void testStringFormattingCompletion_data();
void testStringFormatter();
......
......@@ -279,7 +279,7 @@ void ContextBuilder::openContextForClassDefinition(ClassDefinitionAst* node)
if ( start.line > node->startLine ) {
start = CursorInRevision(node->startLine + 1, 0);
}
RangeInRevision range(start, CursorInRevision(endLine + 1, 0));
RangeInRevision range(start, CursorInRevision(endLine, 0));
DUChainWriteLocker lock;
openContext(node, range, DUContext::Class, node->name);
currentContext()->setLocalScopeIdentifier(identifierForNode(node->name));
......
......@@ -827,6 +827,11 @@ void PyDUChainTest::testTypes_data()
QTest::newRow("arg_after_vararg") << "def func(x, y, *, z:int): return z\ncheckme = func()" << "int";
QTest::newRow("arg_after_vararg_with_default") << "def func(x=5, y=3, *, z:int): return z\ncheckme = func()" << "int";
QTest::newRow("class_scope_end_inside") << "a = str()\nclass M:\n"
" a = 2\n foo = a\n"
"checkme = M().foo" << "int";
QTest::newRow("class_scope_end_outside") << "a = str()\nclass M:\n a = 2\ncheckme = a" << "str";
QTest::newRow("list_access_right_open_slice") << "some_list = []; checkme = some_list[2:]" << "list";
QTest::newRow("list_access_left_open_slice") << "some_list = []; checkme = some_list[:2]" << "list";
QTest::newRow("list_access_closed_slice") << "some_list = []; checkme = some_list[2:17]" << "list";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment