Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qtextsynchronization.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qqmlcodemodelmanager_p.h"
6
#
include
"qtextsynchronization_p.h"
7
#
include
"qqmllsutils_p.h"
8
#
include
"qtextdocument_p.h"
9
10
using
namespace
QLspSpecification;
11
using
namespace
Qt::StringLiterals;
12
13
QT_BEGIN_NAMESPACE
14
15
TextSynchronization::TextSynchronization(QmlLsp::QQmlCodeModelManager *codeModelManager,
16
QObject *parent)
17
: QLanguageServerModule(parent), m_codeModelManager(codeModelManager)
18
{
19
}
20
21
void
TextSynchronization
::
didCloseTextDocument
(
const
DidCloseTextDocumentParams ¶ms)
22
{
23
m_codeModelManager->closeOpenFile(QQmlLSUtils::lspUriToQmlUrl(params.textDocument.uri));
24
}
25
26
void
TextSynchronization
::didOpenTextDocument(
const
DidOpenTextDocumentParams ¶ms)
27
{
28
const
TextDocumentItem &item = params.textDocument;
29
m_codeModelManager->newOpenFile(QQmlLSUtils::lspUriToQmlUrl(item.uri), item.version,
30
QString::fromUtf8(item.text));
31
}
32
33
void
TextSynchronization
::
didDidChangeTextDocument
(
const
DidChangeTextDocumentParams ¶ms)
34
{
35
QByteArray url = QQmlLSUtils::lspUriToQmlUrl(params.textDocument.uri);
36
auto
openDoc = m_codeModelManager->openDocumentByUrl(url);
37
std
::shared_ptr<
Utils
::TextDocument> document = openDoc.textDocument;
38
if
(!document) {
39
qCWarning(lspServerLog) <<
"Ignoring changes to non open or closed document"
40
<< QString::fromUtf8(url);
41
return
;
42
}
43
const
auto
&changes = params.contentChanges;
44
{
45
QMutexLocker l(document->mutex());
46
for
(
const
auto
&change : changes) {
47
if
(
auto
plainText = std::get_if<TextDocumentContentChangeWholeDocument>(&change)) {
48
document->setPlainText(QString::fromUtf8(plainText->text));
49
continue
;
50
}
51
52
const
auto
&withRange = std::get<TextDocumentContentChangePartial>(change);
53
const
auto
&range = withRange.range;
54
const
auto
&rangeStart = range.start;
55
const
int
start =
56
document->findBlockByNumber(rangeStart.line).position() + rangeStart.character;
57
const
auto
&rangeEnd = range.end;
58
const
int
end =
59
document->findBlockByNumber(rangeEnd.line).position() + rangeEnd.character;
60
61
document->setPlainText(document->toPlainText().replace(
62
start, end - start, QString::fromUtf8(withRange.text)));
63
}
64
document->setVersion(params.textDocument.version);
65
qCDebug(lspServerLog).noquote()
66
<<
"text is\n:----------"
<< document->toPlainText() <<
"\n_________"
;
67
}
68
m_codeModelManager->addOpenToUpdate(url);
69
}
70
71
void
TextSynchronization
::
registerHandlers
(QLanguageServer *server, QLanguageServerProtocol *)
72
{
73
QObject::connect(server->notifySignals(),
74
&QLspNotifySignals::receivedDidOpenTextDocumentNotification,
this
,
75
&TextSynchronization::didOpenTextDocument);
76
77
QObject::connect(server->notifySignals(),
78
&QLspNotifySignals::receivedDidChangeTextDocumentNotification,
this
,
79
&TextSynchronization::didDidChangeTextDocument);
80
81
QObject::connect(server->notifySignals(),
82
&QLspNotifySignals::receivedDidCloseTextDocumentNotification,
this
,
83
&TextSynchronization::didCloseTextDocument);
84
}
85
86
void
TextSynchronization
::
setupCapabilities
(QLspSpecification::ServerCapabilities &caps)
87
{
88
TextDocumentSyncOptions syncOptions;
89
syncOptions.openClose =
true
;
90
syncOptions.change = TextDocumentSyncKind::Incremental;
91
caps.textDocumentSync = syncOptions;
92
}
93
94
QT_END_NAMESPACE
TextSynchronization
Definition
qtextsynchronization_p.h:25
TextSynchronization::setupCapabilities
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
Definition
qtextsynchronization.cpp:86
TextSynchronization::didDidChangeTextDocument
void didDidChangeTextDocument(const QLspSpecification::DidChangeTextDocumentParams ¶ms)
Definition
qtextsynchronization.cpp:33
TextSynchronization::registerHandlers
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
Definition
qtextsynchronization.cpp:71
TextSynchronization::didCloseTextDocument
void didCloseTextDocument(const QLspSpecification::DidCloseTextDocumentParams ¶ms)
Definition
qtextsynchronization.cpp:21
qdesigner_internal::Utils
Definition
qdesigner_utils_p.h:526
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtdeclarative
src
qmlls
qtextsynchronization.cpp
Generated on
for Qt by
1.18.0