Search
Close this search box.

Free Coding with AI – Continue plugin for IntelliJ

free coding with AI continue plugin for intelliJ

Table of Contents

1. Introduction

Today development gain new level due to quite good code generators based on LLM models. Programmer can access online chat’s but that require copy/paste between IDE and web browser. Instead you can embedded necessary interface in your favorite editor and even allow manipulation over your code. In this article I will explore tool called Continue.

2. Prerequisites

To fallow steps you need to install

At beginning I will show you how to leverage OpenAI model so you can skip Ollama and Docker installation.

3. Installing Continue plugin

Open IntelliJ and Go to Settings -> Plugin, then type in search box ‘Continue’.
You will see plugin in results so click on install button.

installing continue plugin

4. Explain code

Select code you want to understand with AI and use Command + J (on macBook) so it will open new session with code as subject. I am using below example code in Java – this is about problem of year 2038 which I described in the video.

				
					public class Year2038 {
    public static void main(String[] args) {

        int epochOneSecondBeforeDeadline = 2147483647; // EPOCH represent 2038-01-09 03:14:07 UTC
        System.out.println(epochOneSecondBeforeDeadline);

        System.out.println(epochOneSecondBeforeDeadline + 1); // Adding One Second - HERE we have 2038 problem
        System.out.println(epochOneSecondBeforeDeadline + 2); // Adding Two Seconds

    }
}
				
			

Type under code element “please explain me this code”. Default model was selected as GPT-4 so it is using external serves to interpret prompt and return answer like below

This code is demonstrating the Year 2038 problem, also known as the Unix Y2K38 problem. The issue arises from the way Unix-based systems (like Linux and MacOS) store time information.

In Unix systems, time is represented as a signed 32-bit integer which counts the number of seconds that have passed since January 1, 1970 (known as the Unix epoch). However, a 32-bit integer can only store values up to 2,147,483,647. After this point, it will overflow and start counting from -2,147,483,648.

The "epochOneSecondBeforeDeadline" variable in the code represents the maximum value that a 32-bit integer can store, which corresponds to the date and time 2038-01-19 03:14:07 UTC.

with same window you can ask follow up questions like “why it is problem?”

5. Edit code with help of AI

select again code and Command + J shortcut to start new session.

edit code

start with slash and choose ‘/edit’ then type “improve code”, hit enter. It will open difference window for you known also from code commit actions. You can approve or reject changes. I accepted my changes but in my case it was making a mess by removing class declaration line – this code will not compile now.

buggy improvement

I added missing line myself and made it work.

				
					public class Year2038 {
    public static void main(String[] args) {

        long epochOneSecondBeforeDeadline = 2147483647L; // EPOCH represent 2038-01-19 03:14:07 UTC
        System.out.println(epochOneSecondBeforeDeadline);

        System.out.println(epochOneSecondBeforeDeadline + 1); // Adding One Second - No more 2038 problem
        System.out.println(epochOneSecondBeforeDeadline + 2); // Adding Two Seconds

    }
}

				
			

code improved although with human intervention.

				
					2147483647
2147483648
2147483649

Process finished with exit code 0
				
			

6. Write comments for your code

Good code should be self explanatory but when AI generating it who knows what will be the answer. Here you are ‘/comment’ command will make it auto-commented.

				
					public class Year2038 {
    public static void main(String[] args) {

        // Initialize a long variable to represent the Epoch time one second before the 2038 problem deadline
        long epochOneSecondBeforeDeadline = 2147483647L; // EPOCH represent 2038-01-19 03:14:07 UTC
        // Print the Epoch time one second before the 2038 problem deadline
        System.out.println(epochOneSecondBeforeDeadline);

        // Print the Epoch time of the 2038 problem deadline by adding one second to the Epoch time one second before the deadline
        System.out.println(epochOneSecondBeforeDeadline + 1); // Adding One Second - No more 2038 problem
        // Print the Epoch time two seconds after the 2038 problem deadline by adding two seconds to the Epoch time one second before the deadline
        System.out.println(epochOneSecondBeforeDeadline + 2); // Adding Two Seconds

    }
}

				
			

7. Test generation

For those who do not writting test for their code.
‘/test’ – command will generate tests. Right now you need to copy/paste them in the file yourself.

				
					import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Year2038Test {
    private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    private final PrintStream originalOut = System.out;

    @Before
    public void setUpStreams() {
        System.setOut(new PrintStream(outContent));
    }

    @Test
    public void testMain() {
        Year2038.main(new String[]{});
        String[] lines = outContent.toString().split(System.getProperty("line.separator"));
        assertEquals("2147483647", lines[0]);
        assertEquals("2147483648", lines[1]);
        assertEquals("2147483649", lines[2]);
    }

    @Test
    public void testMainWithEdgeCases() {
        Year2038.main(new String[]{});
        String[] lines = outContent.toString().split(System.getProperty("line.separator"));
        assertEquals("2147483647", lines[0]);
        assertTrue(Long.parseLong(lines[1]) > 2147483647L);
        assertTrue(Long.parseLong(lines[2]) > 2147483647L);
    }

    @After
    public void restoreStreams() {
        System.setOut(originalOut);
    }
}

				
			

GPT-4 added description for results:


These tests first set up a way to capture the output from the System.out.println calls in the main method of the Year2038 class. The testMain method checks that the output is as expected. The testMainWithEdgeCases method checks that the output for the epoch times after the 2038 problem deadline are greater than the epoch time one second before the deadline. After each test, the output stream is restored to its original state.

8. Shell command generator

There is also /cmd option to create shell command like

				
					 /cmd running this java program
 Generated shell command: java -jar /path/to/your/program.jar
				
			

9. Sharing prompts with others

By executing /share you can save markdown file at ~/.continue/session.md

Which contain all prompts from session.

10. Running local models

10.1 Start Ollama

First start ollama and then run model in the shell like:

				
					ollama run wizardcoder:33b
pulling manifest 
pulling c41199acd137... 100% ▕████████████████▏  18 GB                         
pulling 876a8d805b60... 100% ▕████████████████▏  10 KB                         
pulling 2d836d77287d... 100% ▕████████████████▏   61 B                         
pulling 1678ff0c9fe5... 100% ▕████████████████▏  105 B                         
pulling 2f8ec66c33f4... 100% ▕████████████████▏  484 B                         
verifying sha256 digest 
writing manifest 
removing any unused layers 
success 
>>> 
Use Ctrl + d or /bye to exit.
>>> 

				
			

Model I used taking 18GB of disk space and it will take some time to download it.
You can use 7b parameters version of this model if you do not have free 32GB of RAM and less disk space.

10.2 Add model in Continue

When you click on plus button you can go through wizard to add new model.

adding new model

or click on options icon to edit config.json

In this case you can place new model definition inside models array

				
					{
  "models": [
  ...
    {
      "title": "wizardcoder:33b",
      "provider": "ollama",
      "model": "wizardcoder:33b"
    }
  ],
				
			

Then model appears on the list

Now you can use wizardcoder model same way as GPT-4 but without privacy concern.

/edit improve code

gave me result (I had to add class Year2038 line again manually)

				
					public class Year2038 {
    public static void main(String[] args) {

        // Initialize a long variable to represent the Epoch time one second before the 2038 problem deadline
        final long epochOneSecondBeforeDeadline = 2147483647L; // EPOCH represent 2038-01-19 03:14:07 UTC

        // Print the Epoch time one second before the 2038 problem deadline
        System.out.println("Epoch time one second before the 2038 problem deadline: " + epochOneSecondBeforeDeadline);

        // Calculate and print the Epoch time of the 2038 problem deadline by adding one second to the Epoch time one second before the deadline
        final long epochOfTheDeadline = addOneSecond(epochOneSecondBeforeDeadline);
        System.out.println("Epoch time of the 2038 problem deadline: " + epochOfTheDeadline); // No more 2038 problem

        // Calculate and print the Epoch time two seconds after the 2038 problem deadline by adding one second to the Epoch time of the 2038 problem deadline
        final long epochTwoSecondsAfterDeadline = addOneSecond(epochOfTheDeadline);
        System.out.println("Epoch time two seconds after the 2038 problem deadline: " + epochTwoSecondsAfterDeadline); // No more 2038 problem
    }

    // Method to add one second to a given Epoch time
    public static long addOneSecond(long epochTime) {
        return epochTime + 1;
    }
}
				
			

11. Conclusion

In this article you have learned how add Continue plugin to IntelliJ and how to use it for code explanation, improvement and test generation. Now you can start using it on daily basis as your AI code assistant.

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow me on LinkedIn
Share the Post:

Enjoy Free Useful Amazing Content

Related Posts