format method

Future<FormatResult> format(
  1. String? file,
  2. int? selectionOffset,
  3. int? selectionLength, {
  4. int? lineLength,
})

Format the contents of a single file. The currently selected region of text is passed in so that the selection can be preserved across the formatting operation. The updated selection will be as close to matching the original as possible, but whitespace at the beginning or end of the selected region will be ignored. If preserving selection information is not required, zero (0) can be specified for both the selection offset and selection length.

If a request is made for a file which does not exist, or which is not currently subject to analysis (e.g. because it is not associated with any analysis root specified to analysis.setAnalysisRoots), an error of type FORMAT_INVALID_FILE will be generated. If the source contains syntax errors, an error of type FORMAT_WITH_ERRORS will be generated.

Implementation

Future<FormatResult> format(
    String? file, int? selectionOffset, int? selectionLength,
    {int? lineLength}) {
  final Map m = {
    'file': file,
    'selectionOffset': selectionOffset,
    'selectionLength': selectionLength
  };
  if (lineLength != null) m['lineLength'] = lineLength;
  return _call('edit.format', m).then(FormatResult.parse);
}