1
0
forked from VimPlug/jedi

use the new implementation of splitlines all over the code, fixes #424

This commit is contained in:
Dave Halter
2014-07-18 16:59:22 +02:00
parent ffaacbefbc
commit ee1c5041ed
4 changed files with 8 additions and 14 deletions

View File

@@ -86,7 +86,8 @@ class Script(object):
with open(path) as f:
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
if not (0 < line <= len(lines)):
raise ValueError('`line` parameter is not in a valid range.')
@@ -99,7 +100,6 @@ class Script(object):
cache.clear_caches()
debug.reset_time()
self.source = common.source_to_unicode(source, encoding)
self._user_context = UserContext(self.source, self._pos)
self._parser = UserContextParser(self.source, path, self._pos, self._user_context)
self._evaluator = Evaluator()

View File

@@ -100,9 +100,7 @@ def time_cache(time_add_setting):
def cache_call_signatures(source, user_pos, stmt):
"""This function calculates the cache key."""
index = user_pos[0] - 1
lines = source.splitlines() or ['']
if source and source[-1] == '\n':
lines.append('')
lines = common.splitlines(source)
before_cursor = lines[index][:user_pos[1]]
other_lines = lines[stmt.start_pos[0]:index]

View File

@@ -2,6 +2,7 @@ import re
import os
from jedi import cache
from jedi import common
from jedi.parser import tokenize
from jedi._compatibility import u
from jedi.parser.fast import FastParser
@@ -178,12 +179,7 @@ class UserContext(object):
def get_line(self, line_nr):
if not self._line_cache:
self._line_cache = self.source.splitlines()
if self.source:
if self.source[-1] == '\n':
self._line_cache.append(u(''))
else: # ''.splitlines() == []
self._line_cache = [u('')]
self._line_cache = common.splitlines(self.source)
if line_nr == 0:
# This is a fix for the zeroth line. We need a newline there, for

View File

@@ -83,7 +83,7 @@ def _rename(names, replace_str):
with open(current_path) as f:
source = f.read()
new_lines = common.source_to_unicode(source).splitlines()
new_lines = common.splitlines(common.source_to_unicode(source))
old_lines = new_lines[:]
nr, indent = name.line, name.column
@@ -101,7 +101,7 @@ def extract(script, new_name):
:type source: str
: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[:]
user_stmt = script._parser.user_stmt()
@@ -160,7 +160,7 @@ def inline(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 = {}