Skip to content

[BUG] LSP cannot resolve packages in Flutter dependencies #463

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

Open
1 task done
fathilarham opened this issue Mar 30, 2025 · 3 comments
Open
1 task done

[BUG] LSP cannot resolve packages in Flutter dependencies #463

fathilarham opened this issue Mar 30, 2025 · 3 comments

Comments

@fathilarham
Copy link

fathilarham commented Mar 30, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The LSP fails to resolve packages for all Flutter dependencies located in the pub-cache, making it impossible to properly navigate through dependency implementations (go to definition, go to reference, etc.).

Image

Expected Behavior

  • LSP should properly resolve packages in dependencies
  • Navigation (go to definition, references) should work in dependency code
  • Types and imports in dependency files should be properly recognized

Steps To Reproduce

  1. Install Lazyvim
  2. Install flutter with asdf (dart is included from the Flutter installation, not separate asdf dart)
  3. Configure flutter-tools on nvim folder with this lua file
return {
  {
    "nvim-flutter/flutter-tools.nvim",
    lazy = false,
    dependencies = {
      "nvim-lua/plenary.nvim",
      "stevearc/dressing.nvim",
    },
    config = function()
      require("flutter-tools").setup({
        flutter_path = nil,
        flutter_lookup_cmd = "asdf where flutter",
        fvm = false,
        widget_guides = { enabled = true },
        lsp = {
          settings = {
            showtodos = true,
            analysisExcludedFolders = {},
            completefunctioncalls = true,
            renamefileswithclasses = "prompt",
            updateimportsonrename = true,
            enablesnippets = false,
          },
        },
      })
    end,
  },
}
  1. Open a Flutter project in Neovim with flutter-tools configured
  2. Try to navigate to a dependency's function/type definition from your project code
  3. Observe that while the file opens, all imports and types are highlighted as undefined
  4. Open the dependency project directly from pub-cache - the issue persists

Environment

- OS: Ubuntu 24.04.2 LTS x86_64
- neovim version: v0.10.4
- Flutter version: 3.29.2-stable
- Is flutter in $PATH: yes
- Flutter path (from which flutter command): /home/fathilarham/.asdf/shims/flutter
- Flutter absolute path (from asdf where flutter command): /home/fathilarham/.asdf/installs/flutter/3.29.2-stable
- Dart path (from which dart command): /home/fathilarham/.asdf/shims/dart
- Pub cache path: /home/fathilarham/.pub-cache
@fathilarham fathilarham changed the title [BUG] LSP cannot resolve packages in Flutter dependencies [BUG] LSP cannot resolve packages & types in Flutter dependencies Mar 30, 2025
@fathilarham fathilarham changed the title [BUG] LSP cannot resolve packages & types in Flutter dependencies [BUG] LSP cannot resolve packages in Flutter dependencies Mar 30, 2025
@sidlatau
Copy link
Collaborator

sidlatau commented Apr 5, 2025

I was able to reproduce the problem by commenting "/Users/ts/.pub-cache/", line in my config. Dependencies should not be analyzed, please try to add your .pub_cache to analysisExcludedFolders list.

    flutter_tools.setup {
      lsp = {

        settings = {
          renameFilesWithClasses = "always",
          analysisExcludedFolders = {
            ".dart_tool",
            "/Users/ts/.pub-cache/",
            "/Users/ts/fvm/",
          },

        },
      },

@fathilarham
Copy link
Author

fathilarham commented Apr 8, 2025

I was able to reproduce the problem by commenting "/Users/ts/.pub-cache/", line in my config. Dependencies should not be analyzed, please try to add your .pub_cache to analysisExcludedFolders list.

flutter_tools.setup {
  lsp = {

    settings = {
      renameFilesWithClasses = "always",
      analysisExcludedFolders = {
        ".dart_tool",
        "/Users/ts/.pub-cache/",
        "/Users/ts/fvm/",
      },

    },
  },

Thanks for the reply @sidlatau,

I still want to use the LSP to navigate within dependency codes. By exluding the .pub-cahce folder, I can't go to definition, reference, highlight type, etc.

I tried VSCode. The LSP works well in the dependency codes.
Image

@sidlatau
Copy link
Collaborator

Hmm, for me LSP still works even if I disable analysis. I can go to definition, find references, etc. You may even try to remove analysisExcludedFolders from your config, it has defaults to disable analysis on SDK folders.

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

No branches or pull requests

2 participants