packages/insomnia-app/app/ui/components/codemirror/extensions/autocomplete.js
function matchSegments(listOfThings, segment, type, limit = -1) {
  if (!Array.isArray(listOfThings)) {
    console.warn('Autocomplete received items in non-list form', listOfThings);
    return [];
  }

  const matches = [];
  for (const t of listOfThings) {
    const name = typeof t === 'string' ? t : t.name;
    const value = typeof t === 'string' ? '' : t.value;
    const displayName = t.displayName || name;
    const defaultFill = typeof t === 'string' ? name : getDefaultFill(t.name, t.args);

    const matchSegment = segment.toLowerCase();
    const matchName = displayName.toLowerCase();

    // Throw away things that don't match
    if (!matchName.includes(matchSegment)) {
      continue;
    }

    matches.push({
      // Custom Insomnia keys
      type,
      segment,
      comment: value,
      displayValue: value ? JSON.stringify(value) : '',
      score: name.length, // In case we want to sort by this

      // CodeMirror
      text: defaultFill,
      displayText: displayName,
      render: renderHintMatch,
      hint: replaceHintMatch,
    });
  }

  if (limit >= 0) {
    return matches.slice(0, limit);
  } else {
    return matches;
  }
}
function matchSegments(listOfThings, segment, type, limit = -1) {
  if (!Array.isArray(listOfThings)) {
    console.warn('Autocomplete received items in non-list form', listOfThings);
    return [];
  }

  const matches = [];
  for (const t of listOfThings) {
    const name = typeof t === 'string' ? t : t.name;
    const value = typeof t === 'string' ? '' : t.value;
    const displayName = t.displayName || name;
    const defaultFill = typeof t === 'string' ? name : getDefaultFill(t.name, t.args);

    const matchSegment = segment.toLowerCase();
    const matchName = displayName.toLowerCase();

    // Throw away things that don't match
    if (!matchName.includes(matchSegment)) {
      continue;
    }

    matches.push({
      // Custom Insomnia keys
      type,
      segment,
      comment: value,
      displayValue: value ? JSON.stringify(value) : '',
      score: name.length, // In case we want to sort by this

      // CodeMirror
      text: defaultFill,
      displayText: displayName,
      render: renderHintMatch,
      hint: replaceHintMatch,
    });
  }

  if (limit >= 0) {
    return matches.slice(0, limit);
  } else {
    return matches;
  }
}
function matchSegments ( listOfThings , segment , type , limit = - 1 ) { if ( ! Array . isArray ( listOfThings ) ) { console . warn ( 'Autocomplete received items in non-list form' , listOfThings ) ; return [ ] ; } const matches = [ ] ; for ( const t of listOfThings ) { const name = typeof t === 'string' ? t : t . name ; const value = typeof t === 'string' ? '' : t . value ; const displayName = t . displayName || name ; const defaultFill = typeof t === 'string' ? name : getDefaultFill ( t . name , t . args ) ; const matchSegment = segment . toLowerCase ( ) ; const matchName = displayName . toLowerCase ( ) ; // Throw away things that don't match if ( ! matchName . includes ( matchSegment ) ) { continue ; } matches . push ( { // Custom Insomnia keys type , segment , comment : value , displayValue : value ? JSON . stringify ( value ) : '' , score : name . length , // In case we want to sort by this // CodeMirror text : defaultFill , displayText : displayName , render : renderHintMatch , hint : replaceHintMatch , } ) ; } if ( limit >= 0 ) { return matches . slice ( 0 , limit ) ; } else { return matches ; } }
Match against a list of things
@param listOfThings - Can be list of strings or list of {name, value}
@param segment - segment to match against
@param type
@param limit
@returns {Array}
Match against a list of things