mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
add keyword_names method to keyword module (includes test), fixes #248
This commit is contained in:
@@ -138,11 +138,11 @@ class Script(object):
|
||||
if (u.relative_count > 0 or u.from_ns) and not re.search(
|
||||
r'(,|from)\s*$|import\s+$', completion_line):
|
||||
completions += ((k, bs) for k
|
||||
in keywords.get_keywords('import'))
|
||||
in keywords.keyword_names('import'))
|
||||
|
||||
if not path and not isinstance(u, pr.Import):
|
||||
# add keywords
|
||||
completions += ((k, bs) for k in keywords.get_keywords(
|
||||
completions += ((k, bs) for k in keywords.keyword_names(
|
||||
all=True))
|
||||
|
||||
needs_dot = not dot and path
|
||||
@@ -324,7 +324,7 @@ class Script(object):
|
||||
scopes = resolve_import_paths(scopes)
|
||||
|
||||
# add keywords
|
||||
scopes |= keywords.get_keywords(string=goto_path, pos=self.pos)
|
||||
scopes |= keywords.keywords(string=goto_path, pos=self.pos)
|
||||
|
||||
d = set([api_classes.Definition(s) for s in scopes
|
||||
if not isinstance(s, imports.ImportPath._GlobalNamespace)])
|
||||
|
||||
@@ -4,6 +4,7 @@ import pydoc
|
||||
import keyword
|
||||
|
||||
from jedi._compatibility import is_py3k
|
||||
from jedi import parsing_representation as pr
|
||||
from jedi import common
|
||||
import builtin
|
||||
|
||||
@@ -19,7 +20,7 @@ else:
|
||||
keys = keyword.kwlist + ['None', 'False', 'True']
|
||||
|
||||
|
||||
def get_keywords(string='', pos=(0, 0), all=False):
|
||||
def keywords(string='', pos=(0, 0), all=False):
|
||||
if all:
|
||||
return set([Keyword(k, pos) for k in keys])
|
||||
if string in keys:
|
||||
@@ -27,6 +28,15 @@ def get_keywords(string='', pos=(0, 0), all=False):
|
||||
return set()
|
||||
|
||||
|
||||
def keyword_names(*args, **kwargs):
|
||||
kwds = []
|
||||
for k in keywords(*args, **kwargs):
|
||||
start = k.start_pos
|
||||
end = start[0], start[1] + len(k.name)
|
||||
kwds.append(pr.Name(k.parent, [(k.name, start)], start, end, k))
|
||||
return kwds
|
||||
|
||||
|
||||
def get_operator(string, pos):
|
||||
return Keyword(string, pos)
|
||||
|
||||
|
||||
@@ -81,6 +81,11 @@ class TestRegression(TestBase):
|
||||
r = list(self.goto_definitions("asfdasfd", (1, 1)))
|
||||
assert len(r) == 0
|
||||
|
||||
k = self.completions("fro")[0]
|
||||
imp_start = '\nThe ``import'
|
||||
assert k.raw_doc.startswith(imp_start)
|
||||
assert k.doc.startswith(imp_start)
|
||||
|
||||
def test_operator_doc(self):
|
||||
r = list(self.goto_definitions("a == b", (1, 3)))
|
||||
assert len(r) == 1
|
||||
@@ -447,7 +452,6 @@ class TestRegression(TestBase):
|
||||
|
||||
|
||||
class TestDocstring(TestBase):
|
||||
|
||||
def test_function_doc(self):
|
||||
defs = self.goto_definitions("""
|
||||
def func():
|
||||
@@ -538,7 +542,6 @@ class TestSpeed(TestBase):
|
||||
|
||||
|
||||
class TestInterpreterAPI(unittest.TestCase):
|
||||
|
||||
def check_interpreter_complete(self, source, namespace, completions,
|
||||
**kwds):
|
||||
script = api.Interpreter(source, [namespace], **kwds)
|
||||
|
||||
Reference in New Issue
Block a user