How to Use GitHub Copilot in VS Code With Polyglot Notebooks
🔍 WiseChecker

How to Use GitHub Copilot in VS Code With Polyglot Notebooks

Polyglot Notebooks in VS Code let you write code in multiple languages inside one file. You can mix Python, JavaScript, SQL, and more in separate cells. GitHub Copilot provides code suggestions as you type in each cell. This article explains how to set up Copilot for Polyglot Notebooks and write multi-language code efficiently.

Key Takeaways: Using GitHub Copilot in Polyglot Notebooks

  • VS Code > Extensions > Polyglot Notebooks: Install the extension to enable multi-language notebook support in VS Code.
  • GitHub Copilot extension for VS Code: Must be installed and signed in with an active GitHub Copilot subscription.
  • Language specifier in cell metadata: Set the language for each cell using the language dropdown or code comment so Copilot provides correct suggestions.

ADVERTISEMENT

What Are Polyglot Notebooks and How Does Copilot Work With Them

Polyglot Notebooks, previously known as .NET Interactive Notebooks, are a VS Code extension that lets you create a single notebook file with cells that run different programming languages. Each cell can be set to a specific language such as Python, JavaScript, C#, SQL, or PowerShell. The notebook uses a shared variable space so data passes between cells written in different languages.

GitHub Copilot is an AI code completion tool that suggests code based on the context of the file you are editing. In a standard code file, Copilot detects the language from the file extension. In a Polyglot Notebook, Copilot reads the language metadata attached to each cell. When you set a cell to Python, Copilot generates Python suggestions. When you switch the cell to SQL, Copilot switches to SQL completions automatically.

To use Copilot effectively in Polyglot Notebooks, you need both the Polyglot Notebooks extension and the GitHub Copilot extension installed in VS Code. You also need an active GitHub Copilot subscription, which can be the free tier with limited completions or a paid plan. Copilot does not require any special configuration for Polyglot Notebooks beyond the standard setup.

How Copilot Determines the Language in a Polyglot Cell

Copilot looks at the language specifier in the cell metadata. When you create a new cell in a Polyglot Notebook, a dropdown at the top of the cell shows the current language. Copilot reads this value and uses it to select the appropriate language model. If you do not set the language correctly, Copilot may produce suggestions for the wrong language. For example, if the cell is set to JavaScript but you write Python code, Copilot will suggest JavaScript completions.

Steps to Set Up GitHub Copilot in VS Code for Polyglot Notebooks

Follow these steps to enable GitHub Copilot in Polyglot Notebooks. The process assumes you already have VS Code installed.

  1. Install the Polyglot Notebooks extension
    Open VS Code and go to the Extensions view by pressing Ctrl+Shift+X. Search for “Polyglot Notebooks” and install the extension published by Microsoft. This extension adds support for .ipynb files with multiple language kernels.
  2. Install the GitHub Copilot extension
    In the Extensions view, search for “GitHub Copilot” and install the extension. After installation, you will see a Copilot icon in the status bar at the bottom of VS Code.
  3. Sign in to GitHub Copilot
    Click the Copilot icon in the status bar and select “Sign in to GitHub Copilot.” A browser window opens asking you to authorize VS Code. Complete the sign-in process. Your GitHub account must have an active Copilot subscription.
  4. Create a new Polyglot Notebook
    Press Ctrl+Shift+P to open the Command Palette. Type “Polyglot Notebook: Create New Notebook” and select it. A new notebook opens with one empty cell. Alternatively, create a new file with the .ipynb extension and VS Code opens it as a notebook.
  5. Set the language for the first cell
    Click the language dropdown at the top-right of the cell. Select the language you want to use, such as Python. You can also type a language comment at the top of the cell, for example #!python, and Copilot will detect it.
  6. Start typing code and accept Copilot suggestions
    In the cell, start typing code in the selected language. Copilot shows a ghost text suggestion. Press Tab to accept the suggestion. Press Esc to dismiss it. Continue typing to get new suggestions.
  7. Add more cells with different languages
    Click the + Code button at the top of the notebook to add a new cell. Set its language to a different value, for example SQL. Type SQL code in the new cell. Copilot automatically switches to SQL completions.
  8. Run cells and pass data between languages
    Click the Run button on each cell to execute the code. Variables defined in one cell are accessible in later cells if they share the same kernel. For example, a Python variable can be read by a C# cell in the same notebook.

ADVERTISEMENT

If Copilot Stops Suggesting Code in Polyglot Notebooks

Copilot shows no suggestions in a new cell

This usually happens when the cell language is not set. Check the language dropdown at the top of the cell. If it shows “(unspecified)”, click it and select a language. Copilot will not provide suggestions for an unspecified language. Once you set the language, start typing and Copilot should appear.

Copilot suggests code for the wrong language

The cell metadata might be incorrect. Verify the language dropdown shows the language you intend to write. If you see JavaScript but want Python, change the dropdown. You can also delete the cell and recreate it with the correct language. Copilot bases its suggestions on the metadata, not on the code content alone.

Copilot is enabled but still not working

Check the Copilot status in the VS Code status bar. The icon should show a spinning circle or a checkmark. If it shows a crossed-out circle, Copilot is disabled. Click the icon and select “Enable Completions.” Also verify that you are signed in to the correct GitHub account that has an active Copilot subscription. If you use a work or school GitHub account, the subscription must be assigned to your account by your organization.

Polyglot Notebooks vs Standard Notebooks: Key Differences for Copilot Users

Item Polyglot Notebooks Standard Jupyter Notebooks
Supported languages Python, JavaScript, C#, SQL, PowerShell, F#, HTML, Mermaid and more Primarily Python, with optional kernels for R, Julia, and others
Language detection by Copilot Uses cell metadata dropdown or language comment Uses the kernel selected for the notebook, usually one language per notebook
Variable sharing between languages Supported via .NET Interactive kernel, variables pass between cells of different languages Not supported; each kernel runs in its own process
Copilot suggestion accuracy High when language metadata is set correctly High, but limited to the single notebook language

Copilot in Polyglot Notebooks is most useful when you need to combine data processing in Python with database queries in SQL and visualization in JavaScript. Standard notebooks work better for single-language projects where you do not need cross-language variable sharing.

Now you can create Polyglot Notebooks in VS Code and use GitHub Copilot to generate code in multiple languages within the same file. To get the best results, always set the cell language before you start typing. You can also use the Copilot Chat panel to ask questions about your notebook code. For advanced scenarios, try passing a Python DataFrame to a C# cell for further processing and let Copilot suggest the conversion code.

ADVERTISEMENT