mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Completion now always takes a NamePart as input.
This commit is contained in:
@@ -179,7 +179,9 @@ class Script(object):
|
|||||||
comps = []
|
comps = []
|
||||||
comp_dct = {}
|
comp_dct = {}
|
||||||
for c, s in set(completions):
|
for c, s in set(completions):
|
||||||
n = str(c.names[-1])
|
# TODO Remove this line. c should be a namepart even before that.
|
||||||
|
c = c.names[-1]
|
||||||
|
n = str(c)
|
||||||
if settings.case_insensitive_completion \
|
if settings.case_insensitive_completion \
|
||||||
and n.lower().startswith(like.lower()) \
|
and n.lower().startswith(like.lower()) \
|
||||||
or n.startswith(like):
|
or n.startswith(like):
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ class Completion(BaseDefinition):
|
|||||||
if isinstance(self._base, pr.Param):
|
if isinstance(self._base, pr.Param):
|
||||||
append += '='
|
append += '='
|
||||||
|
|
||||||
name = str(self._name.names[-1])
|
name = str(self._name)
|
||||||
if like_name:
|
if like_name:
|
||||||
name = name[self._like_name_length:]
|
name = name[self._like_name_length:]
|
||||||
return dot + name + append
|
return dot + name + append
|
||||||
@@ -457,7 +457,7 @@ class Completion(BaseDefinition):
|
|||||||
|
|
||||||
would return `isinstance`.
|
would return `isinstance`.
|
||||||
"""
|
"""
|
||||||
return unicode(self._name.names[-1])
|
return unicode(self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name_with_symbols(self):
|
def name_with_symbols(self):
|
||||||
@@ -575,8 +575,6 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, definition):
|
def __init__(self, evaluator, definition):
|
||||||
super(Definition, self).__init__(evaluator, definition, definition.start_pos)
|
super(Definition, self).__init__(evaluator, definition, definition.start_pos)
|
||||||
if not isinstance(definition, pr.NamePart):
|
|
||||||
raise NotImplementedError(definition)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import pydoc
|
import pydoc
|
||||||
import keyword
|
import keyword
|
||||||
|
|
||||||
|
from jedi.parser.representation import NamePart
|
||||||
from jedi._compatibility import is_py3
|
from jedi._compatibility import is_py3
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
|
from jedi.evaluate.helpers import FakeSubModule
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pydoc_data import topics as pydoc_topics
|
from pydoc_data import topics as pydoc_topics
|
||||||
@@ -40,7 +42,7 @@ def get_operator(string, pos):
|
|||||||
class KeywordName(object):
|
class KeywordName(object):
|
||||||
def __init__(self, parent, name, start_pos):
|
def __init__(self, parent, name, start_pos):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.names = [name]
|
self.names = [NamePart(FakeSubModule, name, self, (0, 0))]
|
||||||
self.start_pos = start_pos
|
self.start_pos = start_pos
|
||||||
|
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from jedi.common import source_to_unicode
|
|||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
from jedi.evaluate.cache import memoize_default, NO_DEFAULT
|
from jedi.evaluate.cache import memoize_default, NO_DEFAULT
|
||||||
|
from jedi.evaluate.helpers import FakeSubModule
|
||||||
|
|
||||||
|
|
||||||
class ModuleNotFound(Exception):
|
class ModuleNotFound(Exception):
|
||||||
@@ -368,12 +369,12 @@ class _Importer(object):
|
|||||||
pos = (part._line, part._column)
|
pos = (part._line, part._column)
|
||||||
try:
|
try:
|
||||||
self.import_path = (
|
self.import_path = (
|
||||||
pr.NamePart('flask_' + str(part), part.parent, pos),
|
pr.NamePart(FakeSubModule, 'flask_' + str(part), part.parent, pos),
|
||||||
) + orig_path[3:]
|
) + orig_path[3:]
|
||||||
return self._real_follow_file_system()
|
return self._real_follow_file_system()
|
||||||
except ModuleNotFound as e:
|
except ModuleNotFound as e:
|
||||||
self.import_path = (
|
self.import_path = (
|
||||||
pr.NamePart('flaskext', part.parent, pos),
|
pr.NamePart(FakeSubModule, 'flaskext', part.parent, pos),
|
||||||
) + orig_path[2:]
|
) + orig_path[2:]
|
||||||
return self._real_follow_file_system()
|
return self._real_follow_file_system()
|
||||||
return self._real_follow_file_system()
|
return self._real_follow_file_system()
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ class ArrayMethod(IterableWrapper):
|
|||||||
@property
|
@property
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def names(self):
|
def names(self):
|
||||||
return [pr.NamePart(unicode(n), self, n.start_pos) for n in self.name.names]
|
# TODO remove this method, we need the ArrayMethod input to be a NamePart.
|
||||||
|
return [pr.NamePart(self.name._sub_module, unicode(n), self, n.start_pos) for n in self.name.names]
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# Set access privileges:
|
# Set access privileges:
|
||||||
|
|||||||
@@ -294,7 +294,8 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
@property
|
@property
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def names(self):
|
def names(self):
|
||||||
return [pr.NamePart(unicode(n), self, n.start_pos) for n in self.var.names]
|
return [pr.NamePart(helpers.FakeSubModule, unicode(n), self, n.start_pos)
|
||||||
|
for n in self.var.names]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
|
|||||||
@@ -1458,11 +1458,12 @@ class NamePart(object):
|
|||||||
# Unfortunately there's no way to use slots for str (non-zero __itemsize__)
|
# Unfortunately there's no way to use slots for str (non-zero __itemsize__)
|
||||||
# -> http://utcc.utoronto.ca/~cks/space/blog/python/IntSlotsPython3k
|
# -> http://utcc.utoronto.ca/~cks/space/blog/python/IntSlotsPython3k
|
||||||
# Therefore don't subclass `str`.
|
# Therefore don't subclass `str`.
|
||||||
__slots__ = ('parent', '_string', '_line', '_column')
|
__slots__ = ('_sub_module', 'parent', '_string', '_line', '_column')
|
||||||
|
|
||||||
def __init__(self, string, parent, start_pos):
|
def __init__(self, sub_module, string, parent, start_pos):
|
||||||
self._string = string
|
self._string = string
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self._sub_module = sub_module
|
||||||
self._line = start_pos[0]
|
self._line = start_pos[0]
|
||||||
self._column = start_pos[1]
|
self._column = start_pos[1]
|
||||||
|
|
||||||
@@ -1489,7 +1490,7 @@ class NamePart(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def start_pos(self):
|
def start_pos(self):
|
||||||
offset = self.parent._sub_module.line_offset
|
offset = self._sub_module.line_offset
|
||||||
return offset + self._line, self._column
|
return offset + self._line, self._column
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1512,7 +1513,7 @@ class Name(Simple):
|
|||||||
# (seen by using the profiler).
|
# (seen by using the profiler).
|
||||||
self._get_code = ".".join(n[0] for n in names)
|
self._get_code = ".".join(n[0] for n in names)
|
||||||
|
|
||||||
names = tuple(NamePart(n[0], self, n[1]) for n in names)
|
names = tuple(NamePart(module, n[0], self, n[1]) for n in names)
|
||||||
self.names = names
|
self.names = names
|
||||||
|
|
||||||
def get_code(self):
|
def get_code(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user