diff --git a/README.md b/README.md index c4b5bf5f..c60fbe2c 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ require("flutter-tools").setup { flutter_lookup_cmd = nil, -- example "dirname $(which flutter)" or "asdf where flutter" root_patterns = { ".git", "pubspec.yaml" }, -- patterns to find the root of your flutter project fvm = false, -- takes priority over path, uses /.fvm/flutter_sdk if enabled + default_run_args= nil, -- Default options for run command (i.e `{ flutter = "--no-version-check" }`). Configured separately for `dart run` and `flutter run`. widget_guides = { enabled = false, }, diff --git a/lua/flutter-tools.lua b/lua/flutter-tools.lua index ffd31281..5890ff74 100644 --- a/lua/flutter-tools.lua +++ b/lua/flutter-tools.lua @@ -118,14 +118,14 @@ local function setup_autocommands() }) end ----@param opts flutter.ProjectConfig +---@param opts flutter.ProjectConfig | flutter.ProjectConfig[] Project-specific configuration function M.setup_project(opts) config.setup_project(opts) start() end ---Entry point for this plugin ----@param user_config table +---@param user_config flutter.Config Configuration options for flutter-tools function M.setup(user_config) config.set(user_config) setup_autocommands() diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index b3a027cc..f83021df 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -278,10 +278,21 @@ local function run(opts, project_conf, launch_config) -- To determinate if the project is a flutter project we need to check if the pubspec.yaml -- file has a flutter dependency in it. We need to get cwd first to pick correct pubspec.yaml file. local is_flutter_project = has_flutter_dependency_in_pubspec(cwd) + local default_run_args = config.default_run_args + local run_args if is_flutter_project then ui.notify("Starting flutter project...") + if default_run_args then run_args = default_run_args.flutter end else ui.notify("Starting dart project...") + if default_run_args then run_args = default_run_args.dart end + end + if run_args then + if type(run_args) == "string" then + vim.list_extend(args, vim.split(run_args, " ")) + elseif type(run_args) == "table" then + vim.list_extend(args, run_args) + end end runner = use_debugger_runner(opts.force_debug) and debugger_runner or job_runner runner:run( diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index e8676e65..576d9b95 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -15,6 +15,34 @@ local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.util ---@field web_port? string ---@field cwd? string full path of current working directory, defaults to LSP root ---@field additional_args? string[] additional arguments to pass to the flutter run command +--- +---@class flutter.DevLogOpts +---@field filter? fun(data: string): boolean +---@field enabled? boolean +---@field notify_errors? boolean +---@field focus_on_open? boolean +---@field open_cmd? string +--- +---@class flutter.RunArgsOpts +---@field flutter? table|string -- options applied to `flutter run` command +---@field dart? table|string -- options appliert to `dart run` command +--- +---@class flutter.Config +---@field flutter_path? string Path to the Flutter SDK +---@field flutter_lookup_cmd? string Command to find Flutter SDK +---@field pre_run_callback? fun(opts: table) Function called before running Flutter +---@field root_patterns? string[] Patterns to find project root +---@field fvm? boolean Whether to use FVM (Flutter Version Manager) +---@field default_run_args? flutter.RunArgsOpts Default options for run command +---@field widget_guides? {enabled: boolean, debug: boolean} +---@field ui? {border: string} +---@field decorations? {statusline: {app_version: boolean, device: boolean, project_config: boolean}} +---@field debugger? {enabled: boolean, exception_breakpoints?: table, evaluate_to_string_in_debug_views?: boolean, register_configurations?: fun(paths: table)} +---@field closing_tags? {highlight: string, prefix: string, priority: number, enabled: boolean} +---@field lsp? {debug?: number, color?: {enabled: boolean, background: boolean, foreground: boolean, virtual_text: boolean, virtual_text_str: string, background_color?: string}, settings?: table} +---@field outline? {auto_open: boolean, open_cmd?: string} +---@field dev_log? flutter.DevLogOpts +---@field dev_tools? {autostart: boolean, auto_open_browser: boolean} local M = {} @@ -67,13 +95,13 @@ M.debug_levels = { DEBUG = 1, WARN = 2, } - local config = { flutter_path = nil, flutter_lookup_cmd = get_default_lookup(), pre_run_callback = nil, root_patterns = { ".git", "pubspec.yaml" }, fvm = false, + default_run_args = nil, widget_guides = { enabled = false, debug = false, diff --git a/lua/flutter-tools/ui.lua b/lua/flutter-tools/ui.lua index 07b3b45c..b4e85798 100644 --- a/lua/flutter-tools/ui.lua +++ b/lua/flutter-tools/ui.lua @@ -10,6 +10,12 @@ local entry_type = { ---@generic T ---@alias SelectionEntry {text: string, type: EntryType, data: T} +---@class flutter.WindowOpts +---@field open_cmd? string Command to open the window +---@field filename? string Name to give the buffer +---@field filetype string Filetype to set for the buffer +---@field focus_on_open? boolean Whether to focus the window after opening + ---@enum local M = { ERROR = vim.log.levels.ERROR, @@ -129,7 +135,7 @@ function M.select(opts) end ---Create a split window ----@param opts table +---@param opts flutter.WindowOpts ---@param on_open fun(buf: integer, win: integer) ---@return nil function M.open_win(opts, on_open)