Skip to content

Commit

Permalink
feat: setup plugin on require("flutter-tools").setup_project (#408)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sidlatau authored Nov 15, 2024
1 parent 4f48d8b commit fb976f0
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lua/flutter-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ local command = function(name, callback, opts)
api.nvim_create_user_command(name, callback, opts or {})
end

---@param opts flutter.ProjectConfig
function M.setup_project(opts) config.setup_project(opts) end

local function setup_commands()
-- Commands
command("FlutterRun", function(data) commands.run_command(data.args) end, { nargs = "*" })
Expand Down Expand Up @@ -55,12 +52,17 @@ local function setup_commands()
command("FlutterRename", function() require("flutter-tools.lsp.rename").rename() end)
end

local _setup_started = false

---Initialise various plugin modules
local function start()
setup_commands()
if config.debugger.enabled then dap.setup(config) end
if config.widget_guides.enabled then guides.setup() end
if config.decorations then decorations.apply(config.decorations) end
if not _setup_started then
_setup_started = true
setup_commands()
if config.debugger.enabled then dap.setup(config) end
if config.widget_guides.enabled then guides.setup() end
if config.decorations then decorations.apply(config.decorations) end
end
end

local AUGROUP = api.nvim_create_augroup("FlutterToolsGroup", { clear = true })
Expand Down Expand Up @@ -113,6 +115,12 @@ local function setup_autocommands()
})
end

---@param opts flutter.ProjectConfig
function M.setup_project(opts)
config.setup_project(opts)
start()
end

---Entry point for this plugin
---@param user_config table
function M.setup(user_config)
Expand Down

0 comments on commit fb976f0

Please sign in to comment.