---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://sourcecraft.dev/portal/docs/en/code-assistant/operations/autocompletion.md
  - https://sourcecraft.dev/portal/docs/ru/code-assistant/operations/autocompletion.md
title: Running SourceCraft Code Assistant in code autocompletion mode
description: How to use Code Assistant in code autocompletion mode.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Code autocompletion in SourceCraft Code Assistant

<!-- source: en/_includes/code-assistant/vscode-ui-language.md -->
{% note info %}

The interface language of the Visual Studio Code plugin depends on the selected IDE language.

{% endnote %}
<!-- endsource: en/_includes/code-assistant/vscode-ui-language.md -->

<!-- source: en/_includes/code-assistant/instruction-autocompletion.md -->
<!-- source: en/_includes/code-assistant/syntax-support.md -->
The smart autocompletion mode explicitly supports code autocompletion for the following programming languages and frameworks:

* C++
* Go
* Java
* JavaScript/TypeScript
* Kotlin
* Python
* Scala
* SQL
* Swift

Autocompletion may also work for other languages. For languages ​​that are less represented in public repositories, the number and quality of autocompletion prompts will be lower.
<!-- endsource: en/_includes/code-assistant/syntax-support.md -->

## Use case {#examples}

In this example, we use the [_insert_](#insert) mode to revise the code, and then, the [_replace_](#replace) mode, which provides suggestions for the next lines based on the edits we made:

<iframe width="640" height="360" src="https://runtime.strm.yandex.ru/player/video/vplvc2ilmvxzsfk4bkmf?autoplay=0&mute=0" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" frameborder="0" scrolling="no"></iframe>

Here, after we have changed the argument name, the _replace_ mode updates it accordingly in the other lines:

<iframe width="640" height="360" src="https://runtime.strm.yandex.ru/player/video/vplvnuo2g2jw2fjoybgf?autoplay=0&mute=0" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" frameborder="0" scrolling="no"></iframe>

## Insert mode {#insert}

The _insert_ mode in Code Assistant can suggest the most suitable options to complete the current line or word.

<!-- source: en/_includes/code-assistant/auto-manual-modes.md -->
Code Assistant analyzes your code context and provides the following types of suggestions:
* Automatic.
* User-triggered (**Ctrl** + **Space**). In Visual Studio Code, you can also use **Ctrl** + **Enter**.
<!-- endsource: en/_includes/code-assistant/auto-manual-modes.md -->

1. Open the IDE and create a test file named `server.cpp` with the following contents:

    ```cpp
    // simple web-server to work with sockets

    #include <iostream>
    #include <string>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <unistd.h>

    using namespace std;

    int main() {

    }
    ```

1. In the `int main()` section, start typing something, e.g., `//create socket`. See the Code Assistant suggestion:

    ```cpp
    ...
    int main() {

    //create socket
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);

    }
    ```

1. Select an action for the suggestion:

    {% list tabs group=ide %}

    - Visual Studio Code {#vscode}

      <!-- source: en/_includes/code-assistant/actions-with-suggestions.md -->
      * Click **Tab** to accept the suggestion.
      * To start accepting the suggestion word by word, press **Ctrl** + **→** for Windows or Linux or **Command** + **→** for macOS.
      * To discard the suggestion, press **Esc**.
      <!-- endsource: en/_includes/code-assistant/actions-with-suggestions.md -->

      * If there are multiple suggestions, you can switch between them using **Alt** + **[** and **Alt** + **]** for Windows or Linux or **Option** + **[** and **Option** + **]** for macOS.

      ![image](../../_assets/code-assistant/vsc-test-autocomplete-screen.png)

    - JetBrains IDE {#jb}

      * Click **Tab** to accept the suggestion.
      * To discard the suggestion, press **Esc**.

      ![image](../../_assets/code-assistant/jb-test-autocomplete-screen.png)

    {% endlist %}

You can also watch our Code Assistant video tutorial [here](https://sourcecraft.dev/portal/code-assistant/).

## Replace mode {#replace}

The _replace_ mode in Code Assistant can suggest corrections and renaming options in the current file code based on the changes you have made.

1. Open the IDE and create a test file named `fibonacci.py` with the following contents:

   ```py
   def fibonacci(k):
       if k == 0:
           return 0
       elif k == 1:
           return 1
       else:
           return fibonacci(k-1) + fibonacci(k-2)
   
   print(fibonacci(10))
   ```

1. For example, change the variable name from `k` to `n`. See the Code Assistant corrections:

   ```py
   def fibonacci(n):
       if n == 0:
           return 0
       elif n == 1:
           return 1
       else:
           return fibonacci(n-1) + fibonacci(n-2)
   
   print(fibonacci(10))
   ```

   Code Assistant suggests corrections line by line. Move the cursor to the relevant line to see a correction from Code Assistant.

1. Select what to do with the suggestion:

   * Click **Tab** to accept the suggestion.
   * To discard the suggestion, press **Esc**.

The model takes code revision history into account. Depending on this history, the suggestions may vary significantly.
<!-- endsource: en/_includes/code-assistant/instruction-autocompletion.md -->

## Suggestion indicator {#help-indicator}

<!-- source: en/_includes/code-assistant/help-indicator.md -->
<!-- source: en/_includes/code-assistant/help-indicator-load.md -->
When generating a suggestion, the <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="#787878" d="M12 4a8 8 0 0 1 7.89 6.7 1.53 1.53 0 0 0 1.49 1.3 1.5 1.5 0 0 0 1.48-1.75 11 11 0 0 0-21.72 0A1.5 1.5 0 0 0 2.62 12a1.53 1.53 0 0 0 1.49-1.3A8 8 0 0 1 12 4Z"><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></svg> loading icon will appear to the left of the editable code. If generation stops or there is no result, you will see the <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path fill="#787878" d="M7 14a.965.965 0 0 1-.712-.288A.972.972 0 0 1 6 13c0-.283.095-.52.288-.712A.97.97 0 0 1 7 12c.282 0 .52.096.713.288.193.192.289.43.287.712a.986.986 0 0 1-.288.713A.952.952 0 0 1 7 14ZM22 4v12.45a.968.968 0 0 1-.288.713.964.964 0 0 1-.712.287c-.25 0-.479-.083-.687-.25-.208-.167-.312-.417-.313-.75V4H7.275c-.333 0-.583-.104-.75-.312a1.071 1.071 0 0 1 0-1.375c.167-.207.417-.312.75-.313H20c.55 0 1.021.196 1.413.588.392.392.588.863.587 1.412Zm-5 7h-2.725c-.333 0-.583-.104-.75-.312a1.07 1.07 0 0 1 0-1.375c.167-.207.417-.312.75-.313H17c.283 0 .521.096.713.288.192.192.288.43.287.712 0 .283-.097.52-.288.713A.957.957 0 0 1 17 11ZM6 18l-2.3 2.3c-.317.317-.68.388-1.088.213-.409-.175-.613-.487-.612-.938V4.8l-.6-.6a.948.948 0 0 1-.275-.7.95.95 0 0 1 .275-.7.948.948 0 0 1 .7-.275.95.95 0 0 1 .7.275l18.4 18.4a.98.98 0 0 1 .288.688.925.925 0 0 1-.288.712.948.948 0 0 1-.7.275.948.948 0 0 1-.7-.275L15.15 18H6Zm1-7a.965.965 0 0 1-.712-.288A.972.972 0 0 1 6 10c0-.283.095-.52.288-.712A.97.97 0 0 1 7 9c.282 0 .52.096.713.288.193.192.289.43.287.712a.986.986 0 0 1-.288.713A.952.952 0 0 1 7 11Zm10-3h-6a.965.965 0 0 1-.712-.288A.973.973 0 0 1 10 7c0-.283.095-.52.288-.712A.97.97 0 0 1 11 6h6c.283 0 .521.096.713.288.192.192.288.43.287.712 0 .283-.097.52-.288.713A.957.957 0 0 1 17 8ZM4 6.8v10.325L5.15 16h8.05L4 6.8Z"/></svg> (no suggestion) icon.
<!-- endsource: en/_includes/code-assistant/help-indicator-load.md -->

The suggestion indicator is enabled by default.

To enable or disable the indicator:

{% list tabs group=ide %}

  - Visual Studio Code {#vscode}

    1. In the left-hand panel, click <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><g fill="#000" clip-path="url(#svg-46ctykpy__clip0_1068_334)"><path fill-rule="evenodd" d="M5.2 1A1.2 1.2 0 0 0 4 2.2v10.299a.5.5 0 0 0 .853.354L6.706 11H14.8A1.2 1.2 0 0 0 16 9.8V2.2A1.2 1.2 0 0 0 14.8 1H5.2Zm5.273 1.5L8 9.5h1.527L12 2.5h-1.527Z" clip-rule="evenodd"/><path d="M1.2 3H3v1H1.2a.2.2 0 0 0-.2.2v9.6c0 .11.09.2.2.2h11.6a.2.2 0 0 0 .2-.2V12h1v1.8a1.2 1.2 0 0 1-1.2 1.2H1.2A1.2 1.2 0 0 1 0 13.8V4.2A1.2 1.2 0 0 1 1.2 3Z"/></g><defs><clipPath id="svg-46ctykpy__clip0_1068_334"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>.
    1. In the panel that opens, select <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M7.199 2H8.8a.2.2 0 0 1 .2.2c0 1.808 1.958 2.939 3.524 2.034a.2.2 0 0 1 .271.073l.802 1.388a.2.2 0 0 1-.073.272c-1.566.904-1.566 3.164 0 4.069a.2.2 0 0 1 .073.271l-.802 1.388a.2.2 0 0 1-.271.073C10.958 10.863 9 11.993 9 13.8a.2.2 0 0 1-.199.2H7.2a.2.2 0 0 1-.2-.2c0-1.808-1.958-2.938-3.524-2.034a.2.2 0 0 1-.272-.073l-.8-1.388a.2.2 0 0 1 .072-.271c1.566-.905 1.566-3.165 0-4.07a.2.2 0 0 1-.073-.27l.801-1.389a.2.2 0 0 1 .272-.072C5.042 5.138 7 4.007 7 2.199c0-.11.089-.199.199-.199M5.5 2.2c0-.94.76-1.7 1.699-1.7H8.8c.94 0 1.7.76 1.7 1.7a.85.85 0 0 0 1.274.735 1.7 1.7 0 0 1 2.32.622l.802 1.388c.469.813.19 1.851-.622 2.32a.85.85 0 0 0 0 1.472 1.7 1.7 0 0 1 .622 2.32l-.802 1.388a1.7 1.7 0 0 1-2.32.622.85.85 0 0 0-1.274.735c0 .939-.76 1.7-1.699 1.7H7.2a1.7 1.7 0 0 1-1.699-1.7.85.85 0 0 0-1.274-.735 1.7 1.7 0 0 1-2.32-.622l-.802-1.388a1.7 1.7 0 0 1 .622-2.32.85.85 0 0 0 0-1.471 1.7 1.7 0 0 1-.622-2.32l.801-1.389a1.7 1.7 0 0 1 2.32-.622A.85.85 0 0 0 5.5 2.2m4 5.8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0" clip-rule="evenodd"/></svg> **Settings**.
    1. Navigate to **Autocompletion**.
    1. In the settings window that opens, enable or disable the **Code Assistant suggestion indicator** and **Code Assistant load indicator**.

    ![image](../../_assets/code-assistant/vsc-settings-screen.png)

  - JetBrains IDE {#jb}

    1. In the top-right corner, click <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M7.199 2H8.8a.2.2 0 0 1 .2.2c0 1.808 1.958 2.939 3.524 2.034a.2.2 0 0 1 .271.073l.802 1.388a.2.2 0 0 1-.073.272c-1.566.904-1.566 3.164 0 4.069a.2.2 0 0 1 .073.271l-.802 1.388a.2.2 0 0 1-.271.073C10.958 10.863 9 11.993 9 13.8a.2.2 0 0 1-.199.2H7.2a.2.2 0 0 1-.2-.2c0-1.808-1.958-2.938-3.524-2.034a.2.2 0 0 1-.272-.073l-.8-1.388a.2.2 0 0 1 .072-.271c1.566-.905 1.566-3.165 0-4.07a.2.2 0 0 1-.073-.27l.801-1.389a.2.2 0 0 1 .272-.072C5.042 5.138 7 4.007 7 2.199c0-.11.089-.199.199-.199M5.5 2.2c0-.94.76-1.7 1.699-1.7H8.8c.94 0 1.7.76 1.7 1.7a.85.85 0 0 0 1.274.735 1.7 1.7 0 0 1 2.32.622l.802 1.388c.469.813.19 1.851-.622 2.32a.85.85 0 0 0 0 1.472 1.7 1.7 0 0 1 .622 2.32l-.802 1.388a1.7 1.7 0 0 1-2.32.622.85.85 0 0 0-1.274.735c0 .939-.76 1.7-1.699 1.7H7.2a1.7 1.7 0 0 1-1.699-1.7.85.85 0 0 0-1.274-.735 1.7 1.7 0 0 1-2.32-.622l-.802-1.388a1.7 1.7 0 0 1 .622-2.32.85.85 0 0 0 0-1.471 1.7 1.7 0 0 1-.622-2.32l.801-1.389a1.7 1.7 0 0 1 2.32-.622A.85.85 0 0 0 5.5 2.2m4 5.8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0" clip-rule="evenodd"/></svg> and select **Settings...**.
    1. In the left-hand column, select **SourceCraft Code Assistant**.
    1. Enable or disable **Disable suggest indicator**.
    1. To save the settings, click **Apply**.

    ![image](../../_assets/code-assistant/jb-settings-screen.png)

{% endlist %}
<!-- endsource: en/_includes/code-assistant/help-indicator.md -->

#### Useful links {#see-also}

* [Getting started with SourceCraft Code Assistant](https://sourcecraft.dev/portal/docs/en/code-assistant/index.md)
* [SourceCraft Code Assistant chat interface in the JetBrains IDE](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat.md)
* [SourceCraft Code Assistant overview](https://sourcecraft.dev/portal/docs/en/code-assistant/concepts/index.md)