Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made function 'start' in 'lua/flutter-tools.lua' public #429

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lua/flutter-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local lsp = lazy.require("flutter-tools.lsp") ---@module "flutter-tools.lsp"
local outline = lazy.require("flutter-tools.outline") ---@module "flutter-tools.outline"
local devices = lazy.require("flutter-tools.devices") ---@module "flutter-tools.devices"
local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.utils"
local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"

local api = vim.api

Expand Down Expand Up @@ -55,17 +56,23 @@ local function setup_commands()
command("FlutterRename", function() require("flutter-tools.lsp.rename").rename() end)
end

local _setup_started = false
local _has_started = false
local _has_setup = false

---Initialise various plugin modules
local function start()
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
function M.start()
if _has_started then return end

if not _has_setup then
ui.notify("Cannot start because the plugin has not been setup yet.", ui.ERROR)
return
end

_has_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

local AUGROUP = api.nvim_create_augroup("FlutterToolsGroup", { clear = true })
Expand All @@ -78,7 +85,7 @@ local function setup_autocommands()
group = AUGROUP,
pattern = { "*.dart", "pubspec.yaml" },
once = true,
callback = start,
callback = M.start,
})

if config.lsp.color.enabled then
Expand Down Expand Up @@ -120,13 +127,15 @@ end

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

---Entry point for this plugin
---@param user_config table
function M.setup(user_config)
_has_setup = true
config.set(user_config)
setup_autocommands()
end
Expand Down
Loading