Skip to content

fix(validation): Ensure If the terminal buffer is excluded.#1115

Merged
deathbeam merged 1 commit into
CopilotC-Nvim:mainfrom
m4dd0c:m4dd0c/exclude-term
Apr 18, 2025
Merged

fix(validation): Ensure If the terminal buffer is excluded.#1115
deathbeam merged 1 commit into
CopilotC-Nvim:mainfrom
m4dd0c:m4dd0c/exclude-term

Conversation

@m4dd0c
Copy link
Copy Markdown
Contributor

@m4dd0c m4dd0c commented Apr 18, 2025

closes #1091

Problem

As I have explained, the current implementation of utils.buf_valid is not excluding terminal buffer, that is causing the token exceed problem.

Solution

Added a condition to check if the buffer is terminal_buffer using buftype.

--- Check if a buffer is valid
--- Check if the buffer is not a terminal
---@param bufnr number? The buffer number
---@return boolean
function M.buf_valid(bufnr)
  return bufnr
      and vim.api.nvim_buf_is_valid(bufnr)
      and vim.api.nvim_buf_is_loaded(bufnr)
      and vim.bo[bufnr].buftype ~= 'terminal'
    or false
end

…rs and #buffer

This prevents unsolicited text from being included in the CopilotChat context window.
@deathbeam deathbeam merged commit bc644cd into CopilotC-Nvim:main Apr 18, 2025
1 check passed
@deathbeam
Copy link
Copy Markdown
Collaborator

Thanks. Dont think this is the best place for this check but it causes least conflicts with #1029 so for now its good enough.

@all-contributors add @m4dd0c for code

@allcontributors
Copy link
Copy Markdown
Contributor

@deathbeam

I've put up a pull request to add @m4dd0c! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude Terminal buffer from #buffers.

2 participants