1
0
forked from VimPlug/jedi
This commit is contained in:
David Halter
2013-02-06 13:00:23 +01:00
parent 8cf783f2c3
commit 69137a48f0
6 changed files with 26 additions and 19 deletions

View File

@@ -205,7 +205,8 @@ class Completion(BaseDefinition):
@property
def word(self):
"""
Similar to :meth:`Completion.complete`, but return the whole word, e.g. ::
Similar to :meth:`Completion.complete`, but return the whole word, for
example::
>>> isinstan
@@ -235,11 +236,11 @@ class Completion(BaseDefinition):
def follow_definition(self):
"""
Return the original definitions. I strongly recommend not using it for
your completions, because it might slow down |jedi|. If you want to read
only a few objects (<=20), it might be useful, especially to
get the original docstrings. The basic problem of this function is
that it follows all results. This means with 1000 completions (e.g.
numpy), it's just PITA-slow.
your completions, because it might slow down |jedi|. If you want to
read only a few objects (<=20), it might be useful, especially to get
the original docstrings. The basic problem of this function is that it
follows all results. This means with 1000 completions (e.g. numpy),
it's just PITA-slow.
"""
if self._followed_definitions is None:
if self.definition.isinstance(pr.Statement):

View File

@@ -29,6 +29,7 @@ DOCSTRING_RETURN_PATTERNS = [
REST_ROLE_PATTERN = re.compile(r':[^`]+:`([^`]+)`')
#@cache.memoize_default() # TODO add
def follow_param(param):
func = param.parent_function
@@ -68,7 +69,8 @@ def search_param_in_docstr(docstr, param_str):
"""
# look at #40 to see definitions of those params
patterns = [ re.compile(p % re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS ]
patterns = [re.compile(p % re.escape(param_str))
for p in DOCSTRING_PARAM_PATTERNS]
for pattern in patterns:
match = pattern.search(docstr)
if match:
@@ -114,6 +116,7 @@ def find_return_types(func):
p.user_stmt.parent = func
return list(evaluate.follow_statement(p.user_stmt))
def search_return_in_docstr(code):
for p in DOCSTRING_RETURN_PATTERNS:
match = p.search(code)

View File

@@ -373,13 +373,15 @@ def source_to_unicode(source, encoding=None):
http://docs.python.org/2/reference/lexical_analysis.html#encoding-\
declarations
"""
byte_mark = '\xef\xbb\xbf' if is_py25 else literal_eval(r"b'\xef\xbb\xbf'")
byte_mark = '\xef\xbb\xbf' if is_py25 else \
literal_eval(r"b'\xef\xbb\xbf'")
if source.startswith(byte_mark):
# UTF-8 byte-order mark
return 'utf-8'
first_two_lines = re.match(r'(?:[^\n]*\n){0,2}', str(source)).group(0)
possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)", first_two_lines)
possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)",
first_two_lines)
if possible_encoding:
return possible_encoding.group(1)
else:

View File

@@ -65,6 +65,7 @@ def _rename(names, replace_str):
""" For both rename and inline. """
order = sorted(names, key=lambda x: (x.module_path, x.start_pos),
reverse=True)
def process(path, old_lines, new_lines):
if new_lines is not None: # goto next file, save last
dct[path] = path, old_lines, new_lines
@@ -130,7 +131,6 @@ def extract(script, new_name):
end_line = new_lines[end_pos[0] - 1]
text += '\n' + end_line[:end_pos[1]]
# remove code from new lines
t = text.lstrip()
del_start = start_pos[1] + len(text) - len(t)
@@ -194,7 +194,6 @@ def inline(script):
if len(stmt.set_vars) == 1:
line = line[:stmt.start_pos[1]] + line[stmt.end_pos[1]:]
dct = _rename(inlines, replace_str)
# remove the empty line
new_lines = dct[script.source_path][2]

View File

@@ -124,11 +124,13 @@ Use filesystem cache to save once parsed files with pickle.
"""
if platform.system().lower() == 'windows':
_cache_directory = os.path.join(os.getenv('APPDATA') or '~', 'Jedi', 'Jedi')
_cache_directory = os.path.join(os.getenv('APPDATA') or '~', 'Jedi',
'Jedi')
elif platform.system().lower() == 'darwin':
_cache_directory = os.path.join('~', 'Library', 'Caches', 'Jedi')
else:
_cache_directory = os.path.join(os.getenv('XDG_CACHE_HOME') or '~/.cache', 'jedi')
_cache_directory = os.path.join(os.getenv('XDG_CACHE_HOME') or '~/.cache',
'jedi')
cache_directory = os.path.expanduser(_cache_directory)
"""
The path where all the caches can be found.