Skip to content
Merged
Show file tree
Hide file tree
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: 7 additions & 3 deletions pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def __str__(self):

@property
def lines(self):
# An empty document is much nicer to deal with assuming it has a single
# line with no characters and no final newline.
return self.source.splitlines(True) or [u'']
return self.source.splitlines(True)

@property
def source(self):
Expand All @@ -118,7 +116,13 @@ def apply_change(self, change):
end_line = change_range['end']['line']
end_col = change_range['end']['character']

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

new = io.StringIO()

# 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.
Expand Down
17 changes: 17 additions & 0 deletions test/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,20 @@ def test_document_multiline_edit():
"def hello(a, b):\n",
" print a, b\n"
]


def test_document_end_of_file_edit():
old = [
"print 'a'\n",
"print 'b'\n"
]
doc = Document('file:///uri', u''.join(old))
doc.apply_change({'text': u'o', 'range': {
'start': {'line': 2, 'character': 0},
'end': {'line': 2, 'character': 0}
}})
assert doc.lines == [
"print 'a'\n",
"print 'b'\n",
"o",
]