Managing chat context in SourceCraft Code Assistant

Context is auxiliary information that Code Assistant uses to generate relevant and consistent chat responses.

Functionality varies depending on the IDE you are using.

Note

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

Adding information to context

  1. Click SourceCraft Code Assistant in the editor’s left panel.

    If you have many plugins, the chat button may be hidden in the menu.

    Alternatively, use Ctrl + L in Windows/Linux or Command + L in macOS.

  2. In the message input window, click or enter @ and select which information you want to add to the context:

    • Files & folders: File or directory from a project opened in the IDE. Start typing the file or directory name, e.g., sch, and select the relevant option, e.g., schema.json.

      Warning

      When you select a directory, only its top-level files will be included in the context.

    • Rules: Rules that Code Assistant must comply with when responding.

    • Current file: File opened in the current tab.

    • Open tabs: All tabs opened in the IDE.

    • Recent changes: Changes in the project since pushing the last commit (git push), displayed by git diff or git diff --staged. This is only relevant if the project uses git for version control.

    • Terminal: Last lines from the active IDE terminal.

    • Problems: All notifications from the IDE’s Problems menu.

    To add information from a web page to the context, enter @<page_URL>, e.g., @https://sourcecraft.dev/portal/docs/ru/code-assistant/.

    To go to the next list in the context selection menu, click Back or press Ctrl + Alt + for Windows or Linux or Command + Option + for macOS.

    Tip

    After reviewing the context types, we recommend using manual input. For example, start typing the first letters, @term, and then use , , and Enter to select Terminal from the drop-down list. You can also enter the names of directories, files, and rules.

  1. In the editor's right-hand panel, click SourceCraft Code Assistant Chat.

  2. In the message input window, click Add Files and Folders to Context.

  3. Select a file or directory.

    Warning

    When you select a directory, only its top-level files will be included in the context.

Viewing the current context

  1. In the message input window, click .
  2. To go to the content of the current context, e.g., the IDE terminal window, and select an item from the drop-down list.

In the message input window, click .

Deleting information from the context

This feature is only available in Visual Studio Code.

  1. In the message input window, click .
  2. Hover over the context item you want to delete and click .

Viewing used context

After sending a message to the chat, the context becomes fixed, e.g., the Open tabs context type will be represented by specific files.

To see which information was used in the request context:

  1. Below the SourceCraft Code Assistant message title, click Used N references .
  2. To view information from the context, e.g., a specific file, select that item from the drop-down list.

Below the title of your message (Me), click to the right of Used references.

Setting default context

This feature is only available in Visual Studio Code.

You can add the following information to the default context for each request:

  • Current file: File opened in the current tab.
  • Open tabs: All tabs opened in the IDE.
  • Recent changes: Changes in the project since pushing the last commit (git push), displayed by git diff or git diff --staged. This is only relevant if the project uses git for version control.

Note

This context will also be displayed in the menu, and you can extend or delete it.

To set default context:

  1. Click Settings in the chat's top panel.
  2. Under Sourcecraft-code-assist: Predefined Context, edit the default context:
    • To delete a context type, hover over it and click .
    • To update a context type, hover over it, click , and select a new type.
    • To add a new context type, click Add item, select the new type, and click OK.

Enabling context accumulation

This feature is only available in Visual Studio Code.

You can enable context accumulation for the entire current chat session. The context from each previous message will be submitted to the next one, except for the Current file and Open tabs context types. For these types, new context information is generated with each new message sent to the chat.

Note

The accumulated context will also be displayed in the menu, and you can extend or delete it.

Context accumulation is disabled by default.

To enable context accumulation:

  1. Click Settings in the chat's top panel.
  2. Under Sourcecraft-code-assist: Accumulate Context Enabled, enable Accumulating context from previous chat messages.

See also