28 const TextDocumentItem &item = params.textDocument;
29 m_codeModelManager->newOpenFile(QQmlLSUtils::lspUriToQmlUrl(item.uri), item.version,
30 QString::fromUtf8(item.text));
35 QByteArray url = QQmlLSUtils::lspUriToQmlUrl(params.textDocument.uri);
36 auto openDoc = m_codeModelManager->openDocumentByUrl(url);
37 std::shared_ptr<
Utils::TextDocument> document = openDoc.textDocument;
39 qCWarning(lspServerLog) <<
"Ignoring changes to non open or closed document"
40 << QString::fromUtf8(url);
43 const auto &changes = params.contentChanges;
45 QMutexLocker l(document->mutex());
46 for (
const auto &change : changes) {
47 if (
auto plainText = std::get_if<TextDocumentContentChangeEventVariant2>(&change)) {
48 document->setPlainText(QString::fromUtf8(plainText->text));
52 const auto &withRange = std::get<TextDocumentContentChangeEventVariant1>(change);
53 const auto &range = withRange.range;
54 const auto &rangeStart = range.start;
56 document->findBlockByNumber(rangeStart.line).position() + rangeStart.character;
57 const auto &rangeEnd = range.end;
59 document->findBlockByNumber(rangeEnd.line).position() + rangeEnd.character;
61 document->setPlainText(document->toPlainText().replace(
62 start, end - start, QString::fromUtf8(withRange.text)));
64 document->setVersion(params.textDocument.version);
65 qCDebug(lspServerLog).noquote()
66 <<
"text is\n:----------" << document->toPlainText() <<
"\n_________";
68 m_codeModelManager->addOpenToUpdate(url);
73 QObject::connect(server->notifySignals(),
74 &QLspNotifySignals::receivedDidOpenTextDocumentNotification,
this,
75 &TextSynchronization::didOpenTextDocument);
77 QObject::connect(server->notifySignals(),
78 &QLspNotifySignals::receivedDidChangeTextDocumentNotification,
this,
79 &TextSynchronization::didDidChangeTextDocument);
81 QObject::connect(server->notifySignals(),
82 &QLspNotifySignals::receivedDidCloseTextDocumentNotification,
this,
83 &TextSynchronization::didCloseTextDocument);
void setupCapabilities(QLspSpecification::ServerCapabilities &caps) override
void didDidChangeTextDocument(const QLspSpecification::DidChangeTextDocumentParams ¶ms)
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
void didCloseTextDocument(const QLspSpecification::DidCloseTextDocumentParams ¶ms)