-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
feat(chat): Adding buffer watcher #610
Open
bassamsdata
wants to merge
18
commits into
olimorris:main
Choose a base branch
from
bassamsdata:buffer_watcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0f8507f
feat(chat): Adding buffer watcher
1cf8d60
refactor(watcher): refactor how to consolidate changes
cb907ee
refactor(watcher): more reliable chnages report.
f40d011
fix(watcher): fix cleaning the watcher correcly
ab02666
fix(watcher): fix unwatch
1d328f1
refactor(watcher): change the whole mechanism
ae6313f
tests: add watched to references test
5d092ba
fix(references): ensure bother options have defaults
539d312
tests: Adding watcher feature tests
ec3d7a8
fix(watcher): fix the duplicate printing of reference
ea76cdb
refactor(watcher): add more edge cases to be robust
f9e465f
tests: Added more edge cases tests
8d6944f
fix(watcher): handle closing watched buffer
35d967b
fix(watcher): handle unloaded buffers
926ee78
fix(watcher): don't send too much to the llm
c4eaf9d
chore(watcher): clean up the code
1255a1a
tests: update watcher tests
5166bb8
Merge branch 'main' into buffer_watcher
bassamsdata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,17 @@ local config = require("codecompanion.config") | |
local api = vim.api | ||
local user_role = config.strategies.chat.roles.user | ||
local pinned_icon = config.display.chat.icons.pinned_buffer | ||
local watched_icon = config.display.chat.icons.watched_buffer | ||
|
||
local allowed_pins = { | ||
"<buf>", | ||
"<file>", | ||
} | ||
|
||
local allowed_watches = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think we should rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"<buf>", | ||
} | ||
|
||
---Parse the chat buffer to find where to add the references | ||
---@param chat CodeCompanion.Chat | ||
---@return table|nil | ||
|
@@ -106,11 +111,16 @@ function References:add(ref) | |
|
||
if ref then | ||
if not ref.opts then | ||
ref.opts = { | ||
pinned = false, | ||
} | ||
ref.opts = {} | ||
end | ||
-- Ensure both properties exist with defaults | ||
ref.opts.pinned = ref.opts.pinned or false | ||
ref.opts.watched = ref.opts.watched or false | ||
table.insert(self.Chat.refs, ref) | ||
-- If it's a buffer reference and it's being watched, start watching | ||
if ref.bufnr and ref.opts.watched then | ||
self.Chat.watcher:watch(ref.bufnr) | ||
end | ||
end | ||
|
||
local parsed_buffer = ts_parse_buffer(self.Chat) | ||
|
@@ -176,6 +186,8 @@ function References:render() | |
end | ||
if ref.opts and ref.opts.pinned then | ||
table.insert(lines, string.format("> - %s%s", pinned_icon, ref.id)) | ||
elseif ref.opts and ref.opts.watched then | ||
table.insert(lines, string.format("> - %s%s", watched_icon, ref.id)) | ||
else | ||
table.insert(lines, string.format("> - %s", ref.id)) | ||
end | ||
|
@@ -206,6 +218,18 @@ function References:can_be_pinned(ref) | |
return false | ||
end | ||
|
||
---Determine if a reference can be watched | ||
---@param ref string | ||
---@return boolean | ||
function References:can_be_watched(ref) | ||
for _, watch in ipairs(allowed_watches) do | ||
if ref:find(watch) then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
---Get the references from the chat buffer | ||
---@return table | ||
function References:get_from_chat() | ||
|
@@ -225,7 +249,8 @@ function References:get_from_chat() | |
role = role:gsub("## ", "") | ||
elseif role == user_role and query.captures[id] == "ref" then | ||
local ref = vim.treesitter.get_node_text(node, chat.bufnr) | ||
ref = ref:gsub("^> %- ", ""):gsub(pinned_icon, "") | ||
-- Clean both pinned and watched icons | ||
ref = ref:gsub("^> %- ", ""):gsub(pinned_icon, ""):gsub(watched_icon, "") | ||
table.insert(refs, vim.trim(ref)) | ||
end | ||
end | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's add these icons into a table then we can iterate over them to remove them on line 253
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.
done