nodes: 0, module; 1, function_definition; 2, function_name:sort_completions; 3, parameters; 4, block; 5, identifier:completions_gen; 6, expression_statement; 7, import_from_statement; 8, function_definition; 9, return_statement; 10, comment:""" sorts the completions """; 11, dotted_name; 12, dotted_name; 13, function_name:_get_weight; 14, parameters; 15, block; 16, call; 17, identifier:knack; 18, identifier:help; 19, identifier:REQUIRED_TAG; 20, identifier:val; 21, expression_statement; 22, expression_statement; 23, if_statement; 24, return_statement; 25, identifier:sorted; 26, argument_list; 27, comment:""" weights the completions with required things first the lexicographically"""; 28, assignment; 29, boolean_operator; 30, block; 31, binary_operator:priority + val.text; 32, identifier:completions_gen; 33, keyword_argument; 34, identifier:priority; 35, string; 36, attribute; 37, call; 38, expression_statement; 39, comment:# a space has the lowest ordinance; 40, identifier:priority; 41, attribute; 42, identifier:key; 43, identifier:_get_weight; 44, identifier:val; 45, identifier:display_meta; 46, attribute; 47, argument_list; 48, assignment; 49, identifier:val; 50, identifier:text; 51, attribute; 52, identifier:startswith; 53, identifier:REQUIRED_TAG; 54, identifier:priority; 55, string; 56, identifier:val; 57, identifier:display_meta; 58, string_content:
code: def sort_completions(completions_gen):
      """ sorts the completions """
      from knack.help import REQUIRED_TAG
  
      def _get_weight(val):
          """ weights the completions with required things first the lexicographically"""
          priority = ''
          if val.display_meta and val.display_meta.startswith(REQUIRED_TAG):
              priority = ' '  # a space has the lowest ordinance
          return priority + val.text
  
      return sorted(completions_gen, key=_get_weight)