Skip to content
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

[:CopilotChatOptimise]: When the output is relatively long, the entire page freezes and does not respond to any operations. #395

Open
kaneruan opened this issue Aug 18, 2024 · 4 comments
Labels
bug Something isn't working upstream

Comments

@kaneruan
Copy link

Phenomenon

When I use :CopilotChatOptimise on 1000 lines of code, it gets stuck at the end and Neovim becomes unresponsive. Pressing any key on the keyboard has no effect.

version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

This is My lunarvim config

lvim.format_on_save.enabled = false
lvim.leader = "space"

lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
lvim.keys.normal_mode["|"] = ":vsplit<CR>"
lvim.keys.normal_mode["<C-q>"] = ":TodoTrouble<CR>"
lvim.keys.visual_mode["<leader>ca"] = ":lua vim.lsp.buf.range_code_action()<CR>"
function open_project_todo()
  local root_dir = vim.fn.systemlist('git rev-parse --show-toplevel')[1]
  if vim.v.shell_error == 0 then
    local todo_file = root_dir .. "/note.md"
    vim.cmd('vsplit ' .. todo_file)
  else
    print("Not inside a Git repository")
  end
end

-- Map the function to Ctrl+L
vim.api.nvim_set_keymap('n', '<S-n>', ':lua open_project_todo()<CR>', { noremap = true, silent = true })


lvim.plugins = {
  { "folke/tokyonight.nvim" },
  -- { "github/copilot.vim" },
  {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    event = "InsertEnter",
    config = function()
      vim.g.copilot_proxy = "http://127.0.0.1:7890"
      require("copilot").setup({
        suggestion = {
          enabled = true,
          auto_trigger = true,
          debounce = 75,
          keymap = {
            accept = "<C-g>",
            next = "<C-;>",
            prev = "<C-,>",
            dismiss = "<C-x>",
          },
        },
        filetypes = {
          yaml = false,
          markdown = false,
          help = false,
          gitcommit = false,
          gitrebase = false,
          hgcommit = false,
          svn = false,
          cvs = false,
          ["."] = false,
        },
        copilot_node_command = 'node', -- Or specify your node path
      })
    end,
  },

  {
    "CopilotC-Nvim/CopilotChat.nvim",
    branch = "canary",
    dependencies = {
      { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim
      { "nvim-lua/plenary.nvim" },  -- for curl, log wrapper
    },
    opts = {
      debug = true, -- Enable debugging
      prompts = {
        Explain = {
          prompt = '/COPILOT_EXPLAIN 请详细解释所选代码或文本。将其功能、基本原理和使用场景分段清晰地说明。输出内容请使用中文。',
        },
        Review = {
          prompt = '/COPILOT_REVIEW 对所选代码进行全面的代码审查。识别潜在问题,指出可以改进的地方,并提出最佳实践建议。在审查中请考虑代码的可读性、效率和可维护性。请用中文输出审查结果。',
        },
        Fix = {
          prompt = '/COPILOT_GENERATE 所选代码存在问题。请重写代码以修复bug,并清楚地解释所做的更改及其原因。所有解释和注释请使用中文。',
        },
        Optimize = {
          prompt = '/COPILOT_GENERATE 优化所选代码以提高性能和可读性。请解释你的优化选择及其预期影响。所有解释和注释请用中文表述。',
        },
        Docs = {
          prompt = '/COPILOT_GENERATE 为所选代码生成全面的文档注释。包括函数描述、参数说明、返回值详情,以及适用的使用示例。所有文档内容请使用中文编写。',
        },
        Tests = {
          prompt = '/COPILOT_GENERATE 为所选代码创建一套完整的单元测试。确保覆盖各种情况和边界条件。解释每个测试的目的。所有测试说明和注释请用中文书写。',
        },
        FixDiagnostic = {
          prompt = '请解决文件中的以下诊断问题。提供问题的详细解释和逐步修复指南。所有解释和指南请使用中文。',
          selection = require("CopilotChat.select").diagnostics,
        },
        Commit = {
          prompt =
          '使用commitizen规范为以下更改编写提交信息。确保标题最多50个字符,正文每行不超过72个字符。将整个信息用gitcommit语言的代码块包装。解释每项更改的理由及其潜在影响。提交信息的内容请使用中文。',
          selection = require("CopilotChat.select").gitdiff,
        },
        CommitStaged = {
          prompt =
          '使用commitizen规范为已暂存的更改编写提交信息。将标题限制在50个字符以内,正文每行不超过72个字符。用gitcommit语言的代码块封装整个信息。总结这些暂存更改的整体目的及其对项目的集体影响。提交信息请用中文撰写。',
          selection = function(source)
            return require("CopilotChat.select").gitdiff(source, true)
          end,
        },
      },
    },
    -- See Commands section for default commands if you want to lazy load on them
  },
}
require("lvim.lsp.manager").setup("emmet_ls")
vim.keymap.set("n", "<S-m>", ":HopChar2<cr>")
vim.keymap.set("n", "<S-p>", ":Telescope marks<cr>")
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"

vim.opt.cmdheight = 2         -- more space in the neovim command line for displaying messages
-- vim.opt.guifont = "monospace:h17" -- the font used in graphical neovim applications
vim.opt.shiftwidth = 2        -- the number of spaces inserted for each indentation
vim.opt.tabstop = 2           -- insert 2 spaces for a tab
vim.opt.relativenumber = true -- relative line numbers
vim.opt.wrap = true           -- wrap lines

-- theme
require("tokyonight").setup({
  -- your configuration comes here
  -- or leave it empty to use the default settings
  style = "storm",        -- The theme comes in three styles, `storm`, `moon`, a darker variant `night` and `day`
  light_style = "day",    -- The theme is used when the background is set to light
  transparent = false,    -- Enable this to disable setting the background color
  terminal_colors = true, -- Configure the colors used when opening a `:terminal` in [Neovim](https://github.com/neovim/neovim)
  styles = {
    -- Style to be applied to different syntax groups
    -- Value is any valid attr-list value for `:help nvim_set_hl`
    comments = { italic = true },
    keywords = { italic = true },
    functions = {},
    variables = {},
    -- Background styles. Can be "dark", "transparent" or "normal"
    sidebars = "dark",              -- style for sidebars, see below
    floats = "dark",                -- style for floating windows
  },
  sidebars = { "qf", "help" },      -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]`
  day_brightness = 0.3,             -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors
  hide_inactive_statusline = false, -- Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**.
  dim_inactive = false,             -- dims inactive windows
  lualine_bold = false,             -- When `true`, section headers in the lualine theme will be bold
})

lvim.builtin.telescope.defaults.layout_config = {
  vertical = {
    width = 0.9,  -- 调整宽度为屏幕宽度的 90%
    height = 0.9, -- 可选,调整高度为屏幕高度的 90%
  },
}

lvim.builtin.telescope.defaults.layout_strategy = 'vertical'
-- Set up keybindings for Codeium
lvim.keys.insert_mode = {
  -- ... your other keybindings ...
  ["<C-g>"] = function() require("copilot.suggestion").accept() end,
  ["<C-;>"] = function() require("copilot.suggestion").next() end,
  ["<C-,>"] = function() require("copilot.suggestion").prev() end,
  ["<C-x>"] = function() require("copilot.suggestion").dismiss() end,
}
-- 添加新的快速聊天映射
lvim.keys.normal_mode["<leader>m"] = function()
  local input = vim.fn.input("快速聊天: ")
  if input ~= "" then
    require("CopilotChat").ask(input, { selection = require("CopilotChat.select").buffer })
  end
end
lvim.keys.visual_mode["<leader>m"] = function()
  local input = vim.fn.input("快速聊天: ")
  if input ~= "" then
    require("CopilotChat").ask(input, { selection = require("CopilotChat.select").visual })
  end
end
@jellydn jellydn added enhancement New feature or request good first issue Good for newcomers labels Aug 21, 2024
@franroa
Copy link

franroa commented Aug 31, 2024

same issue

@deathbeam deathbeam added bug Something isn't working and removed enhancement New feature or request good first issue Good for newcomers labels Sep 2, 2024
@kaneruan
Copy link
Author

I think I haven found out the key problem now. That removed the below code would solve the problem.

vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"

problem reference

@deathbeam
Copy link
Collaborator

So looks like this is neovim core issue then neovim/neovim#27422, should we keep this issue open then or nah?

@Woit
Copy link

Woit commented Oct 7, 2024

Have same issue even on small buffers/files. It related mostly to how long nvim is opened.

Upd: For some reason in debug mode all works fine. CopilotChat freezes not only chat screen, but whole nvim tab in kitty terminal window. This happens only during "animation" process, when spinner is animated and copilot response prints out line by line. In debug mode i forced to press enter on each line, and whole response text is appears on screen at the end, in one big piece, and no issue here. Is it possible to somehow disable this "animation" in easy way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream
Projects
None yet
Development

No branches or pull requests

5 participants