diff --git a/lua/flutter-tools/executable.lua b/lua/flutter-tools/executable.lua index 48f3de4..1f74f84 100644 --- a/lua/flutter-tools/executable.lua +++ b/lua/flutter-tools/executable.lua @@ -174,13 +174,13 @@ function M.get(callback) if config.flutter_lookup_cmd then return path_from_lookup_cmd(config.flutter_lookup_cmd, function(paths) - paths = { + cached_paths = { flutter_bin = paths.flutter_bin, flutter_sdk = paths.flutter_sdk, dart_bin = paths.dart_bin, dart_sdk = dart_sdk_root(paths), } - callback(paths) + callback(cached_paths) end) end diff --git a/lua/flutter-tools/lsp/init.lua b/lua/flutter-tools/lsp/init.lua index 2f5e7dd..e95672d 100644 --- a/lua/flutter-tools/lsp/init.lua +++ b/lua/flutter-tools/lsp/init.lua @@ -287,12 +287,15 @@ function M.attach() if not is_valid_path(buffer_path) then return end get_server_config(user_config, function(c) + -- This callback can run asynchronously, by which point the user may have + -- switched to or deleted the buffer we were asked to attach to. + if not api.nvim_buf_is_valid(buf) then return end c.root_dir = M.get_project_root_dir() or fs.dirname(fs.find(conf.root_patterns, { path = buffer_path, upward = true, })[1]) - vim.lsp.start(c) + vim.lsp.start(c, { bufnr = buf }) end) end