mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
functions -> api
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
from functions import *
|
from api import *
|
||||||
import settings
|
import settings
|
||||||
|
|||||||
@@ -177,8 +177,8 @@ if 1:
|
|||||||
buf_path = vim.current.buffer.name
|
buf_path = vim.current.buffer.name
|
||||||
source = '\n'.join(vim.current.buffer)
|
source = '\n'.join(vim.current.buffer)
|
||||||
try:
|
try:
|
||||||
definitions = functions.get_definition(source, row, column, buf_path)
|
definitions = api.get_definition(source, row, column, buf_path)
|
||||||
except functions.NotFoundError:
|
except api.NotFoundError:
|
||||||
definitions = []
|
definitions = []
|
||||||
except Exception:
|
except Exception:
|
||||||
# print to stdout, will be in :messages
|
# print to stdout, will be in :messages
|
||||||
@@ -431,7 +431,7 @@ import re
|
|||||||
|
|
||||||
# normally you should import jedi. jedi-vim is an exception, because you can
|
# normally you should import jedi. jedi-vim is an exception, because you can
|
||||||
# copy that directly into the .vim directory.
|
# copy that directly into the .vim directory.
|
||||||
import functions
|
import api
|
||||||
|
|
||||||
temp_rename = None # used for jedi#rename
|
temp_rename = None # used for jedi#rename
|
||||||
|
|
||||||
@@ -453,7 +453,7 @@ def get_script(source=None, column=None):
|
|||||||
if column is None:
|
if column is None:
|
||||||
column = vim.current.window.cursor[1]
|
column = vim.current.window.cursor[1]
|
||||||
buf_path = vim.current.buffer.name
|
buf_path = vim.current.buffer.name
|
||||||
return functions.Script(source, row, column, buf_path)
|
return api.Script(source, row, column, buf_path)
|
||||||
|
|
||||||
|
|
||||||
def _goto(is_definition=False, is_related_name=False, no_output=False):
|
def _goto(is_definition=False, is_related_name=False, no_output=False):
|
||||||
@@ -466,7 +466,7 @@ def _goto(is_definition=False, is_related_name=False, no_output=False):
|
|||||||
definitions = script.get_definition()
|
definitions = script.get_definition()
|
||||||
else:
|
else:
|
||||||
definitions = script.goto()
|
definitions = script.goto()
|
||||||
except functions.NotFoundError:
|
except api.NotFoundError:
|
||||||
echo_highlight("Cannot follow nothing. Put your cursor on a valid name.")
|
echo_highlight("Cannot follow nothing. Put your cursor on a valid name.")
|
||||||
except Exception:
|
except Exception:
|
||||||
# print to stdout, will be in :messages
|
# print to stdout, will be in :messages
|
||||||
@@ -485,7 +485,7 @@ def _goto(is_definition=False, is_related_name=False, no_output=False):
|
|||||||
|
|
||||||
d = list(definitions)[0]
|
d = list(definitions)[0]
|
||||||
if d.in_builtin_module():
|
if d.in_builtin_module():
|
||||||
if isinstance(d.definition, functions.keywords.Keyword):
|
if isinstance(d.definition, api.keywords.Keyword):
|
||||||
echo_highlight("Cannot get the definition of Python keywords.")
|
echo_highlight("Cannot get the definition of Python keywords.")
|
||||||
else:
|
else:
|
||||||
echo_highlight("Builtin modules cannot be displayed.")
|
echo_highlight("Builtin modules cannot be displayed.")
|
||||||
|
|||||||
@@ -9,23 +9,23 @@ os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
|||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from _compatibility import is_py25
|
from _compatibility import is_py25
|
||||||
import functions
|
import api
|
||||||
#functions.set_debug_function(functions.debug.print_to_stdout)
|
#api.set_debug_function(api.debug.print_to_stdout)
|
||||||
|
|
||||||
|
|
||||||
class TestRegression(unittest.TestCase):
|
class TestRegression(unittest.TestCase):
|
||||||
def get_def(self, src, pos):
|
def get_def(self, src, pos):
|
||||||
script = functions.Script(src, pos[0], pos[1], '')
|
script = api.Script(src, pos[0], pos[1], '')
|
||||||
return script.get_definition()
|
return script.get_definition()
|
||||||
|
|
||||||
def complete(self, src, pos):
|
def complete(self, src, pos):
|
||||||
script = functions.Script(src, pos[0], pos[1], '')
|
script = api.Script(src, pos[0], pos[1], '')
|
||||||
return script.complete()
|
return script.complete()
|
||||||
|
|
||||||
def get_in_function_call(self, src, pos=None):
|
def get_in_function_call(self, src, pos=None):
|
||||||
if pos is None:
|
if pos is None:
|
||||||
pos = 1, len(src)
|
pos = 1, len(src)
|
||||||
script = functions.Script(src, pos[0], pos[1], '')
|
script = api.Script(src, pos[0], pos[1], '')
|
||||||
return script.get_in_function_call()
|
return script.get_in_function_call()
|
||||||
|
|
||||||
def test_get_definition_cursor(self):
|
def test_get_definition_cursor(self):
|
||||||
@@ -61,7 +61,7 @@ class TestRegression(unittest.TestCase):
|
|||||||
#print should2, diff_line
|
#print should2, diff_line
|
||||||
assert should2 == diff_line
|
assert should2 == diff_line
|
||||||
|
|
||||||
self.assertRaises(functions.NotFoundError, get_def, cls)
|
self.assertRaises(api.NotFoundError, get_def, cls)
|
||||||
|
|
||||||
def test_keyword_doc(self):
|
def test_keyword_doc(self):
|
||||||
r = list(self.get_def("or", (1, 1)))
|
r = list(self.get_def("or", (1, 1)))
|
||||||
@@ -108,7 +108,7 @@ class TestRegression(unittest.TestCase):
|
|||||||
s = ("def abc(): pass\n"
|
s = ("def abc(): pass\n"
|
||||||
"abc.d.a.abc.d"
|
"abc.d.a.abc.d"
|
||||||
)
|
)
|
||||||
functions.Script(s, 2, 2, '/').related_names()
|
api.Script(s, 2, 2, '/').related_names()
|
||||||
|
|
||||||
def test_get_in_function_call(self):
|
def test_get_in_function_call(self):
|
||||||
s = "isinstance(a, abs("
|
s = "isinstance(a, abs("
|
||||||
|
|||||||
12
test/run.py
12
test/run.py
@@ -10,7 +10,7 @@ os.chdir(dirname(abspath(__file__)) + '/..')
|
|||||||
|
|
||||||
from _compatibility import unicode, BytesIO, reduce, literal_eval, is_py25
|
from _compatibility import unicode, BytesIO, reduce, literal_eval, is_py25
|
||||||
|
|
||||||
import functions
|
import api
|
||||||
import debug
|
import debug
|
||||||
|
|
||||||
sys.path.pop() # pop again, because it might affect the completion
|
sys.path.pop() # pop again, because it might affect the completion
|
||||||
@@ -110,7 +110,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
"""
|
"""
|
||||||
def get_defs(correct, correct_start, path):
|
def get_defs(correct, correct_start, path):
|
||||||
def defs(line_nr, indent):
|
def defs(line_nr, indent):
|
||||||
script = functions.Script(source, line_nr, indent, path)
|
script = api.Script(source, line_nr, indent, path)
|
||||||
return set(script.get_definition())
|
return set(script.get_definition())
|
||||||
|
|
||||||
should_be = set()
|
should_be = set()
|
||||||
@@ -121,7 +121,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
# -1 for the comment, +3 because of the comment start `#? `
|
# -1 for the comment, +3 because of the comment start `#? `
|
||||||
start = index.start()
|
start = index.start()
|
||||||
if print_debug:
|
if print_debug:
|
||||||
functions.set_debug_function(None)
|
api.set_debug_function(None)
|
||||||
number += 1
|
number += 1
|
||||||
try:
|
try:
|
||||||
should_be |= defs(line_nr - 1, start + correct_start)
|
should_be |= defs(line_nr - 1, start + correct_start)
|
||||||
@@ -129,7 +129,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
raise Exception('could not resolve %s indent %s'
|
raise Exception('could not resolve %s indent %s'
|
||||||
% (line_nr - 1, start))
|
% (line_nr - 1, start))
|
||||||
if print_debug:
|
if print_debug:
|
||||||
functions.set_debug_function(debug.print_to_stdout)
|
api.set_debug_function(debug.print_to_stdout)
|
||||||
# because the objects have different ids, `repr` it, then compare it.
|
# because the objects have different ids, `repr` it, then compare it.
|
||||||
should_str = set(r.desc_with_module for r in should_be)
|
should_str = set(r.desc_with_module for r in should_be)
|
||||||
if len(should_str) < number:
|
if len(should_str) < number:
|
||||||
@@ -157,7 +157,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
# get_definition test
|
# get_definition test
|
||||||
path = completion_test_dir + os.path.sep + f_name
|
path = completion_test_dir + os.path.sep + f_name
|
||||||
try:
|
try:
|
||||||
script = functions.Script(source, line_nr, index, path)
|
script = api.Script(source, line_nr, index, path)
|
||||||
if test_type == '!':
|
if test_type == '!':
|
||||||
fails += run_goto_test(script, correct, line_nr)
|
fails += run_goto_test(script, correct, line_nr)
|
||||||
elif test_type == '<':
|
elif test_type == '<':
|
||||||
@@ -238,7 +238,7 @@ except ValueError:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print_debug = True
|
print_debug = True
|
||||||
functions.set_debug_function(debug.print_to_stdout)
|
api.set_debug_function(debug.print_to_stdout)
|
||||||
|
|
||||||
# get test list, that should be executed
|
# get test list, that should be executed
|
||||||
test_files = {}
|
test_files = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user