akinsho / flutter-tools.nvim

Tools to help create flutter apps in neovim using the native lsp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: flutter-tools breaks LunarVim distribution

tom-010 opened this issue · comments

Describe the bug
I've set up fresh LunarVim-installation. LunarVim is a NeoVim-Distribution. Adding the Treesitter for Dart worked just fine as well as the Dart-LSP, which I set up with the line require('lspconfig').dartls.setup{}.

But when I installed flutter-tools, Treesitter, as well as the installed Dart-LSP stopped working. But flutter-tools does not work either. For example, when I try to run the code_actions, I get:

E5108: Error executing lua /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1799: Expected Lua number
stack traceback:
        [C]: in function 'nvim_win_get_buf'
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1799: in function 'make_range_params'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:597: in function 'code_action'
        [string ":lua"]:1: in main chunk

System information

  • OS: Ubuntu 22.04
  • Flutter version: 3.7.5
  • Is flutter in $PATH: yes
  • neovim version: NVIM v0.8.3 / LuaJIT 2.1.0-beta3

Additional context
Here is nvim/runtime/lua/vim/lsp/buf.lua:597:

function M.code_action(context)
  validate { context = { context, 't', true } }
  context = context or {}
  if not context.diagnostics then
    context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
  end
  local params = util.make_range_params() -- <-- THIS LINE
  params.context = context
  code_action_request(params)
end

And nvim/runtime/lua/vim/lsp/util.lua:1799:

function M.make_range_params(window, offset_encoding)
  local buf = vim.api.nvim_win_get_buf(window) -- <--- THIS LINE
  offset_encoding = offset_encoding or M._get_offset_encoding(buf)
  local position = make_position_param(window, offset_encoding)
  return {
    textDocument = M.make_text_document_params(buf),
    range = { start = position; ["end"] = position; }
  }
end
commented

Hi @tom-010,

So there are a few issues with this report, firstly users are strongly advised Not to have dartls setup separate to this plugin because this is already done by this plugin. It also just won't work correctly. This is described in the README so I think you should take a look at that again in more detail.

Also to properly handle issues I need to have the issue reproduced in a minimal init.lua there are a few extra moving parts in a premade config that I can't really afford to spend the time digging into. Based on normal usage I can't reproduce this issue.

Can you please try setting this plugin up using the minimal init.lua without any other plugins or setup and with only the lsp setup via this plugin not via lspconfig and then see if you are still seeing issues.

Hi @akinsho,

thank you for your answer. The report was misleading. I had it first without another Dart LS. I just wanted to let you know the effect.

Regarding a minimal init.lua: It is kind of hard for me, as LunarVim does so much and I have a hard time to go from the big configuration LunarVim provides to a minimal init.lua. But I will give it another try.

commented

@tom-010 just to clarify I'm not suggesting you change your entire configuration. I just mean for the purposes of clarifying the issue you are raising you should create an empty init.lua and load only this plugin and set it up then open a dart file and see if the issue reproduces.

@tom-010 I use LunarVim with the following config:

config.lua

reload "user.plugins"
reload "user.flutter-tools"

user/plugins.lua

lvim.plugins = {
  # ...
  {
    'akinsho/flutter-tools.nvim',
    requires = 'nvim-lua/plenary.nvim',
  },
  # ...
}

user/flutter-tools.lua

local status_ok, flutter_tools = pcall(require, "flutter-tools")
if not status_ok then
  return
end

flutter_tools.setup {
  debugger = {
    enabled = true,
    run_via_dap = true, -- use dap instead of a plenary job to run flutter apps
  },
  decorations = {
    statusline = {
      app_version = false,
      device = false,
    },
  },
  fvm = true,
  widget_guides = {
    enabled = true,
    debug = true,
  },
  dev_log = {
    enabled = false,
  },
  dev_tools = {
    autostart = false, -- autostart devtools server if not detected
    auto_open_browser = true, -- Automatically opens devtools in the browser
  },
  outline = {
    auto_open = false, -- if true this will open the outline automatically when it is first populated
  },
  lsp = {
    on_attach = require("lvim.lsp").common_on_attach,
    capabilities = require("lvim.lsp").common_capabilities,
    color = { -- show the derived colours for dart variables
      enabled = false, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10
      background = false, -- highlight the background
      foreground = false, -- highlight the foreground
      virtual_text = true, -- show the highlight using virtual text
      virtual_text_str = "", -- the virtual text character to highlight
    },
    settings = {
      showTodos = true,
      renameFilesWithClasses = 'prompt',
    },
  },
}
commented

I'm going to close this out since I think the likely issue relates to configuring LunarVim rather than a bug in this plugin since I believe it should all work when used with a minimal configuration. If not please post a minimal init.lua and I'll retest +/- re-open this

I agree and will investigate my config further. Thank you for your help @akinsho and @amitkot

Hi @tom-010

Past few weeks I've been struggling to configure lunarvim for flutter specially with debug capabilities, I'm able to run flutter app with planery but not with dap enabled.

Have you found any solution yet?

I gave up and use vscode for flutter development, which does not happen too often. Sorry.