Skip to content

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

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

Merged
merged 1 commit into from
Apr 18, 2025

Conversation

m4dd0c
Copy link
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
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

Copy link
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