Skip to content

fix: do not start new LSP client when navigating to flutter dependency file #483

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

Merged
merged 2 commits into from
Jul 1, 2025
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
14 changes: 3 additions & 11 deletions ftplugin/dart/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ if vim.b.flutter_tools_did_ftplugin then return end
vim.b.flutter_tools_did_ftplugin = 1

require("flutter-tools.lsp").attach()
local path = require("flutter-tools.utils.path")

vim.opt_local.comments = [[sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://]]
vim.opt_local.commentstring = [[//%s]]
vim.opt.includeexpr = "v:lua.require('flutter-tools.resolve_url').resolve_url(v:fname)"

local function is_nonmodifiable_path()
local path_parts = { [[.pub-cache]], [[Pub\Cache]], [[/fvm/versions/]] }
local full_path = vim.fn.expand("%:p")
if full_path then
for _, path_part in ipairs(path_parts) do
if full_path:find(path_part, nil, true) then return true end
end
end
return false
end
local full_path = vim.fn.expand("%:p")
-- Prevent writes to files in the pub cache and FVM folder.
if is_nonmodifiable_path() then vim.opt_local.modifiable = false end
if path.is_flutter_dependency_path(full_path) then vim.opt_local.modifiable = false end
14 changes: 8 additions & 6 deletions lua/flutter-tools/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ end
function M.get_project_root_dir()
local conf = require("flutter-tools.config")
local current_buffer_path = path.current_buffer_path()
local root_path = lsp_utils.is_valid_path(current_buffer_path)
and path.find_root(conf.root_patterns, current_buffer_path)
or nil

if root_path ~= nil then return root_path end

-- Check if path is flutter dependency. For dependencies we do not
-- search for a root directory as they are not projects.
if not path.is_flutter_dependency_path(current_buffer_path) then
local root_path = lsp_utils.is_valid_path(current_buffer_path)
and path.find_root(conf.root_patterns, current_buffer_path)
or nil
if root_path ~= nil then return root_path end
end
local client = lsp_utils.get_dartls_client()
return client and client.config.root_dir or nil
end
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 @@ -139,4 +139,14 @@ function M.get_absolute_path(input_path)
end
end

function M.is_flutter_dependency_path(full_path)
local path_parts = { [[.pub-cache]], [[Pub\Cache]], [[/fvm/versions/]] }
if full_path then
for _, path_part in ipairs(path_parts) do
if full_path:find(path_part, nil, true) then return true end
end
end
return false
end

return M
Loading