Skip to content

Commit 300f22b

Browse files
authored
refactor(ui): diff resets winbar and doc updates (#2432)
Co-authored-by: Oli Morris <olimorris@users.noreply.github.com>
1 parent d8fbcfe commit 300f22b

File tree

7 files changed

+79
-104
lines changed

7 files changed

+79
-104
lines changed

doc/.vitepress/config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { joinURL, withoutTrailingSlash } from "ufo";
22
import { defineConfig } from "vitepress";
3+
import { tabsMarkdownPlugin } from "vitepress-plugin-tabs";
34
import { execSync } from "node:child_process";
45
import { withMermaid } from "vitepress-plugin-mermaid";
56

@@ -74,6 +75,11 @@ const headers = inProd ? [...baseHeaders, umamiScript] : baseHeaders;
7475
// https://vitepress.dev/reference/site-config
7576
export default withMermaid(
7677
defineConfig({
78+
markdown: {
79+
config(md) {
80+
md.use(tabsMarkdownPlugin);
81+
},
82+
},
7783
mermaid: {
7884
securityLevel: "loose", // Allows more flexibility
7985
theme: "base", // Use base theme to allow CSS variables to take effect

doc/.vitepress/theme/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import DefaultTheme from "vitepress/theme";
22
import "./vaporwave.css";
3+
import { enhanceAppWithTabs } from "vitepress-plugin-tabs/client";
34

4-
export default DefaultTheme;
5+
export default {
6+
extends: DefaultTheme,
7+
enhanceApp({ app }) {
8+
enhanceAppWithTabs(app);
9+
},
10+
};

doc/codecompanion.txt

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*codecompanion.txt* For NVIM v0.11 Last change: 2025 November 23
1+
*codecompanion.txt* For NVIM v0.11 Last change: 2025 November 24
22

33
==============================================================================
44
Table of Contents *codecompanion-table-of-contents*
@@ -1866,69 +1866,9 @@ utilize the `insert_edit_into_file` tool, then the plugin can update files and
18661866
buffers and a diff will be created so you can see the changes made by the LLM.
18671867
The `inline` is the default diff.
18681868

1869-
There are a number of diff settings available to you:
1869+
Depending on which provider you choose, there are different configuration
1870+
options available to you:
18701871

1871-
>lua
1872-
require("codecompanion").setup({
1873-
display = {
1874-
diff = {
1875-
enabled = true,
1876-
provider = providers.diff, -- mini_diff|split|inline
1877-
1878-
provider_opts = {
1879-
-- Options for inline diff provider
1880-
inline = {
1881-
layout = "float", -- float|buffer - Where to display the diff
1882-
1883-
diff_signs = {
1884-
signs = {
1885-
text = "▌", -- Sign text for normal changes
1886-
reject = "✗", -- Sign text for rejected changes in super_diff
1887-
highlight_groups = {
1888-
addition = "DiagnosticOk",
1889-
deletion = "DiagnosticError",
1890-
modification = "DiagnosticWarn",
1891-
},
1892-
},
1893-
-- Super Diff options
1894-
icons = {
1895-
accepted = " ",
1896-
rejected = " ",
1897-
},
1898-
colors = {
1899-
accepted = "DiagnosticOk",
1900-
rejected = "DiagnosticError",
1901-
},
1902-
},
1903-
1904-
opts = {
1905-
context_lines = 3, -- Number of context lines in hunks
1906-
dim = 25, -- Background dim level for floating diff (0-100, [100 full transparent], only applies when layout = "float")
1907-
full_width_removed = true, -- Make removed lines span full width
1908-
show_keymap_hints = true, -- Show "gda: accept | gdr: reject" hints above diff
1909-
show_removed = true, -- Show removed lines as virtual text
1910-
},
1911-
},
1912-
1913-
-- Options for the split provider
1914-
split = {
1915-
close_chat_at = 240, -- Close an open chat buffer if the total columns of your display are less than...
1916-
layout = "vertical", -- vertical|horizontal split
1917-
opts = {
1918-
"internal",
1919-
"filler",
1920-
"closeoff",
1921-
"algorithm:histogram", -- https://adamj.eu/tech/2024/01/18/git-improve-diff-histogram/
1922-
"indent-heuristic", -- https://blog.k-nut.eu/better-git-diffs
1923-
"followwrap",
1924-
"linematch:120",
1925-
},
1926-
},
1927-
},
1928-
},
1929-
},
1930-
})
1931-
<
19321872

19331873
You can also customize the window that the diff appears in (taking precedence
19341874
over `child_window`):

doc/configuration/chat-buffer.md

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -429,41 +429,32 @@ require("codecompanion").setup({
429429

430430
CodeCompanion has built-in inline and split diffs available to you. If you utilize the `insert_edit_into_file` tool, then the plugin can update files and buffers and a diff will be created so you can see the changes made by the LLM. The `inline` is the default diff.
431431

432-
There are a number of diff settings available to you:
432+
Depending on which provider you choose, there are different configuration options available to you:
433+
434+
:::tabs
435+
436+
== Select Provider
433437

434438
```lua
435439
require("codecompanion").setup({
436440
display = {
437441
diff = {
438442
enabled = true,
439-
provider = providers.diff, -- mini_diff|split|inline
443+
provider = providers.diff, -- inline|split|mini.diff
444+
},
445+
},
446+
})
447+
```
440448

449+
== Inline Provider
450+
451+
```lua
452+
require("codecompanion").setup({
453+
display = {
454+
diff = {
441455
provider_opts = {
442-
-- Options for inline diff provider
443456
inline = {
444457
layout = "float", -- float|buffer - Where to display the diff
445-
446-
diff_signs = {
447-
signs = {
448-
text = "", -- Sign text for normal changes
449-
reject = "", -- Sign text for rejected changes in super_diff
450-
highlight_groups = {
451-
addition = "DiagnosticOk",
452-
deletion = "DiagnosticError",
453-
modification = "DiagnosticWarn",
454-
},
455-
},
456-
-- Super Diff options
457-
icons = {
458-
accepted = "",
459-
rejected = "",
460-
},
461-
colors = {
462-
accepted = "DiagnosticOk",
463-
rejected = "DiagnosticError",
464-
},
465-
},
466-
467458
opts = {
468459
context_lines = 3, -- Number of context lines in hunks
469460
dim = 25, -- Background dim level for floating diff (0-100, [100 full transparent], only applies when layout = "float")
@@ -472,8 +463,19 @@ require("codecompanion").setup({
472463
show_removed = true, -- Show removed lines as virtual text
473464
},
474465
},
466+
},
467+
},
468+
},
469+
})
470+
```
471+
472+
== Split Provider
475473

476-
-- Options for the split provider
474+
```lua
475+
require("codecompanion").setup({
476+
display = {
477+
diff = {
478+
provider_opts = {
477479
split = {
478480
close_chat_at = 240, -- Close an open chat buffer if the total columns of your display are less than...
479481
layout = "vertical", -- vertical|horizontal split
@@ -493,6 +495,9 @@ require("codecompanion").setup({
493495
})
494496
```
495497

498+
499+
:::
500+
496501
You can also customize the window that the diff appears in (taking precedence over `child_window`):
497502

498503
```lua

doc/package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"mermaid": "^11.10.0",
55
"ufo": "^1.6.1",
66
"vitepress": "^1.5.0",
7-
"vitepress-plugin-mermaid": "^2.0.17"
7+
"vitepress-plugin-mermaid": "^2.0.17",
8+
"vitepress-plugin-tabs": "^0.7.3"
89
},
910
"scripts": {
1011
"dev": "vitepress dev",

lua/codecompanion/providers/diff/inline.lua

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ local api = vim.api
77
---@class CodeCompanion.Diff.Inline
88
---@field bufnr number
99
---@field contents string[]
10-
---@field id number
11-
---@field ns_id number
1210
---@field extmark_ids number[]
1311
---@field has_changes boolean
14-
---@field winnr number|nil
12+
---@field id number
1513
---@field is_floating boolean
14+
---@field ns_id number
1615
---@field show_hints boolean
16+
---@field winnr number|nil
17+
---@field winbar {content: string, winhighlight: string}|nil Original winbar state
1718

1819
---@class CodeCompanion.Diff.Inline
1920
local InlineDiff = {}
@@ -22,9 +23,9 @@ local InlineDiff = {}
2223
---@field bufnr number Buffer number to apply diff to
2324
---@field contents string[] Original content lines
2425
---@field id number|string Unique identifier for this diff
25-
---@field winnr? number Window number (optional)
2626
---@field is_floating boolean|nil Whether this diff is in a floating window
2727
---@field show_hints? boolean Whether to show keymap hints (default: true)
28+
---@field winnr? number Window number (optional)
2829

2930
---Creates a new InlineDiff instance and applies diff highlights
3031
---@param args CodeCompanion.Diff.InlineArgs
@@ -33,15 +34,19 @@ function InlineDiff.new(args)
3334
local self = setmetatable({
3435
bufnr = args.bufnr,
3536
contents = args.contents,
37+
extmark_ids = {},
38+
has_changes = false,
3639
id = args.id,
37-
winnr = args.winnr,
3840
is_floating = args.is_floating or false,
39-
show_hints = args.show_hints == nil and true or args.show_hints,
4041
ns_id = api.nvim_create_namespace(
4142
"codecompanion_inline_diff_" .. (args.id ~= nil and args.id or math.random(1, 100000))
4243
),
43-
extmark_ids = {},
44-
has_changes = false,
44+
show_hints = args.show_hints == nil and true or args.show_hints,
45+
winnr = args.winnr,
46+
winbar = {
47+
content = vim.wo[args.winnr or 0].winbar or "",
48+
winhighlight = vim.wo[args.winnr or 0].winhighlight or "",
49+
},
4550
}, { __index = InlineDiff })
4651
---@cast self CodeCompanion.Diff.Inline
4752

@@ -231,11 +236,11 @@ end
231236

232237
---Clear winbar and winhighlight from the diff window
233238
---@return nil
234-
function InlineDiff:clear_winbar()
239+
function InlineDiff:restore_winbar()
235240
if self.winnr and api.nvim_win_is_valid(self.winnr) then
236241
pcall(function()
237-
vim.wo[self.winnr].winbar = ""
238-
vim.wo[self.winnr].winhighlight = ""
242+
vim.wo[self.winnr].winbar = self.winbar.content
243+
vim.wo[self.winnr].winhighlight = self.winbar.winhighlight
239244
end)
240245
end
241246
end
@@ -261,7 +266,7 @@ function InlineDiff:teardown()
261266
end)
262267
end)
263268
self:clear_highlights()
264-
self:clear_winbar()
269+
self:restore_winbar()
265270
self:close_floating_window()
266271
utils.fire("DiffDetached", { diff = "inline", bufnr = self.bufnr, id = self.id })
267272
end

0 commit comments

Comments
 (0)