async provideInlineCompletionItems()

in src/common/code_suggestions/code_suggestions_provider.ts [355:415]


  async provideInlineCompletionItems(
    document: vscode.TextDocument,
    position: vscode.Position,
    context: vscode.InlineCompletionContext,
    cancellationToken: vscode.CancellationToken,
  ): Promise<vscode.InlineCompletionItem[]> {
    if (!this.#languages.includes(document.languageId)) {
      return [];
    }

    CodeSuggestionsTelemetryManager.rejectOpenedSuggestions();

    this.#documentChangesTracker.trackCompletionRequest(document, position);

    if (this.#debouncedCall !== undefined) {
      clearTimeout(this.#debouncedCall);
    }

    if (
      this.#documentChangesTracker.getLastChangeType(document) === SuggestionChangeType.NoChange &&
      context.selectedCompletionInfo
    ) {
      CodeSuggestionsTelemetryManager.rejectSuggestionRequest(
        RejectCodeSuggestionReason.UnchangedDocument,
      ).catch(e => log.error(e));
      return [];
    }

    if (
      this.#documentChangesTracker.getLastChangeType(document) ===
      SuggestionChangeType.DeletedCharacter
    ) {
      CodeSuggestionsTelemetryManager.rejectSuggestionRequest(
        RejectCodeSuggestionReason.DeletingSingleCharacter,
      ).catch(e => log.error(e));
      return [];
    }

    if (
      this.#documentChangesTracker.getLastChangeType(document) ===
      SuggestionChangeType.RepeatedSpaces
    ) {
      CodeSuggestionsTelemetryManager.rejectSuggestionRequest(
        RejectCodeSuggestionReason.TypingRepeatedSpaces,
      ).catch(e => log.error(e));
      return [];
    }

    return new Promise(resolve => {
      //  In case of a hover, this will be triggered which is not desired as it calls for a new prediction
      if (context.triggerKind === vscode.InlineCompletionTriggerKind.Automatic) {
        if (this.#noDebounce) {
          resolve(this.getCompletions({ document, position, cancellationToken }));
        } else {
          this.#debouncedCall = setTimeout(() => {
            resolve(this.getCompletions({ document, position, cancellationToken }));
          }, this.#debounceTimeMs);
        }
      }
    });
  }