openDocument method

Future<void> openDocument({
  1. String? initialContent,
})

Opens the document in the LSP server.

This method is used internally by the CodeCrafter widget and calling it directly is not recommended.

If initialContent is provided, it will be used as the document content. Otherwise, the content will be read from filePath.

Implementation

Future<void> openDocument({String? initialContent}) async {
  final version = (_openDocuments[filePath] ?? 0) + 1;
  _openDocuments[filePath] = version;
  final String text = initialContent ?? await File(filePath).readAsString();
  await _sendNotification(
    method: 'textDocument/didOpen',
    params: {
      'textDocument': {
        'uri': Uri.file(filePath).toString(),
        'languageId': languageId,
        'version': version,
        'text': text,
      },
    },
  );
  await Future.delayed(Duration(milliseconds: 300));
}