From 130ad29d4d2d3b38426ef7840b9055b5e26a2cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Sun, 29 Jun 2025 12:40:30 +0300 Subject: [PATCH 1/2] refactor: rename and move is_flutter_dependency_path method --- ftplugin/dart/init.lua | 14 +++----------- lua/flutter-tools/utils/path.lua | 10 ++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ftplugin/dart/init.lua b/ftplugin/dart/init.lua index a5f6442..7f39379 100644 --- a/ftplugin/dart/init.lua +++ b/ftplugin/dart/init.lua @@ -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 diff --git a/lua/flutter-tools/utils/path.lua b/lua/flutter-tools/utils/path.lua index 42cef25..49bc7f6 100644 --- a/lua/flutter-tools/utils/path.lua +++ b/lua/flutter-tools/utils/path.lua @@ -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 From ce7e89a64166eeecc8d7576632295d542c0b722e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Sun, 29 Jun 2025 12:52:16 +0300 Subject: [PATCH 2/2] fix: do not start new lsp client for flutter dependency --- lua/flutter-tools/lsp/init.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/flutter-tools/lsp/init.lua b/lua/flutter-tools/lsp/init.lua index 6b3ab03..2f5e7dd 100644 --- a/lua/flutter-tools/lsp/init.lua +++ b/lua/flutter-tools/lsp/init.lua @@ -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