copilot.lua

repository·master·Indexed 26 days ago

https://github.com/zbirenbaum/copilot.lua

A pure Lua replacement for copilot.vim that provides GitHub Copilot integration for Neovim. It features an API for interacting with GitHub Copilot, a preview panel for suggestions, and configurable inline ghost text. Version 1.0.0 requires Neovim 0.11.0+, NodeJS v22+, and Curl.

Tokens
5.2K
Snippets
18
Records
33
Agent score
88%

What's inside copilot.lua

  1. Authenticate with GitHub Copilot

    master

    The recommended way to authenticate is via permanent sign-in. Once the plugin is running, execute the :Copilot auth command to start the process.

    To manage your account:

    • Sign out: :Copilot auth signout
    • Sign in with a different account: :Copilot auth signin
    • Check status: :Copilot auth info

    Credentials are stored in ~/.config/github-copilot/auth.db (Linux/macOS) or ~/AppData/Local/github-copilot/auth.db (Windows).

    :Copilot auth
  2. Configure GitHub Copilot macOS Policies via Configuration Profile

    master

    Administrators can manage GitHub Copilot behavior on macOS using the IDEGitHubCopilot.mobileconfig Apple Configuration Profile. This profile allows for system-wide control over extension settings, specifically regarding MCP (Model Context Protocol) servers.

    Available Policies

    Policy NameDescriptionTypeDefault
    mcp.contributionPoint.enabledControls whether extension-contributed MCP servers are enabledBooleantrue
    1. Locate the IDEGitHubCopilot.mobileconfig file.
    2. Double-click the file to open System Settings (or System Preferences).
    3. Click Install and enter your administrator password.
    4. To verify, navigate to System SettingsPrivacy & SecurityProfiles and look for "GitHub Copilot Policy".

    Modifying Settings

    To change the mcp.contributionPoint.enabled setting:

    1. Go to System SettingsPrivacy & SecurityProfiles.
    2. Select the "GitHub Copilot Policy" profile.
    3. Click Edit or Configure.
    4. Toggle mcp.contributionPoint.enabled to true (enabled) or false (disabled).
    5. Click Save or Apply.
  3. Deploy GitHub Copilot Policies via Microsoft Intune

    master

    To deploy GitHub Copilot settings using Microsoft Intune, create a Custom Configuration Profile:

    1. In the Microsoft Endpoint Manager admin center, go to DevicesConfiguration profiles.
    2. Create a new profile:
      • Platform: Windows 10 and later
      • Profile type: Custom
    3. Add the following OMA-URI setting:
      • Name: Enable Extension-Contributed MCP Servers
      • OMA-URI: ./Device/Vendor/MSFT/Policy/Config/ADMX_IDEGitHubCopilot/McpContributionPointEnabled
      • Data type: Integer
      • Value: 1 (enabled) or 0 (disabled)
    4. Assign the profile to your target device groups.
  4. Manage Workspace Folders

    master

    Workspace folders improve suggestion quality. By default, the root_dir is used. You can add additional folders via configuration or runtime commands.

    Runtime command: :Copilot workspace add [folderpath]

    workspace_folders = {
      "/home/user/gits",
      "/home/user/projects",
    }
  5. Configure GitHub Copilot via Group Policy Editor

    master

    Once the templates are installed, you can manage settings through the Windows Group Policy Editor:

    1. Open the Editor:
      • Run gpedit.msc (Local Group Policy Editor).
      • Or use gpmc.msc (Group Policy Management Console) for domain environments.
    2. Navigate to Policies:
      • Computer Configuration → Administrative Templates → GitHub Copilot
      • User Configuration → Administrative Templates → GitHub Copilot
  6. Deploy GitHub Copilot Policies via MDM

    master

    For enterprise environments, the IDEGitHubCopilot.mobileconfig file can be deployed to target devices using Mobile Device Management (MDM) solutions. Supported solutions include:

    • Apple Business Manager
    • Jamf Pro
    • Microsoft Intune
    • VMware Workspace ONE

    Simply upload the IDEGitHubCopilot.mobileconfig file to your MDM solution and assign it to the desired device groups.

  7. Install copilot.lua

    master

    Install the plugin using your preferred Neovim plugin manager. If you want to use Next Edit Suggestion (NES) functionality, you should also include copilotlsp-nvim/copilot-lsp as a requirement.

    use { "zbirenbaum/copilot.lua"
      requires = {
        "copilotlsp-nvim/copilot-lsp", -- (optional) for NES functionality
      },
    }
  8. Initialize copilot.lua with setup()

    master

    To start Copilot, you must call require("copilot").setup(options). If no options are provided, the plugin uses its default configuration. It is highly recommended to lazy load the plugin because the Copilot server takes time to start up.

    use {
      "zbirenbaum/copilot.lua",
      requires = {
        "copilotlsp-nvim/copilot-lsp", -- (optional) for NES functionality
      },
      cmd = "Copilot",
      event = "InsertEnter",
      config = function()
        require("copilot").setup({})
      end,
    }
  9. Install GitHub Copilot Group Policy Templates for Windows

    master

    To manage GitHub Copilot settings via Windows Group Policy, you must install the Administrative Template (ADMX/ADML) files provided with the GitHub Copilot Language Server.

    Template Location

    Templates are located in the policy-templates/win32/ directory of your Language Server installation. Common paths include:

    • NPM Global: %APPDATA%\npm\node_modules\@github\copilot-language-server\dist\policy-templates\win32
    • Local NPM: .\node_modules\@github\copilot-language-server\dist\policy-templates\win32

    Installation Methods

    1. Open PowerShell as Administrator.
    2. Navigate to the template directory:
      cd "[Language Server Installation Directory]\policy-templates\win32"
    3. Run the installation script:
      .\Install-PolicyTemplates.ps1

    Option 2: Manual Installation

    1. Copy IDEGitHubCopilot.admx to C:\Windows\PolicyDefinitions\.
    2. Copy en-US\IDEGitHubCopilot.adml to C:\Windows\PolicyDefinitions\en-US\.

    Option 3: Microsoft Intune

    Create a Custom Configuration Profile using OMA-URI settings (see Microsoft Intune Deployment section).

    # Option 1: PowerShell Script (Recommended)
    cd "[Language Server Installation Directory]\policy-templates\win32"
    .\Install-PolicyTemplates.ps1
  10. Enable Next Edit Suggestion (NES)

    master

    NES is an experimental feature that provides suggestions based on your likely next edit. It requires copilot-lsp as a dependency.

    use {
      "zbirenbaum/copilot.lua",
      requires = {
        "copilotlsp-nvim/copilot-lsp",
        init = function()
          vim.g.copilot_nes_debounce = 500
        end,
      },
      cmd = "Copilot",
      event = "InsertEnter",
      config = function()
        require("copilot").setup({
          nes = {
            enabled = true,
            keymap = {
              accept_and_goto = "<leader>p",
              accept = false,
              dismiss = "<Esc>",
            },
          },
        })
      end,
    }
  11. Configure filetypes for Copilot

    master

    You can specify which filetypes Copilot should attach to. You can use booleans, or a function that returns a boolean for fine-grained control (e.g., excluding specific filenames).

    require("copilot").setup {
      filetypes = {
        markdown = true, -- overrides default
        terraform = false, -- disallow specific filetype
        sh = function ()
          if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
            -- disable for .env files
            return false
          end
          return true
        end,
      },
    }