fix(copilot): Prioritize XDG_CONFIG_HOME
for OAuth token references on Windows
#1037
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:The detailed stack trace is as follows:
Cause
On Windows, the current implementation attempts to load the authentication file (
hosts.json
,apps.json
) from:However, if
XDG_CONFIG_HOME
is set, the file is actually generated at:As a result, the OAuth token cannot be retrieved and the above error is triggered.
Changes
XDG_CONFIG_HOME
first on all platforms.~/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
XDG_CONFIG_HOME
environment variable and point it to any directory.$XDG_CONFIG_HOME/github-copilot/apps.json
is generated.