splitForCompletion function

({String current, List<String> words}) splitForCompletion(
  1. String line
)

Splits the text before the cursor into the complete words and the current word being typed, for Tab completion.

Implementation

({List<String> words, String current}) splitForCompletion(String line) {
  int start = 0;
  String? quote;
  for (int i = 0; i < line.length; i++) {
    final String char = line[i];
    if (quote != null) {
      if (char == quote) quote = null;
    } else if (char == "'" || char == '"') {
      quote = char;
    } else if (char == r'\') {
      i++;
    } else if (char.trim().isEmpty) {
      start = i + 1;
    }
  }
  List<String> words;
  try {
    words = splitLiveShellLine(line.substring(0, start));
  } on FormatException {
    words = const [];
  }
  return (words: words, current: line.substring(start));
}