Normalize line endings when creating ParseJob from background file.

Authored by flherne on Jul 25 2017, 9:32 AM.

Description

Normalize line endings when creating ParseJob from background file.

When the file being parsed is open in the editor, ParseJob::readContents()
uses KTextEditor::Document::text() to read the contents.
At some point within KTextEditor, the line endings are normalized - even if
the document uses \r or \r\n, the returned content is separated by \n only.

Otherwise, the contents are read directly from the file. Until this patch,
the line endings aren't normalized in this case; the ParseJob contents
differ depending on whether the file is open in the editor.

Several places in kdev-python (and, at a glance, other language plugins)
assume that lines can be separated by, and end with, \n. Old-style Macintosh
endings (\r) break this assumption, in the worst case causing a crash.

BUG: 378827

Using a regex in each instance would be a pain, and one code path normalizes
line endings already, so I think the best option is to do so for background
files also.

Differential Revision: https://phabricator.kde.org/D5707