Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,12 @@ vim.api.nvim_create_autocmd("LspAttach", {
```

**NOTE:**
By default this plugin excludes analysis of the packages in the flutter SDK. If for example
By default this plugin excludes analysis of the packages in the flutter SDK and in the pub cache
(`$PUB_CACHE`, or `~/.pub-cache` / `%LOCALAPPDATA%\Pub\Cache` when it is unset). If for example
you jump to the definition of `StatelessWidget`, the lsp will not try and index the 100s (maybe 1000s) of
files in that directory. If for some reason you would like this behaviour set `analysisExcludedFolders = {}`
You cannot/should not edit the files in the sdk directly so diagnostic analysis of these file is pointless.

**Exclude Note for Windows:**
To ignore packages installed with pub, consider adding `vim.fn.expand("$HOME/AppData/Local/Pub/Cache")` to
`analysisExcludedFolders` if you are using PowerShell.

#### Project Configuration

It is possible to configure how each project is run using neovim's `exrc` functionality (see `:help exrc`).
Expand Down
4 changes: 3 additions & 1 deletion lua/flutter-tools/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ end
---@param opts table
---@return table
local function get_defaults(opts)
local flutter_sdk_path = opts.flutter_sdk
local flutter_sdk_path = opts.flutter_sdk and vim.uv.fs_realpath(opts.flutter_sdk)
or opts.flutter_sdk
local config = {
init_options = {
onlyAnalyzeProjectsWithOpenFiles = true,
Expand All @@ -112,6 +113,7 @@ local function get_defaults(opts)
analysisExcludedFolders = {
path.join(flutter_sdk_path, "packages"),
path.join(flutter_sdk_path, ".pub-cache"),
path.pub_cache_dir(),
},
updateImportsOnRename = true,
},
Expand Down
10 changes: 10 additions & 0 deletions lua/flutter-tools/utils/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ function M.get_absolute_path(input_path)
end
end

---Directory where pub stores downloaded packages
---@return string?
function M.pub_cache_dir()
if vim.env.PUB_CACHE and vim.env.PUB_CACHE ~= "" then return vim.env.PUB_CACHE end
if M.is_windows then
return vim.env.LOCALAPPDATA and M.join(vim.env.LOCALAPPDATA, "Pub", "Cache")
end
return vim.env.HOME and M.join(vim.env.HOME, ".pub-cache")
end

function M.is_flutter_dependency_path(full_path)
local path_parts = { [[.pub-cache]], [[Pub\Cache]], [[/fvm/versions/]] }
if full_path then
Expand Down
28 changes: 28 additions & 0 deletions tests/path_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,31 @@ describe("path.find_root", function()
assert.are.equal(workspace_root, path.find_root(patterns, file_path))
end)
end)

describe("path.pub_cache_dir", function()
local original_pub_cache
local original_home

before_each(function()
original_pub_cache = vim.env.PUB_CACHE
original_home = vim.env.HOME
end)

after_each(function()
vim.env.PUB_CACHE = original_pub_cache
vim.env.HOME = original_home
end)

it("should use PUB_CACHE when it is set", function()
vim.env.PUB_CACHE = "/custom/pub-cache"
assert.are.equal("/custom/pub-cache", path.pub_cache_dir())
end)

it("should fall back to the default location when PUB_CACHE is unset", function()
vim.env.PUB_CACHE = nil
vim.env.HOME = "/home/user"
local expected = path.is_windows and path.join(vim.env.LOCALAPPDATA, "Pub", "Cache")
or "/home/user/.pub-cache"
assert.are.equal(expected, path.pub_cache_dir())
end)
end)
Loading