akinsho / flutter-tools.nvim

Tools to help create flutter apps in neovim using the native lsp
MIT License
932 stars 75 forks source link

[BUG] "error drawing label" when cut a large block of code #357

Closed justjew closed 1 day ago

justjew commented 2 weeks ago

Is there an existing issue for this?

Current Behavior

Sometimes when I cut (d) a big block of code, especially after var qwer = until ;, I am facing the following error.

error drawing label for /Users/path/to/my.dart on line 80. 
because:

If I disable flutter-tools and enable dartls using lspconfig, the error never appears.

Here's my flutter-tools config:

return {
  'akinsho/flutter-tools.nvim',
  lazy = false,
  dependencies = {
    'nvim-lua/plenary.nvim',
    'stevearc/dressing.nvim', -- optional for vim.ui.select
  },
  ft = 'dart',
  config = function()
    require('flutter-tools').setup {
      flutter_path = nil,
      flutter_lookup_cmd = 'asdf where flutter',
      statusline = {
        app_version = true,
      },
      lsp = {
        color = { -- show the derived colours for dart variables
          enabled = true, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10
          background = false, -- highlight the background
          background_color = nil, -- required, when background is transparent (i.e. background_color = { r = 19, g = 17, b = 24},)
          foreground = true, -- highlight the foreground
          virtual_text = true, -- show the highlight using virtual text
          virtual_text_str = '■', -- the virtual text character to highlight
        },
      },
    }
    require('flutter-tools.lsp').attach()
  end,
}

Expected Behavior

No error

Steps To Reproduce

  1. Cut a large block of some var definition from = to ;
  2. See error (sometimes)

Environment

- OS: Mac OS Sonoma 14.2.1 (23C71)
- Flutter version: 3.22.2
- Is flutter in $PATH: of course
- neovim version: v0.9.5

Anything else?

No response

JordanllHarper commented 6 days ago

Not super helpful but have also seen this issue.

CrestNiraj12 commented 2 days ago

Any updates? This issue is so annoying. I get multiple of those if I delete/undo/cut multiple lines of code at once for each of the lines I delete and it blocks my entire view.

akinsho commented 2 days ago

For full visibility, this issue is going to need someone to get their hands dirty and dig in for a solution. As I've mentioned in other issues I'm not currently actively maintaining this and am fully dependent on users and contributors submitting PRs to fix issues like this.

JordanllHarper commented 2 days ago

I'll be happy to have a look at this

JordanllHarper commented 1 day ago

On investigation, it seems the line numbers we're getting (from the lsp) to draw the labels are falling out of sync with the buffer. Managed to reproduce this with some sample data.

Current theory is we get line numbers from the lsp response that don't match with the line numbers in the buffer. The current implementation is when we come to draw the labels using nvim_buf_set_extmark, we catch any issues and notify with the error in the post.

Not sure how we want to handle this? I don't think this is the plugin's specific problem, and labels will recover pretty quickly. Perhaps only render the label if it doesn't exceed the file line length?

sidlatau commented 1 day ago

This is a good proposal. As you said labels will recover pretty quickly, so showing this label error does not add much value.

akinsho commented 1 day ago

Merged this in now which I hope fixes this issue so will close this out but if it recurs for anyone comment back on here and I'll re-open