Skip to content

fix(copilot): Prioritize XDG_CONFIG_HOME for OAuth token references on Windows #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

hat0uma
Copy link
Contributor

@hat0uma hat0uma commented Jan 5, 2025

Overview

This PR fixes an issue where, on Windows environments with XDG_CONFIG_HOME set, Copilot's OAuth token cannot be found, resulting in the following error:

...m-data/lazy/avante.nvim/lua/avante/providers/copilot.lua:293: You must setup copilot with either copilot.lua or copilot.vim

The detailed stack trace is as follows:

- avante.nvim\lua\avante\providers\copilot.lua:120 _in_ **get_oauth_token**
- avante.nvim\lua\avante\providers\copilot.lua:293 _in_ **setup**
- avante.nvim\lua\avante\providers\init.lua:164 _in_ **setup**
- avante.nvim\lua\avante\providers\init.lua:317 _in_ **setup**
- avante.nvim\lua\avante\init.lua:367 _in_ **setup**

Cause

On Windows, the current implementation attempts to load the authentication file (hosts.json , apps.json) from:

~/AppData/Local/github-copilot/

However, if XDG_CONFIG_HOME is set, the file is actually generated at:

$XDG_CONFIG_HOME/github-copilot/

As a result, the OAuth token cannot be retrieved and the above error is triggered.

Changes

  • The code now checks XDG_CONFIG_HOME first on all platforms.
  • If the file is not found there, it falls back to the existing logic (on Windows, ~/AppData/Local).

This behavior aligns with how copilot.lua currently works:

https://github.com/zbirenbaum/copilot.lua/blob/886ee73b6d464b2b3e3e6a7ff55ce87feac423a9/lua/copilot/auth.lua#L171

https://github.com/zbirenbaum/copilot.lua/blob/886ee73b6d464b2b3e3e6a7ff55ce87feac423a9/lua/copilot/auth.lua#L134-L151

Repro

  1. On Windows, define the XDG_CONFIG_HOME environment variable and point it to any directory.
  2. Sign in to Copilot so that $XDG_CONFIG_HOME/github-copilot/apps.json is generated.
  3. Apply the following configuration:
    require("avante").setup({
      provider = "copilot",
    })

…indows

This commit updates the logic for determining the `config_dir` so that
`xdg_config` is prioritized on Windows as well. It follows the behavior
outlined in the code here:
https://github.com/zbirenbaum/copilot.lua/blob/master/lua/copilot/auth.lua#L134-L151.
@yetone yetone merged commit 0536c6e into yetone:main Jan 5, 2025
2 checks passed
brewinski pushed a commit to brewinski/avante.nvim that referenced this pull request Jan 10, 2025
brewinski pushed a commit to brewinski/avante.nvim that referenced this pull request Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants