Skip to content

fix(context): normalize file paths for Windows compatibility#263

Open
john-mutuma wants to merge 5 commits intofolke:mainfrom
john-mutuma:fix/windows-file-context-path
Open

fix(context): normalize file paths for Windows compatibility#263
john-mutuma wants to merge 5 commits intofolke:mainfrom
john-mutuma:fix/windows-file-context-path

Conversation

@john-mutuma
Copy link

Summary

On Windows, {file} and other context variables that use Loc.get() send garbled paths. For example, {file} for lua/sidekick/text.lua sends @lua instead of @lua/sidekick/text.lua — backslashes in the path are interpreted as escape characters by CLI tools.

Root cause

In lua/sidekick/cli/context/location.lua, vim.api.nvim_buf_get_name() returns backslash paths on Windows (e.g., C:\Users\...\lua\sidekick\text.lua), but the value is never normalized. The cwd fallback (vim.fn.getcwd(0)) has the same issue. This causes vim.fs.relpath to produce backslash-separated relative paths that break when sent to CLI tools.

Fix

Normalize both name and the cwd fallback with vim.fs.normalize(), consistent with how paths are handled elsewhere in the codebase (e.g., context/init.lua:209 normalizes cwd).

- local name = ctx.name or vim.api.nvim_buf_get_name(ctx.buf)
+ local name = ctx.name or vim.fs.normalize(vim.api.nvim_buf_get_name(ctx.buf))
- local cwd = ctx.cwd or vim.fn.getcwd(0)
+ local cwd = ctx.cwd or vim.fs.normalize(vim.fn.getcwd(0))

Testing

Tested on Windows 11 with psmux. {file} now correctly sends @lua/sidekick/text.lua instead of @lua.

John Mutuma (from Dev Box) and others added 4 commits March 3, 2026 18:06
@github-actions github-actions bot added the size/m Medium PR (<50 lines changed) label Mar 3, 2026
@john-mutuma john-mutuma force-pushed the fix/windows-file-context-path branch from 7516196 to c82264a Compare March 3, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m Medium PR (<50 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant