mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
Follow up from the last async issue, fixes more related things about #1092.
This commit is contained in:
@@ -57,7 +57,8 @@ def get_user_scope(module_context, position):
|
|||||||
def scan(scope):
|
def scan(scope):
|
||||||
for s in scope.children:
|
for s in scope.children:
|
||||||
if s.start_pos <= position <= s.end_pos:
|
if s.start_pos <= position <= s.end_pos:
|
||||||
if isinstance(s, (tree.Scope, tree.Flow)):
|
if isinstance(s, (tree.Scope, tree.Flow)) \
|
||||||
|
or s.type in ('async_stmt', 'async_funcdef'):
|
||||||
return scan(s) or s
|
return scan(s) or s
|
||||||
elif s.type in ('suite', 'decorated'):
|
elif s.type in ('suite', 'decorated'):
|
||||||
return scan(s)
|
return scan(s)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def test_in_whitespace(Script):
|
def test_in_whitespace(Script):
|
||||||
code = dedent('''
|
code = dedent('''
|
||||||
@@ -118,3 +120,20 @@ def test_generator(Script):
|
|||||||
def test_in_comment(Script):
|
def test_in_comment(Script):
|
||||||
assert Script(" # Comment").completions()
|
assert Script(" # Comment").completions()
|
||||||
assert Script("max_attr_value = int(2) # Cast to int for spe").completions()
|
assert Script("max_attr_value = int(2) # Cast to int for spe").completions()
|
||||||
|
|
||||||
|
|
||||||
|
def test_async(Script, environment):
|
||||||
|
if environment.version_info < (3, 5):
|
||||||
|
pytest.skip()
|
||||||
|
|
||||||
|
code = dedent('''
|
||||||
|
foo = 3
|
||||||
|
async def x():
|
||||||
|
hey = 3
|
||||||
|
ho'''
|
||||||
|
)
|
||||||
|
print(code)
|
||||||
|
comps = Script(code, column=4).completions()
|
||||||
|
names = [c.name for c in comps]
|
||||||
|
assert 'foo' in names
|
||||||
|
assert 'hey' in names
|
||||||
|
|||||||
Reference in New Issue
Block a user