forked from VimPlug/jedi
use the new implementation of splitlines all over the code, fixes #424
This commit is contained in:
@@ -86,7 +86,8 @@ class Script(object):
|
|||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
source = f.read()
|
source = f.read()
|
||||||
|
|
||||||
lines = common.splitlines(source)
|
self.source = common.source_to_unicode(source, encoding)
|
||||||
|
lines = common.splitlines(self.source)
|
||||||
line = max(len(lines), 1) if line is None else line
|
line = max(len(lines), 1) if line is None else line
|
||||||
if not (0 < line <= len(lines)):
|
if not (0 < line <= len(lines)):
|
||||||
raise ValueError('`line` parameter is not in a valid range.')
|
raise ValueError('`line` parameter is not in a valid range.')
|
||||||
@@ -99,7 +100,6 @@ class Script(object):
|
|||||||
|
|
||||||
cache.clear_caches()
|
cache.clear_caches()
|
||||||
debug.reset_time()
|
debug.reset_time()
|
||||||
self.source = common.source_to_unicode(source, encoding)
|
|
||||||
self._user_context = UserContext(self.source, self._pos)
|
self._user_context = UserContext(self.source, self._pos)
|
||||||
self._parser = UserContextParser(self.source, path, self._pos, self._user_context)
|
self._parser = UserContextParser(self.source, path, self._pos, self._user_context)
|
||||||
self._evaluator = Evaluator()
|
self._evaluator = Evaluator()
|
||||||
|
|||||||
@@ -100,9 +100,7 @@ def time_cache(time_add_setting):
|
|||||||
def cache_call_signatures(source, user_pos, stmt):
|
def cache_call_signatures(source, user_pos, stmt):
|
||||||
"""This function calculates the cache key."""
|
"""This function calculates the cache key."""
|
||||||
index = user_pos[0] - 1
|
index = user_pos[0] - 1
|
||||||
lines = source.splitlines() or ['']
|
lines = common.splitlines(source)
|
||||||
if source and source[-1] == '\n':
|
|
||||||
lines.append('')
|
|
||||||
|
|
||||||
before_cursor = lines[index][:user_pos[1]]
|
before_cursor = lines[index][:user_pos[1]]
|
||||||
other_lines = lines[stmt.start_pos[0]:index]
|
other_lines = lines[stmt.start_pos[0]:index]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
|
from jedi import common
|
||||||
from jedi.parser import tokenize
|
from jedi.parser import tokenize
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi.parser.fast import FastParser
|
from jedi.parser.fast import FastParser
|
||||||
@@ -178,12 +179,7 @@ class UserContext(object):
|
|||||||
|
|
||||||
def get_line(self, line_nr):
|
def get_line(self, line_nr):
|
||||||
if not self._line_cache:
|
if not self._line_cache:
|
||||||
self._line_cache = self.source.splitlines()
|
self._line_cache = common.splitlines(self.source)
|
||||||
if self.source:
|
|
||||||
if self.source[-1] == '\n':
|
|
||||||
self._line_cache.append(u(''))
|
|
||||||
else: # ''.splitlines() == []
|
|
||||||
self._line_cache = [u('')]
|
|
||||||
|
|
||||||
if line_nr == 0:
|
if line_nr == 0:
|
||||||
# This is a fix for the zeroth line. We need a newline there, for
|
# This is a fix for the zeroth line. We need a newline there, for
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ def _rename(names, replace_str):
|
|||||||
with open(current_path) as f:
|
with open(current_path) as f:
|
||||||
source = f.read()
|
source = f.read()
|
||||||
|
|
||||||
new_lines = common.source_to_unicode(source).splitlines()
|
new_lines = common.splitlines(common.source_to_unicode(source))
|
||||||
old_lines = new_lines[:]
|
old_lines = new_lines[:]
|
||||||
|
|
||||||
nr, indent = name.line, name.column
|
nr, indent = name.line, name.column
|
||||||
@@ -101,7 +101,7 @@ def extract(script, new_name):
|
|||||||
:type source: str
|
:type source: str
|
||||||
:return: list of changed lines/changed files
|
:return: list of changed lines/changed files
|
||||||
"""
|
"""
|
||||||
new_lines = common.source_to_unicode(script.source).splitlines()
|
new_lines = common.splitlines(common.source_to_unicode(script.source))
|
||||||
old_lines = new_lines[:]
|
old_lines = new_lines[:]
|
||||||
|
|
||||||
user_stmt = script._parser.user_stmt()
|
user_stmt = script._parser.user_stmt()
|
||||||
@@ -160,7 +160,7 @@ def inline(script):
|
|||||||
"""
|
"""
|
||||||
:type script: api.Script
|
:type script: api.Script
|
||||||
"""
|
"""
|
||||||
new_lines = common.source_to_unicode(script.source).splitlines()
|
new_lines = common.splitlines(common.source_to_unicode(script.source))
|
||||||
|
|
||||||
dct = {}
|
dct = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user