flutter-tools.nvim icon indicating copy to clipboard operation
flutter-tools.nvim copied to clipboard

How to setup `root_dir` for dartls

Open Energizer328 opened this issue 2 years ago • 6 comments

Hi! I usually work in flutter projects with multiple packages and I realized that lsp features like references were only analyzing the packages of the currently opened buffers. I did some digging around and the problem seems to be the root directory of dartls. Now, if I setup dartls using lspconfig, I can actually configure this using the root_dir parameter of the configuration. Like this

require("lspconfig").dartls.setup {
  on_attach = commons.on_attach,
  settings = {
    enableSnippets = true,
  },
  init_options = {
    onlyAnalyzeProjectsWithOpenFiles = false,
  },
  root_dir = function() return vim.loop.cwd() end,
}

However, when i try to do a similar thing with flutter-tools

require("flutter-tools").setup {
  lsp = {
    on_attach = commons.on_attach,
    settings = {
      enableSnippets = true,
    },
    root_dir = function() return vim.loop.cwd() end,
    init_options = {
      onlyAnalyzeProjectsWithOpenFiles = false,
    },
  },
  widget_guides = {
    enabled = true,
  },
}

it doesn't work. I also took a quick peek under the hood, and it seems to me that the root_dir parameter is completely ignored by flutter-tools: https://github.com/akinsho/flutter-tools.nvim/blob/ae0be3cef35c0cb41d6c7f814a19b3402d50fd7a/lua/flutter-tools/lsp/init.lua#L257-L264

So my question is: Does flutter-tools support customization of the root directory and, if so, what is the correct way to do this?

Thank you so much for time!

Energizer328 avatar Jan 25 '23 13:01 Energizer328