openDocument method
Opens the document in the LSP server.
This method is used internally by the CodeForge widget and calling it directly is not recommended.
Otherwise, the content will be read from filePath.
Implementation
Future<void> openDocument(String filePath, {String? initialContent}) async {
if (kIsWeb && initialContent == null) {
throw UnsupportedError(
'Opening an LSP document from filePath is not supported on web. '
'Provide initialContent or use a URI-backed document.',
);
}
final version = (_openDocuments[filePath] ?? 0) + 1;
_openDocuments[filePath] = version;
final text = initialContent ?? await File(filePath).readAsString();
await sendNotification(
method: 'textDocument/didOpen',
params: {
'textDocument': {
'uri': toFileUri(filePath),
'languageId': languageId,
'version': version,
'text': text,
},
},
);
await Future.delayed(Duration(milliseconds: 300));
}