This text describes the GitHub Copilot instrument and the primary tips and assumptions concerning its use in software program growth tasks. The rules concern each the instrument’s configuration and its utility in on a regular basis work and assume the reader will use GitHub Copilot with IntelliJ IDEA (by way of a devoted plugin).
GitHub Copilot: What Is It?
GitHub Copilot is an AI developer assistant that makes use of a generative AI mannequin educated for all programming languages obtainable in GitHub repositories. The total description and documentation of the instrument is out there right here.
There are different related instruments in the marketplace, similar to OpenAI Codex, JetBrains AI Assistant, or Tabnine, however GitHub Copilot stands out as a result of following options:
- The most important and most numerous assortment for coaching an AI mannequin – GitHub repositories
- Estimated utilization share – presently approx. 40-50% (in accordance with Abhay Mishra’s article primarily based on undisclosed business insights), however the market may be very dynamic
- Assist for standard applied sciences – we’ve examined it with the Java programming language, Scala, Kotlin, Groovy, SQL, Spring, Dockerfile, OpenShift, Bash
- Superb integration with the JetBrains IntelliJ IDEA IDE
- Low entry-level on account of fast and straightforward configuration, basic ease of use, clear documentation, and plenty of utilization examples on the web
- A variety of functionalities, together with:
- Solutions whereas writing code
- Producing code primarily based on feedback in pure language
- Taking present code into consideration when producing a brand new code snippet
- Creating unit assessments
- Chat – means that you can ask questions concerning code, language, and expertise, in addition to suggests corrections for simplifying the code
- CLI – assist for working within the console and creating bash scripts
Our Objectives
Our important purpose for utilizing GitHub Copilot was to enhance the effectivity of writing code and its high quality. As well as, we meant it to assist and help us in work during which programmers lack information and expertise. Listed here are the precise objectives that we needed our growth crew to attain by utilizing GitHub Copilot:
1. Accelerating Growth
- Producing code fragments
- Producing SQL queries
- Hints for creating and modifying OpenShift and Dockerfile configuration recordsdata
- Sooner seek for options utilizing the chat operate, e.g., rationalization of normal expressions, operation of libraries or framework mechanisms
2. Bettering Code High quality
- Producing unit assessments with edge instances – each in Java and Groovy languages
- Suggesting corrections and simplifications in our personal code
3. Working With Much less Incessantly Used Applied sciences
- Explaining and producing code (together with unit assessments) in Scala and Kotlin
- Assist whereas utilizing “legacy” options like Activiti, and many others.
- Assist in creating and understanding configuration recordsdata
4. Extra Environment friendly Administrative Work within the Console Utilizing CLI Features
Instrument Limitations Tips
Since GitHub Copilot relies on generative AI, you should at all times keep in mind that it could generate incorrect code or responses. Subsequently, when utilizing the instrument, you should pay attention to potential limitations and apply the precept of restricted belief and verification. The principle limitations are offered within the desk beneath.
Limitation | Description |
Restricted scope of data | The instrument relies on code present in GitHub repositories. Some issues, or complicated buildings, languages or information notations, have poor illustration within the coaching units |
Dynamic growth and options within the beta section | The instrument is creating very dynamically. Patches and updates seem each week or each a number of weeks, which signifies that many components of the instrument aren’t working correctly. Some functionalities, similar to GitHub Copilot CLI, are nonetheless in beta |
Inaccurate code | The instrument supplier informs that the generated code might not meet the consumer’s expectations, might not remedy the precise drawback, and should include errors |
Inaccurate chat responses | When utilizing chat, the accuracy of the reply relies upon largely on the query or command formulated. The documentation says that “Copilot Chat is not designed to answer non-coding questions”, so there are doable solutions, particularly in areas not strictly associated to the code (design, and many others.), that won’t be applicable and even wise |
Harmful code | The coaching set (repositories) might also include code components that violate safety guidelines, each in the safety and security sense, similar to API keys, community scanning, IP addresses, code that overloads assets or causes reminiscence leaks, and many others. |
To attenuate the adverse affect of the recognized GitHub Copilot limitations, you must at all times:
- Verify various recommendations (utilizing Ctrl+[ and Ctrl+], and many others.) and select those that greatest go well with a given state of affairs
- Learn and analyze the correctness of the generated code
- Take a look at and run code in pre-production environments – primarily regionally and within the growth surroundings
- Submit the generated code to code assessment
Vital: By no means deploy the code generated by GitHub Copilot to manufacturing environments with out performing the above checks.
Configuration Tips
On this part, we’ll current the fundamental info concerning the pricing plans (with benefits and drawbacks for every possibility, as seen from the attitude of our meant objectives) and private account configuration (for each GitHub Copilot and the IntelliJ IDEA plugin).
Pricing Plans
GitHub Copilot gives three subscription plans with totally different scopes of supplied performance and value. In our case, two plans have been price contemplating: Copilot Particular person or Copilot Enterprise. The Copilot Enterprise plan moreover gives entry to talk by way of the github.com web site and producing summaries for pull requests, which was unimportant for our assumed objectives (however it could be totally different in your case). Each plans’ important benefits and drawbacks are offered within the desk beneath.
Plan | Benefits | Disadvantages |
GitHub Copilot Particular person | Decrease price at $10/month/consumer
Provides the important thing performance required to attain the meant objectives |
Lack of management over instrument configuration and consumer entry by the group |
GitHub Copilot Enterprise | Provides the important thing performance required to attain the meant objectives
Management over instrument configuration and consumer entry by the group |
Larger price at $19/month/consumer |
In our case, Copilot Enterprise was the higher possibility, particularly as a result of it permits full management over the configuration and entry to the instrument for builders within the crew. For those who’re working by yourself, the Copilot Particular person plan is perhaps sufficient.
Account Configuration
You’ll be able to configure GitHub Copilot when buying a subscription plan, and the settings may also be modified after activating the account within the group’s account settings on GitHub. On the account degree, there have been two key parameters for our use case to configure in GitHub Copilot, described within the desk beneath.
Possibility identify | Description | Advisable settings |
Solutions matching public code | Accessible choices:
Allowed and Blocked Determines whether or not to point out or to dam code recommendations that overlap round 150 strains with public code |
Blocked
This feature reduces the danger of duplicating code from public repositories, thus lowering the uncertainty in regards to the copyright possession of the code |
Enable GitHub to make use of my code snippets for product enhancements | Accessible choices: Sure and No
Determines whether or not GitHub, its associates, and third events might use consumer code snippets to discover and enhance GitHub Copilot recommendations, associated product fashions, and options |
No
For those who plan to make use of GitHub Copilot for industrial functions, GitHub and its related entities shouldn’t use consumer code on account of copyright issues |
Here’s a detailed description and directions for altering configuration choices in your GitHub account.
IntelliJ IDEA Plugin Configuration
To allow GitHub Copilot within the IntelliJ IDEA IDE, you should set up the GitHub Copilot extension from the Visible Studio Code market. Set up is finished by way of the IDE within the plugin settings. After set up, log in to your GitHub account together with your system code. You will discover detailed directions for putting in and updating the plugin right here.
The GitHub Copilot plugin for the IntelliJ IDEA IDE gives the power to configure the next issues:
- Computerized submission of recommendations
- The way in which recommendations are displayed
- Computerized plugin updates
- Supported languages
- Keyboard shortcuts
In our case, utilizing the default plugin settings was advisable as a result of they guarantee good working consolation and are suitable with the present instrument documentation. Any adjustments to the configuration may be made by every consumer in accordance with their very own preferences.
How To Use GitHub Copilot in IntelliJ
Listed here are some tips for utilizing key functionalities that can allow you to use the GitHub Copilot instrument optimally.
Producing Utility Code
When To Use
- Creating lessons
- Creating fields, strategies, constructors
- Writing code snippets inside strategies
How To Use
- By writing code and utilizing automated recommendations – it’s at all times price checking different recommendations utilizing the Ctrl+] / Ctrl+[ keys
- By writing concise and precise comments in natural English
- Using the chat function – the chat can generate a fragment of code in response to a query (see examples in the section “Using the GitHub Copilot Chat” below) and allows you to quickly generate code using the Copy Code Block or Insert Code Block at Cursor buttons that appear in the section with code in the chat window
Writing Unit Tests
When To Use
- Creating new classes and methods that we want to cover with unit tests
- Coverage of existing classes and methods with unit tests
How To Use
- By writing a comment in the test class. For example, if you write
// Unit test in JUnit for CurrencyService
, you will get the following result:
- It is possible to generate individual test methods by entering in the comment the test case that the method is to test. Similarly, you can generate mocks in the test class.
- Using the chat – you can select the GitHub Copilot > Generate Test option from the context menu, enter the
/tests
command, or write an instruction in a natural language, e.g.,Generate unit test for class CurrencyService
. In response, you will receive a descriptive explanation of the test structure and the code of the entire test class:
Generating SQL Queries and Stored Procedures
When To Use
- When writing DDL, DML, and DQL queries that will be used in the application
- During data analysis and errors related to data in the database
- When writing scripts and stored procedures
How To Use
- IMPORTANT: you must have a database connection configured in IntelliJ IDEA or DataGrip
- By writing queries and using automatic suggestions
- By writing a comment, e.g. if you write
– – get party data for account
, you will get the following result:
Creating OpenShift Configuration or Other Configuration Files
When To Use
- Creating or modifying configuration files
- Analysis of directives, their options and values, and configuration mechanisms
How To Use
- By writing directives and using automatic suggestions
- Using the chat – you can select the directive and choose GitHub Copilot > Explain This from the context menu, enter the /explain command, or write a query in natural language about a given configuration element
Using the BASH Console
When To Use
- When trying to use obscure console commands
- For an explanation of command operation and its options
- To find the right command to perform a task
- When writing BASH scripts
How To Use
- IMPORTANT: to use the CLI tool, install GitHub CLI with the gh-copilot extension according to the instructions
- Currently, the tool offers two commands, summarized in the table below
Command | Example | Result |
gh copilot suggest | # gh copilot suggest “find IP number in text file” | grep -E -o ‘([0-9]{1,3}.){3}[0-9]{1,3}’ |
gh copilot clarify | # gh copilot clarify “curl -k” | curl is used to concern net requests, e.g., obtain net pages
–ok or –insecure permits curl to carry out insecure SSL connections and transfers |
How To Use GitHub Copilot Chat
We’ve written a separate chapter for the GitHub Copilot Chat – as there are a number of use instances price speaking about. Let’s undergo them individually and focus on particular tips for every case.
Creating New Functionalities
When To Use
- If you find yourself searching for an answer to an issue, similar to creating an internet site, a technique that performs a selected activity, error dealing with for a given block of code/methodology/class, and many others.
How To Use
- Enter a question in pure English concerning the performance you might be searching for. It ought to concern subjects associated to programming – code, frameworks/libraries, companies, structure, and many others. Beneath is an instance for the question: Learn how to get forex trade information?
Utilizing Common Expressions
When To Use
- When it’s good to create and confirm a daily expression
How To Use
- Enter a question in pure English concerning the sample you might be searching for. The instance beneath reveals a generated methodology with an incorrect sample, a question, and a response with an evidence and corrected code
Discovering Errors within the Code
When To Use
- Whenever you create new lessons or strategies
- When analyzing a category or methodology that causes errors
How To Use
- You’ll be able to choose the code and select GitHub Copilot > Repair This from the context menu, enter the
/repair
command, or write an instruction in pure English, e.g., Discover doable errors on this class. You’ll be able to specify a command to a technique identify or error kind. For instance, for a easy class, explanations of potential errors have been obtained, and the chat generated code to deal with these errors:
Rationalization of Present Code
When To Use
- Whenever you don’t perceive what precisely a module, class, methodology, piece of code, common expression, and many others., does
- Whenever you don’t know the framework or library mechanism used
How To Use
- In a category or methodology, you possibly can choose GitHub Copilot > Clarify this from the context menu, kind the
/clarify
command, or write a question in pure English in regards to the problematic code ingredient, e.g., Clarify what is that this class doing. The instance beneath presents an evidence of the category and its strategies. This is applicable to the category generated within the bug-finding instance
Simplify Present Code
When To Use
- When the code is difficult and obscure or unnecessarily intensive
- When refactoring the code
How To Use
- In a category or chosen methodology or code fragment, you possibly can choose GitHub Copilot > Simplify This from the context menu, kind the
/simplify
command, or write a question in pure English. An instance of a easy methodology of refactoring for a category is beneath:
The consequence:
Abstract: A Highly effective Instrument, as Lengthy as You’re Cautious
As you possibly can see, GitHub Copilot is usually a highly effective instrument in a software program developer’s arsenal. It might probably pace up and simplify numerous processes and day-to-day duties. Nonetheless, as with all issues associated to generative AI, you possibly can by no means totally belief this instrument – subsequently, the essential rule is to at all times learn, assessment, and check what it creates.