Find Related Code in the Copilot
Find Related Code is an experimental feature that allows you to quickly find files in your codebase that may be related to the current file that you are coding in.
grep, using your editor's find all references feature, asking your teammates, etc.
The rest of this article will show you how to use Find Related Code in your editor of choice.
Find Related Code works in all Kite-supported editors except for Spyder and JupyterLab.
For the rest of this article, we will use Kite's codebase as an example. Specifically, we will be looking at the parts of Kite's codebase which implement the editor plugin manager.
You can use Find Related Code from almost any source code file inside a Git project. If you see the Kite indicator message at the bottom of your editor, then the file that you have open will work with Find Related Code.
Within a supported file, there are two ways to access Find Related Code.
Find Related Code by file
If you have a file open and want to quickly find other files that may be relevant to the currently open file, you can use Find Related Code to do so.
To make this more concrete, let's imagine you have
Say you want to use Find Related Code to find the backend code which sends data to the UI. To do so, you can open your editor's command palette and run the command
Kite: Find Related Code From File.
In JetBrains editors, you would use the action finder to run the action
Kite: Find Related Code From File.
In Vim, you would run the command
Kite will then search for files related to
Plugins.js and display the results in the Copilot.
Taking a quick look at the results, you notice two Go files
plugin_status.go (result 4) and
plugin.go (result 7) that seem promising. Let's take a look at the result for
Find Related Code shows you the keywords in
plugin_status.go which indicate that it may be related to
Plugins.js. You can use these keywords to do a quick sanity check to determine whether or not you think this file is relevant.
Browsing code blocks
You can also click on the file name to show the code blocks that Find Related Code deemed to be relevant. The code blocks will expand below the file name.
In this case, it looks like
plugin_status.go defines the data type that abstracts the concept of a plugin installation on a system.
You can also open
plugin_status.go in your editor by clicking on the "Open" link next to the file name.
You can also click on an expanded code block to open the file at the start of the shown code block.
Find Related Code by line
In some situations, you may only want to look for files that are related to a specific line or region in an open file.
For example, let's assume the reverse situation from above — You now have the file
plugin_status.go open and you want to find the frontend code that uses the data type
In this situation, you can position your cursor over the line that starts the type definition, and then click on the tooltip that reads
Find related code in kiteco.
In JetBrains editors, you can click on the intention icon to reveal the intention
Kite: Find code in kiteco related to this line.
In Vim, you will need to manually run the command
Running Find Related Code from the line will then open the search results the Copilot.
In this case, you can see that
Plugins.js is result 2.
Note that can also run the command (action)
Kite: Find Related Code From Line via the command palette (action finder).
Share your feedback
Find Related Code was designed as a quicker alternative to navigate large and intricate codebases. If you have thoughts on how to improve this feature, we'd love to hear from you! Feel free to submit a feature request in our issue tracker with your ideas.