Skip to content

Commit fb976f0

Browse files
authored
feat: setup plugin on require("flutter-tools").setup_project (#408)
Previously `FlutterRun` and other plugin commands were created only if .dart or pubspec.yaml file were opened. This change will register plugin commands on project config setup. So flutter app will be possible to start without need to open dart file first.
1 parent 4f48d8b commit fb976f0

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lua/flutter-tools.lua

+15-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ local command = function(name, callback, opts)
2020
api.nvim_create_user_command(name, callback, opts or {})
2121
end
2222

23-
---@param opts flutter.ProjectConfig
24-
function M.setup_project(opts) config.setup_project(opts) end
25-
2623
local function setup_commands()
2724
-- Commands
2825
command("FlutterRun", function(data) commands.run_command(data.args) end, { nargs = "*" })
@@ -55,12 +52,17 @@ local function setup_commands()
5552
command("FlutterRename", function() require("flutter-tools.lsp.rename").rename() end)
5653
end
5754

55+
local _setup_started = false
56+
5857
---Initialise various plugin modules
5958
local function start()
60-
setup_commands()
61-
if config.debugger.enabled then dap.setup(config) end
62-
if config.widget_guides.enabled then guides.setup() end
63-
if config.decorations then decorations.apply(config.decorations) end
59+
if not _setup_started then
60+
_setup_started = true
61+
setup_commands()
62+
if config.debugger.enabled then dap.setup(config) end
63+
if config.widget_guides.enabled then guides.setup() end
64+
if config.decorations then decorations.apply(config.decorations) end
65+
end
6466
end
6567

6668
local AUGROUP = api.nvim_create_augroup("FlutterToolsGroup", { clear = true })
@@ -113,6 +115,12 @@ local function setup_autocommands()
113115
})
114116
end
115117

118+
---@param opts flutter.ProjectConfig
119+
function M.setup_project(opts)
120+
config.setup_project(opts)
121+
start()
122+
end
123+
116124
---Entry point for this plugin
117125
---@param user_config table
118126
function M.setup(user_config)

0 commit comments

Comments
 (0)