updateDocument method

Future<void> updateDocument(
  1. String filePath,
  2. String content, {
  3. List<Map<String, dynamic>>? contentChanges,
})

Updates the document content in the LSP server.

Sends a 'didChange' notification to the LSP server. If contentChanges is provided, the update is sent incrementally. If the document is not open, this method does nothing.

Implementation

Future<void> updateDocument(
  String filePath,
  String content, {
  List<Map<String, dynamic>>? contentChanges,
}) async {
  if (!_openDocuments.containsKey(filePath)) {
    return;
  }

  final version = _openDocuments[filePath]! + 1;
  _openDocuments[filePath] = version;

  final changes = forceFullDocumentSync
      ? [
          {'text': content},
        ]
      : (contentChanges != null && contentChanges.isNotEmpty
            ? contentChanges
            : [
                {'text': content},
              ]);

  await sendNotification(
    method: 'textDocument/didChange',
    params: {
      'textDocument': {
        'uri': Uri.file(filePath).toString(),
        'version': version,
      },
      'contentChanges': changes,
    },
  );
}