1
0
forked from VimPlug/jedi

basic work to get renaming to work in other modules/folders.

This commit is contained in:
David Halter
2012-09-20 00:25:32 +02:00
parent f9595d7897
commit 076a537801
3 changed files with 44 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ Sorry to everyone who is reading this code. Especially the array parts are
really cryptic and not understandable. It's just a hack, that turned out to be really cryptic and not understandable. It's just a hack, that turned out to be
working quite good. working quite good.
""" """
from __future__ import with_statement
import re import re
import os import os
@@ -15,12 +16,44 @@ import evaluate
import helpers import helpers
import settings import settings
import debug import debug
import builtin
# This is something like the sys.path, but only for searching params. It means # This is something like the sys.path, but only for searching params. It means
# that this is the order in which Jedi searches params. # that this is the order in which Jedi searches params.
search_param_modules = ['.'] search_param_modules = ['.']
search_param_cache = {} search_param_cache = {}
def get_directory_modules_for_name(mods, name):
"""
Search a name in the directories of modules.
"""
def check_python_file(path):
try:
return builtin.CachedModule.cache[path][1].module
except KeyError:
return check_fs(path)
def check_fs(path):
with open(path) as f:
source = f.read()
if name in source:
return modules.Module(path, source).parser.module
mod_paths = set()
for m in mods:
mod_paths.add(m.path)
new = set()
for p in mod_paths:
d = os.path.dirname(p)
for entry in os.listdir(d):
if entry not in mod_paths:
if entry.endswith('.py'):
c = check_python_file(d + os.path.sep + entry)
if c is not None:
new.add(c)
return set(mods) | new
def search_param_memoize(func): def search_param_memoize(func):
""" """
@@ -302,7 +335,7 @@ class ArrayInstance(parsing.Base):
return items return items
def related_names(definitions, search_name, modules): def related_names(definitions, search_name, mods):
def check_call(call): def check_call(call):
result = [] result = []
follow = [] # There might be multiple search_name's in one call_path follow = [] # There might be multiple search_name's in one call_path
@@ -330,9 +363,9 @@ def related_names(definitions, search_name, modules):
return result return result
mods |= set([d.get_parent_until() for d in definitions])
names = [] names = []
# TODO check modules in the same directoy for m in get_directory_modules_for_name(mods, search_name):
for m in modules:
if not m.path.endswith('.py'): if not m.path.endswith('.py'):
# don't search for names in builtin modules # don't search for names in builtin modules
continue continue

View File

@@ -17,8 +17,8 @@ class Module(builtin.CachedModule):
""" """
Manages all files, that are parsed and caches them. Manages all files, that are parsed and caches them.
:param source: The source code of the file.
:param path: The module path of the file. :param path: The module path of the file.
:param source: The source code of the file.
""" """
def __init__(self, path, source): def __init__(self, path, source):
super(Module, self).__init__(path=path) super(Module, self).__init__(path=path)

View File

@@ -69,3 +69,10 @@ colorama
#< 3 #< 3
import abc import abc
from import_tree import rename1
#< (78,8) (3,0)
rename1.abc