forked from qt-creator/qt-creator
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:
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user