Skip to content

fix: support file paths with spaces in block headers#1504

Merged
deathbeam merged 1 commit intoCopilotC-Nvim:mainfrom
junqizhang:fix/block-header-path-with-spaces
Feb 2, 2026
Merged

fix: support file paths with spaces in block headers#1504
deathbeam merged 1 commit intoCopilotC-Nvim:mainfrom
junqizhang:fix/block-header-path-with-spaces

Conversation

@junqizhang
Copy link
Contributor

Problem

The block header pattern matching in match_block_header() uses %S+ (non-whitespace characters) to capture file paths. This fails when file paths contain spaces, causing:

  • Code blocks to not be parsed (blocks array remains empty)
  • Diff acceptance features (<C-y>, gd, gy, etc.) to be non-functional
  • Treesitter correctly identifies block nodes, but they're not added to the message

Example failing path:

python path=/Users/name/my projects/test.py start_line=1 end_line=10

Solution

  • Added a new pattern with lazy match (.-) to support paths with spaces
  • Kept the original %S+ pattern as fallback for compatibility
  • The lazy match stops at the next expected token (start_line=)

Testing

Tested with file paths containing spaces and verified:

  • ✅ Blocks are now correctly parsed and added to message.section.blocks
  • ✅ All diff-related mappings work (accept_diff, show_diff, jump_to_diff, etc.)
  • ✅ Backward compatibility maintained for paths without spaces
  • ✅ Treesitter captures are properly converted to block objects

Changes

  • Modified lua/CopilotChat/ui/chat.lua - Added pattern to support spaces in paths

The block header pattern used %S+ (non-whitespace characters) to match
file paths, which failed when paths contained spaces. This prevented
code blocks from being parsed and made diff acceptance (<C-y>)
non-functional for files in directories with spaces.

Changes:
- Add new pattern with lazy match (.-) to support paths with spaces
- Keep original pattern as fallback for compatibility
- Pattern now correctly parses headers like:
  python path=/path/with spaces/file.py start_line=1 end_line=10

Fixes the issue where blocks count remained 0 even when Treesitter
correctly identified block_header and block_content nodes.

Tested with paths containing spaces and verified that:
- Blocks are now correctly parsed and added to message.section.blocks
- Diff acceptance mappings (accept_diff, show_diff, etc.) now work
- Backward compatibility maintained for paths without spaces
@deathbeam deathbeam added the bug Something isn't working label Feb 2, 2026
@deathbeam deathbeam merged commit 5c5e6c2 into CopilotC-Nvim:main Feb 2, 2026
1 check passed
@deathbeam
Copy link
Collaborator

@all-contributors add @junqizhang for code

@allcontributors
Copy link
Contributor

@deathbeam

I've put up a pull request to add @junqizhang! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments