Skip to content

Commit afdb0d1

Browse files
committed
feat: enhance message rendering with rich markdown and styled code blocks
- Add styled code block headers with language badge (LANGUAGE: LUA) - Add copy indicator and fold support for code blocks - Add markdown highlighting (headers, bold, italic, lists, blockquotes) - Add diff highlighting for +/- lines in diff blocks - Add sender indicators (You/Assistant) before messages - Add message dividers between answers - Add inline code, links, task lists, strikethrough styling - Remove context display from settings panel (now using @refs) - Restore add_context/add_project_context for backwards compatibility - Update README with new features and keybindings
1 parent c10fccf commit afdb0d1

5 files changed

Lines changed: 359 additions & 62 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ test addition, code optimization, summarization, bug fixing, code explanation,
3232
Roxygen editing, and code readability analysis. Additionally, you can define
3333
your own custom actions using a JSON file.
3434

35+
- **Rich Message Rendering**: Enhanced chat display with styled code blocks
36+
(language headers, copy indicators, foldable), markdown formatting (headers,
37+
bold, italic, lists, blockquotes, links), diff highlighting, and sender indicators.
38+
39+
- **Inline Context References**: Use `@` to add context from LSP definitions or
40+
project files directly in your prompts. References are displayed inline and
41+
expanded when sending to the API.
42+
3543
For a comprehensive understanding of the extension's functionality, you can watch
3644
a plugin showcase [video](https://www.youtube.com/watch?v=7k0KZsheLP4)
3745

@@ -349,6 +357,9 @@ keybindings are available:
349357
- `<C-i>` [Edit Window] use response as input.
350358
- `<C-d>` [Edit Window] view the diff between left and right panes and use diff-mode
351359
commands
360+
- `y` [Chat] Copy code block at cursor.
361+
- `za` [Chat] Toggle fold for code block.
362+
- `@` [Chat] Trigger context autocomplete (LSP definitions, project context).
352363

353364
The settings window (`<C-o>`) displays current configuration (model, temperature,
354365
max_tokens, session name). To change settings, modify your `setup()` configuration.

lua/chatgpt.lua

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ M.setup = function(options)
2424

2525
vim.api.nvim_set_hl(0, "ChatGPTContextRef", { fg = "#89b4fa", bg = "#1e1e2e", bold = true, default = true })
2626

27+
vim.api.nvim_set_hl(0, "ChatGPTInlineCode", { fg = "#f38ba8", bg = "#1e1e2e", default = true })
28+
vim.api.nvim_set_hl(0, "ChatGPTCodeBlock", { bg = "#181825", default = true })
29+
vim.api.nvim_set_hl(0, "ChatGPTCodeBlockHeader", { fg = "#6c7086", bg = "#181825", italic = true, default = true })
30+
31+
vim.api.nvim_set_hl(0, "ChatGPTLink", { fg = "#89b4fa", underline = true, default = true })
32+
vim.api.nvim_set_hl(0, "ChatGPTBold", { bold = true, default = true })
33+
vim.api.nvim_set_hl(0, "ChatGPTItalic", { italic = true, default = true })
34+
vim.api.nvim_set_hl(0, "ChatGPTHeader", { fg = "#cba6f7", bold = true, default = true })
35+
vim.api.nvim_set_hl(0, "ChatGPTDivider", { fg = "#313244", default = true })
36+
vim.api.nvim_set_hl(0, "ChatGPTListMarker", { fg = "#f9e2af", bold = true, default = true })
37+
vim.api.nvim_set_hl(0, "ChatGPTBlockquote", { fg = "#a6adc8", italic = true, default = true })
38+
vim.api.nvim_set_hl(0, "ChatGPTHRule", { fg = "#45475a", default = true })
39+
vim.api.nvim_set_hl(0, "ChatGPTTaskDone", { fg = "#a6e3a1", default = true })
40+
vim.api.nvim_set_hl(0, "ChatGPTTaskPending", { fg = "#f9e2af", default = true })
41+
vim.api.nvim_set_hl(0, "ChatGPTStrikethrough", { strikethrough = true, fg = "#6c7086", default = true })
42+
vim.api.nvim_set_hl(0, "ChatGPTLinkText", { fg = "#89dceb", default = true })
43+
vim.api.nvim_set_hl(0, "ChatGPTLinkUrl", { fg = "#6c7086", underline = true, default = true })
44+
vim.api.nvim_set_hl(0, "ChatGPTCodeLang", { fg = "#ffffff", bg = "#45475a", bold = true, default = true })
45+
vim.api.nvim_set_hl(0, "ChatGPTDiffAdd", { fg = "#a6e3a1", bg = "#1e3a2f", default = true })
46+
vim.api.nvim_set_hl(0, "ChatGPTDiffDel", { fg = "#f38ba8", bg = "#3a1e2f", default = true })
47+
vim.api.nvim_set_hl(0, "ChatGPTSenderUser", { fg = "#89b4fa", bold = true, default = true })
48+
vim.api.nvim_set_hl(0, "ChatGPTSenderAssistant", { fg = "#a6e3a1", bold = true, default = true })
49+
2750
vim.cmd("highlight default link ChatGPTSelectedMessage ColorColumn")
2851

2952
config.setup(options)
@@ -57,4 +80,28 @@ end
5780

5881
M.complete_code = module.complete_code
5982

83+
-- Context APIs (deprecated but kept for backwards compatibility)
84+
M.add_context = function()
85+
local lsp_context = require("chatgpt.context.lsp")
86+
lsp_context.get_context(function(item)
87+
if item then
88+
local Context = require("chatgpt.context")
89+
local ref = Context.make_ref(item)
90+
Context.add(ref, item)
91+
vim.notify(string.format("Context added: %s", ref), vim.log.levels.INFO)
92+
end
93+
end)
94+
end
95+
96+
M.add_project_context = function()
97+
local project_context = require("chatgpt.context.project")
98+
local item = project_context.get_context()
99+
if item then
100+
local Context = require("chatgpt.context")
101+
local ref = Context.make_ref(item)
102+
Context.add(ref, item)
103+
vim.notify(string.format("Context added: %s", ref), vim.log.levels.INFO)
104+
end
105+
end
106+
60107
return M

lua/chatgpt/config.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ function M.defaults()
8181
toggle_message_role = "<C-r>",
8282
toggle_system_role_open = "<C-s>",
8383
stop_generating = "<C-x>",
84-
delete_context_item = "d",
84+
yank_code = "y",
85+
toggle_fold = "za",
8586
},
8687
},
8788
popup_layout = {
@@ -107,6 +108,8 @@ function M.defaults()
107108
wrap = true,
108109
linebreak = true,
109110
foldcolumn = "1",
111+
foldmethod = "manual",
112+
foldenable = true,
110113
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
111114
},
112115
buf_options = {

0 commit comments

Comments
 (0)