suggest method

Iterable<Suggestion> suggest(
  1. String input, {
  2. int cursorOffset = -1,
  3. String fullInput = "",
})

Returns autocomplete suggestions at cursor position in expr.

Implementation

Iterable<Suggestion> suggest(String input, {int cursorOffset = -1, String fullInput = ""}) {
  if ( cursorOffset == -1)
    cursorOffset = input.length;

  var result = parser.parsePrefix(input, typeChecker: typeChecker);

  if (!result.success)
    return [];

  // Find the deepest node at the cursor

  final node = _findNodeAt(result.value!, cursorOffset);
  if (node == null)
    return [];

  // Determine if there is a dot prefix before the cursor

  if ( node is Variable) {
    if ( node.getType<Desc>() is UnknownPropertyDesc) {
      return node.getType<UnknownPropertyDesc>().suggestions();
    }
  }

  if ( node is MemberExpression) {
    if ( node.getType() is UnknownPropertyDesc)
      return node.getType<UnknownPropertyDesc>().suggestions();

    var type = node.object.getType();
    var property = node.property.name;

    if ( type is ClassDesc)
      return type.properties.values
          .where((prop) => prop.name.startsWith(property))
          .map((prop) => Suggestion(
              suggestion: prop.isField() ? prop.name : methodSuggestion(prop as MethodDesc),
              type: prop.isField() ? "field" : "method",
              tooltip: ""));
  }

  return [];
}