@@ -166,6 +166,52 @@ void MarkdownLspClient::didOpen(const QString &uri, const QString &languageId, c
166166 sendMessage (obj);
167167}
168168
169+ MarkdownLspClient::TextDocumentSyncKind MarkdownLspClient::serverSyncKind () const {
170+ return _serverSyncKind;
171+ }
172+
173+ void MarkdownLspClient::didChangeIncremental (const QString &uri,
174+ const QVector<IncrementalChange> &changes,
175+ int version) {
176+ if (!_initialized || changes.isEmpty ()) {
177+ return ;
178+ }
179+
180+ QJsonObject doc;
181+ doc.insert (QStringLiteral (" uri" ), uri);
182+ doc.insert (QStringLiteral (" version" ), version);
183+
184+ QJsonArray changesArray;
185+ for (const IncrementalChange &change : changes) {
186+ QJsonObject start;
187+ start.insert (QStringLiteral (" line" ), change.startLine );
188+ start.insert (QStringLiteral (" character" ), change.startCharacter );
189+
190+ QJsonObject end;
191+ end.insert (QStringLiteral (" line" ), change.endLine );
192+ end.insert (QStringLiteral (" character" ), change.endCharacter );
193+
194+ QJsonObject range;
195+ range.insert (QStringLiteral (" start" ), start);
196+ range.insert (QStringLiteral (" end" ), end);
197+
198+ QJsonObject changeObj;
199+ changeObj.insert (QStringLiteral (" range" ), range);
200+ changeObj.insert (QStringLiteral (" text" ), change.text );
201+ changesArray.append (changeObj);
202+ }
203+
204+ QJsonObject params;
205+ params.insert (QStringLiteral (" textDocument" ), doc);
206+ params.insert (QStringLiteral (" contentChanges" ), changesArray);
207+
208+ QJsonObject obj;
209+ obj.insert (QStringLiteral (" jsonrpc" ), QStringLiteral (" 2.0" ));
210+ obj.insert (QStringLiteral (" method" ), QStringLiteral (" textDocument/didChange" ));
211+ obj.insert (QStringLiteral (" params" ), params);
212+ sendMessage (obj);
213+ }
214+
169215void MarkdownLspClient::didChange (const QString &uri, const QString &text, int version) {
170216 if (!_initialized) {
171217 _pendingDocument.uri = uri;
@@ -498,6 +544,34 @@ void MarkdownLspClient::handleResponse(const QJsonObject &object) {
498544 if (id == _initializeRequestId) {
499545 _initialized = true ;
500546 _initializeRequestId = -1 ;
547+
548+ // Extract textDocumentSync capability from the server response.
549+ // The sync kind can appear as a bare integer or inside an options object.
550+ _serverSyncKind = SyncFull;
551+ const QJsonObject result = object.value (QStringLiteral (" result" )).toObject ();
552+ const QJsonObject capabilities = result.value (QStringLiteral (" capabilities" )).toObject ();
553+ const QJsonValue syncValue = capabilities.value (QStringLiteral (" textDocumentSync" ));
554+ if (syncValue.isDouble ()) {
555+ const int kind = syncValue.toInt (1 );
556+ if (kind == 2 ) {
557+ _serverSyncKind = SyncIncremental;
558+ } else if (kind == 0 ) {
559+ _serverSyncKind = SyncNone;
560+ }
561+ } else if (syncValue.isObject ()) {
562+ const QJsonObject syncObj = syncValue.toObject ();
563+ const int kind = syncObj.value (QStringLiteral (" change" )).toInt (1 );
564+ if (kind == 2 ) {
565+ _serverSyncKind = SyncIncremental;
566+ } else if (kind == 0 ) {
567+ _serverSyncKind = SyncNone;
568+ }
569+ }
570+
571+ if (_verboseLogging) {
572+ qDebug () << " Markdown LSP server sync kind:" << static_cast <int >(_serverSyncKind);
573+ }
574+
501575 emit serverInitialized ();
502576 sendInitializedNotification ();
503577 flushPendingDocument ();
0 commit comments