From 378b2d835db5edb8867618fb0a39ac5f3142745f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Tue, 27 May 2025 22:30:34 +0300 Subject: [PATCH 1/3] feat: add possibility to set global run options --- README.md | 1 + lua/flutter-tools.lua | 4 ++-- lua/flutter-tools/commands.lua | 8 ++++++++ lua/flutter-tools/config.lua | 26 +++++++++++++++++++++++++- lua/flutter-tools/ui.lua | 8 +++++++- 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c4b5bf5f..18975240 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 + global_run_options= nil, -- Global options for flutter run (from `flutter run --verbose --help`, i.e `--no-version-check`) 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..41e59c61 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -283,6 +283,14 @@ local function run(opts, project_conf, launch_config) else ui.notify("Starting dart project...") end + local global_run_options = config.global_run_options + if global_run_options then + if type(global_run_options) == "string" then + vim.list_extend(args, vim.split(global_run_options, " ")) + elseif type(global_run_options) == "table" then + vim.list_extend(args, global_run_options) + end + end runner = use_debugger_runner(opts.force_debug) and debugger_runner or job_runner runner:run( opts, diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index e8676e65..13861c17 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -15,6 +15,30 @@ 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.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 global_run_options? table|string Global options for flutter run (from `flutter run --verbose --help`) +---@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 +91,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, + global_run_options = 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) From 680f3965a082206a5864e1878ea0eb51dc8fc83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Wed, 28 May 2025 21:46:37 +0300 Subject: [PATCH 2/3] fixup! feat: add possibility to set global run options --- README.md | 2 +- lua/flutter-tools/commands.lua | 15 +++++++++------ lua/flutter-tools/config.lua | 6 +++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 18975240..c60fbe2c 100644 --- a/README.md +++ b/README.md @@ -240,7 +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 - global_run_options= nil, -- Global options for flutter run (from `flutter run --verbose --help`, i.e `--no-version-check`) + 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/commands.lua b/lua/flutter-tools/commands.lua index 41e59c61..f83021df 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -278,17 +278,20 @@ 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 - local global_run_options = config.global_run_options - if global_run_options then - if type(global_run_options) == "string" then - vim.list_extend(args, vim.split(global_run_options, " ")) - elseif type(global_run_options) == "table" then - vim.list_extend(args, global_run_options) + 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 diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index 13861c17..78869e8c 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -23,13 +23,17 @@ local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.util ---@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 global_run_options? table|string Global options for flutter run (from `flutter run --verbose --help`) +---@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}} From 0a63971f9cb50e19ceb53231addbbbea7eecba54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Wed, 28 May 2025 21:48:35 +0300 Subject: [PATCH 3/3] fixup! fixup! feat: add possibility to set global run options --- lua/flutter-tools/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index 78869e8c..576d9b95 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -101,7 +101,7 @@ local config = { pre_run_callback = nil, root_patterns = { ".git", "pubspec.yaml" }, fvm = false, - global_run_options = nil, + default_run_args = nil, widget_guides = { enabled = false, debug = false,