@@ -3,7 +3,6 @@ local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.util
33local path = lazy .require (" flutter-tools.utils.path" ) --- @module " flutter-tools.utils.path"
44local color = lazy .require (" flutter-tools.lsp.color" ) --- @module " flutter-tools.lsp.color"
55local lsp_utils = lazy .require (" flutter-tools.lsp.utils" ) --- @module " flutter-tools.lsp.utils"
6- local fvm_utils = lazy .require (" flutter-tools.lsp.fvm_utils" ) --- @module " flutter-tools.lsp.fvm_utils"
76
87local api = vim .api
98local lsp = vim .lsp
@@ -168,14 +167,16 @@ end
168167--- @return string ?
169168function M .get_project_root_dir ()
170169 local conf = require (" flutter-tools.config" )
171- local current_buffer_path = lsp_utils .current_buffer_path_if_valid ()
170+ local current_buffer_path = path .current_buffer_path ()
171+ local root_path = lsp_utils .is_valid_path (current_buffer_path ) and
172+ path .find_root (conf .root_patterns , current_buffer_path )
172173
173- if (current_buffer_path == nil ) then
174- local client = lsp_utils .get_dartls_client ()
175- return client and client .config .root_dir or nil
174+ if (root_path ~= nil ) then
175+ return root_path
176176 end
177177
178- return path .find_root (conf .root_patterns , current_buffer_path ) or current_buffer_path
178+ local client = lsp_utils .get_dartls_client ()
179+ return client and client .config .root_dir or nil
179180end
180181
181182-- FIXME: I'm not sure how to correctly wait till a server is ready before
@@ -242,18 +243,6 @@ local function get_server_config(user_config, callback)
242243 config .on_init = function (client , _ )
243244 return client .notify (" workspace/didChangeConfiguration" , { settings = config .settings })
244245 end
245- -- TODO: flag something such that we only call attach on exit that has been flagged to
246- -- re attach.
247- config .on_exit = function ()
248- if not M .pending_reattach then
249- return
250- end
251- M .pending_reattach = false
252- -- vim.schedule does not work, it executes attach too soon and
253- -- instead of creating a new client, the lsp implementation tries
254- -- to use the old, stopped client.
255- vim .defer_fn (M .attach , 0 )
256- end
257246 callback (config , paths )
258247 end )
259248end
0 commit comments