DEV Community

Cover image for Use inline completions for more answers with GitHub Copilot Free
Jesse Houwing
Jesse Houwing

Posted on • Originally published at jessehouwing.net on

Use inline completions for more answers with GitHub Copilot Free

2 months ago, GitHub gave everybody their taste of GitHub Copilot with the limited free tier. You get 2000 completions and 50 chats.

This is awesome! But 50 chats aren't that many.

Did you know you can use your completions for simple chat answers as well? And this is a nice tip for NeoVim users as well who don't have access to Chat in their editor. Inline Suggestions are significantly faster than Chat to boot.

You can use inline completions to get tips, answer questions and suggest improvements to your code as well.

Q&A

// Q: Explain the key usage scenarios for the Singleton pattern
// A: The singleton pattern |
Enter fullscreen mode Exit fullscreen mode

In most cases typing // A: will do the trick, but sometimes you'll need to give Copilot a starting sentence to provide you with an answer:

// Q: Explain the key usage scenarios for the Singleton pattern. A detailed description
// A: The Singleton pattern is used when we want to ensure that a class has only one instance and provide a global point of access to that instance. Some key usage scenarios for the Singleton pattern include:
Enter fullscreen mode Exit fullscreen mode

If you type // - on the next line or open the completions panel (ctrl-enter), you'll get more details:

// 1. Global Access: It provides a single point of access to the instance of the class, allowing other objects to easily access and use its functionality.
// 2. Resource Management: It can be used to manage shared resources, such as database connections, file systems, or configuration settings, ensuring that there is only one instance to avoid conflicts or resource wastage.
// 3. Caching: It can be used to implement a cache that stores frequently used data or objects in memory, reducing the need to recreate or fetch them from external sources.
// 4. Logging: It can be used to create a single logger instance that logs messages from different parts of the application, centralizing the logging functionality.
// 5. Configuration Settings: It can be used to manage application-wide configuration settings, ensuring that changes are reflected consistently across the application.
// 6. State Management: It can be used to maintain a shared state or context across different parts of the application, allowing objects to share and update state information.
// 7. Thread Safety: It can be used to provide a thread-safe way to access and modify shared resources or data, ensuring that concurrent access does
Enter fullscreen mode Exit fullscreen mode

Suggest test cases

You can also ask questions about the contents of the current file:

// Suggest additional test cases to add to this test fixture, signatures only:
// |
Enter fullscreen mode Exit fullscreen mode

Returns the following suggestions:

// public void GetById_WhenFlightDoesNotExist_ReturnsNull()
// public void Add_WhenFlightIsNull_DoesNotAddFlightToRepository()
// public void Add_WhenFlightHasNullFlightNumber_ThrowsException()
// public void Add_WhenFlightHasEmptyFlightNumber_ThrowsException()
// public void Add_WhenFlightHasNullOrigin_ThrowsException()
// public void Add_WhenFlightHasEmptyOrigin_ThrowsException()
// public void Add_WhenFlightHasNullDestination_ThrowsException()
// public void Add_WhenFlightHasEmptyDestination_ThrowsException()
// public void Add_WhenFlightHasDepartureTimeInThePast_ThrowsException()
// public void Add_WhenFlightHasArrivalTimeBeforeDepartureTime_ThrowsException()
// public void Add_WhenFlightHasFuelRangeLessThanZero_ThrowsException()
// public void Add_WhenFlightHasFuelTankLeakTrue_ThrowsException()
// public void Add_WhenFlightHasNullFlightLogSignature_ThrowsException()
// public void Add_WhenFlightHasEmptyFlightLogSignature_ThrowsException()
// public void Add_WhenFlightHasNullAerobaticSequenceSignature_ThrowsException()
// public void Add_WhenFlightHasEmptyAerobaticSequenceSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateId_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumber_ThrowsException()
// public void Add_WhenFlightHasDuplicateOriginAndDestination_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightLogSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateAerobaticSequenceSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumberAndOriginAndDestination_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumberAndFlightLogSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumberAndAerobaticSequenceSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumberAndOriginAndDestinationAndFlightLogSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumberAndOriginAndDestinationAndAerobaticSequenceSignature_ThrowsException()
// public void Add_WhenFlightHasDuplicateFlightNumberAndFlightLogSignatureAndAerobaticSequenceSignature_ThrowsException()
Enter fullscreen mode Exit fullscreen mode

Suggest improvements

You can ask for improvements you can make to the current code file:

// To improve the security of this REST API I can:
// |
Enter fullscreen mode Exit fullscreen mode

And GitHub Copilot will reply with:

// add an authorization filter to this controller
// and require authentication for all actions
// using the [Authorize] attribute
Enter fullscreen mode Exit fullscreen mode

You can tweak the replies by adding // and or //something else I could do is

Conclusion

If you run out of Chat messages, you can continue the conversation using inline suggestions. If you run out of those too, you seem to be getting enough value from GitHub Copilot to warrant a subscription ;).

This also adds a bit of Chat support to NeoVim, Qt Explorer, XCode and other tools that only support inline suggestions for now.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay