pasky / claude.vim

Claude vim plugin for AI pair programming - a hacker's gateway to LLMs
MIT License
66 stars 2 forks source link

Ignoring the contents of invisible buffers #1

Closed StanAngeloff closed 5 days ago

StanAngeloff commented 2 weeks ago

In keeping with the spirit of the original development, I asked Claude to update function! s:GetBufferContents() to only send buffers that are currently visible. This is very handy as anything that's quit and not attached to a window will get ignored. I'm a heavy user of tabs and I found that claude.vim was sending the contents of tabs I have long since quit.

I'm not sending as a PR as I find this change to be controversial and may affect current users of the plug-in. I'd be happy to refactor (or rather ask Claude to refactor) and put this behind a flag?

diff --git a/plugin/claude.vim b/plugin/claude.vim
index 6d66f10..df3c45e 100644
--- a/plugin/claude.vim
+++ b/plugin/claude.vim
@@ -441,9 +441,13 @@ function! s:GetBufferContents()
   let l:buffers = []
   for bufnr in range(1, bufnr('$'))
     if buflisted(bufnr) && bufname(bufnr) != 'Claude Chat'
-      let l:bufname = bufname(bufnr)
-      let l:contents = join(getbufline(bufnr, 1, '$'), "\n")
-      call add(l:buffers, {'name': l:bufname, 'contents': l:contents})
+      " Check if the buffer is attached to any window
+      let l:windows = win_findbuf(bufnr)
+      if !empty(l:windows)
+        let l:bufname = bufname(bufnr)
+        let l:contents = join(getbufline(bufnr, 1, '$'), "\n")
+        call add(l:buffers, {'name': l:bufname, 'contents': l:contents})
+      endif
     endif
   endfor
   return l:buffers
pasky commented 1 week ago

I think it's more surprising to send non-visible buffers than the opposite, so I'd be happy to apply this unconditionally. I think for sending hidden buffers a better mechanism would be prudent (e.g. a way to specify such buffers explicitly in the ClaudeChat window).