Code autocompletion in SourceCraft Code Assistant

Note

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

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.

Use case

In this example, we use the insert mode to revise the code, and then, the replace mode, which provides suggestions for the next lines based on the edits we made:

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

Insert mode

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

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.
  1. Open the IDE and create a test file named server.cpp with the following contents:

    // 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() {
    
    }
    
  2. In the int main() section, start typing something, e.g., //create socket. See the Code Assistant suggestion:

    ...
    int main() {
    
    //create socket
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    
    }
    
  3. Select an action for the suggestion:

    • 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.
    • 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

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

    image

You can also watch our Code Assistant video tutorial here.

Replace mode

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:

    def fibonacci(k):
        if k == 0:
            return 0
        elif k == 1:
            return 1
        else:
            return fibonacci(k-1) + fibonacci(k-2)
    
    print(fibonacci(10))
    
  2. For example, change the variable name from k to n. See the Code Assistant corrections:

    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.

  3. 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.

Suggestion indicator

When generating a suggestion, the loading icon will appear to the left of the editable code. If generation stops or there is no result, you will see the (no suggestion) icon.

The suggestion indicator is enabled by default.

To enable or disable the indicator:

  1. In the left-hand panel, click .
  2. In the panel that opens, select Settings.
  3. Navigate to Autocompletion.
  4. In the settings window that opens, enable or disable the Code Assistant suggestion indicator and Code Assistant load indicator.

image

  1. In the top-right corner, click and select Settings....
  2. In the left-hand column, select SourceCraft Code Assistant.
  3. Enable or disable Disable suggest indicator.
  4. To save the settings, click Apply.

image

See also