Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not call str.splitlines() twice in the same function. #628

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pylsp/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ def apply_change(self, change):
end_col = change_range["end"]["character"]

# Check for an edit occuring at the very end of the file
if start_line == len(self.lines):
lines = self.lines
if start_line == len(lines):
self._source = self.source + text
return

Expand All @@ -469,7 +470,7 @@ def apply_change(self, change):
# Iterate over the existing document until we hit the edit range,
# at which point we write the new text, then loop until we hit
# the end of the range and continue writing.
for i, line in enumerate(self.lines):
for i, line in enumerate(lines):
if i < start_line:
new.write(line)
continue
Expand All @@ -493,10 +494,11 @@ def offset_at_position(self, position):

def word_at_position(self, position):
"""Get the word under the cursor returning the start and end positions."""
if position["line"] >= len(self.lines):
lines = self.lines
if position["line"] >= len(lines):
return ""

line = self.lines[position["line"]]
line = lines[position["line"]]
i = position["character"]
# Split word in two
start = line[:i]
Expand Down