LSP: fix lsp position to QTextCursor position conversion

If the 'character' part of the lsp position is greater than the block
length for the 'line' it defaults to the end of the line (see
documentation under
https://microsoft.github.io/language-server-protocol/specification ).

Change-Id: I3ed6cefd7431e58adbab1dbcf94a12a5e460019a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2019-05-27 14:19:28 +02:00
committed by hjk
parent 2b1c8aa877
commit 7c93b26792

View File

@@ -324,8 +324,10 @@ Position::Position(const QTextCursor &cursor)
int Position::toPositionInDocument(QTextDocument *doc) const int Position::toPositionInDocument(QTextDocument *doc) const
{ {
const QTextBlock block = doc->findBlockByNumber(line()); const QTextBlock block = doc->findBlockByNumber(line());
if (!block.isValid() || block.length() <= character()) if (!block.isValid())
return -1; return -1;
if (block.length() <= character())
return block.position() + block.length();
return block.position() + character(); return block.position() + character();
} }