-
Notifications
You must be signed in to change notification settings - Fork 15
Fix missing syntax highlighting in proposed diff view #32
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
Conversation
* Adds helper and propagates filetype to proposed buffers to restore syntax highlighting * Cleans up duplicate code and stray newline * Makes CI-friendly by defining global to avoid nested nix shells * Updates unit tests to cover filetype propagation Co-authored-by: ThomasK33 <[email protected]>
0ba7d77
to
ddad527
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that proposed diff buffers inherit the original file’s syntax highlighting by detecting and propagating the filetype, and also refines CI shell invocation.
- Introduces a
_detect_filetype
helper for path‐ and buffer‐based filetype resolution. - Applies detected filetypes in both native diff and split diff views.
- Adds a unit test for native-diff filetype propagation and updates the Makefile to prevent nested Nix shells in CI.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/unit/diff_spec.lua | Added a test to verify filetype propagation in _open_native_diff . |
lua/claudecode/diff.lua | Implemented _detect_filetype and applied filetype in diff views. |
Makefile | Defined NIX_PREFIX to skip nix develop when already in a shell. |
Comments suppressed due to low confidence (2)
lua/claudecode/diff.lua:721
- Add a unit test for
_create_diff_view_from_window
to verify that the filetype is correctly propagated in split diff views, matching the native-diff test pattern.
-- Ensure new buffer inherits filetype from original for syntax highlighting (#20)
lua/claudecode/diff.lua:722
- Ensure that
original_buffer
is defined in this scope before passing it to_detect_filetype
. Iforiginal_buffer
is undefined, this will cause a runtime error.
local original_ft = _detect_filetype(old_file_path, original_buffer)
local simple_map = { | ||
lua = "lua", | ||
ts = "typescript", | ||
js = "javascript", | ||
jsx = "javascriptreact", | ||
tsx = "typescriptreact", | ||
py = "python", | ||
go = "go", | ||
rs = "rust", | ||
c = "c", | ||
h = "c", | ||
cpp = "cpp", | ||
hpp = "cpp", | ||
md = "markdown", | ||
sh = "sh", | ||
zsh = "zsh", | ||
bash = "bash", | ||
json = "json", | ||
yaml = "yaml", | ||
yml = "yaml", | ||
toml = "toml", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider extracting the simple_map
table to a module-level constant so it isn’t recreated on every call, improving performance and clarity.
local simple_map = { | |
lua = "lua", | |
ts = "typescript", | |
js = "javascript", | |
jsx = "javascriptreact", | |
tsx = "typescriptreact", | |
py = "python", | |
go = "go", | |
rs = "rust", | |
c = "c", | |
h = "c", | |
cpp = "cpp", | |
hpp = "cpp", | |
md = "markdown", | |
sh = "sh", | |
zsh = "zsh", | |
bash = "bash", | |
json = "json", | |
yaml = "yaml", | |
yml = "yaml", | |
toml = "toml", | |
} |
Copilot uses AI. Check for mistakes.
diff.setup({}) | ||
|
||
-- Spy on nvim_set_option_value | ||
spy.on(_G.vim.api, "nvim_set_option_value") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] After spying on nvim_set_option_value
, consider restoring or removing the spy in an after_each
block to avoid side effects on other tests.
Copilot uses AI. Check for mistakes.
What & Why
When Claude Code shows a Proposed changes diff, the scratch buffer on the right didn’t inherit the original file’s
filetype
, so Neovim rendered it without syntax highlighting (issue #20).Key changes in this PR
_detect_filetype
helpervim.filetype.match
(≥0.10) or falls back to the extension map.Filetype propagation
vim.api.nvim_set_option_value
.Tests
spy.on
) so regressions are caught.Makefile improvements
NIX_PREFIX
that expands tonix develop .#ci -c
only when outside a Nix shell, preventing nested shells in CI.Misc
diff.lua
docblock.Verification
Fixes #20.
Co-authored-by: ThomasK33 [email protected]