Skip to content

Commit d1022db

Browse files
authored
feat: add possibility to set default run args (#471)
1 parent d5bb1dc commit d1022db

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ require("flutter-tools").setup {
240240
flutter_lookup_cmd = nil, -- example "dirname $(which flutter)" or "asdf where flutter"
241241
root_patterns = { ".git", "pubspec.yaml" }, -- patterns to find the root of your flutter project
242242
fvm = false, -- takes priority over path, uses <workspace>/.fvm/flutter_sdk if enabled
243+
default_run_args= nil, -- Default options for run command (i.e `{ flutter = "--no-version-check" }`). Configured separately for `dart run` and `flutter run`.
243244
widget_guides = {
244245
enabled = false,
245246
},

lua/flutter-tools.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ local function setup_autocommands()
118118
})
119119
end
120120

121-
---@param opts flutter.ProjectConfig
121+
---@param opts flutter.ProjectConfig | flutter.ProjectConfig[] Project-specific configuration
122122
function M.setup_project(opts)
123123
config.setup_project(opts)
124124
start()
125125
end
126126

127127
---Entry point for this plugin
128-
---@param user_config table
128+
---@param user_config flutter.Config Configuration options for flutter-tools
129129
function M.setup(user_config)
130130
config.set(user_config)
131131
setup_autocommands()

lua/flutter-tools/commands.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,21 @@ local function run(opts, project_conf, launch_config)
280280
-- To determinate if the project is a flutter project we need to check if the pubspec.yaml
281281
-- file has a flutter dependency in it. We need to get cwd first to pick correct pubspec.yaml file.
282282
local is_flutter_project = has_flutter_dependency_in_pubspec(cwd)
283+
local default_run_args = config.default_run_args
284+
local run_args
283285
if is_flutter_project then
284286
ui.notify("Starting flutter project...")
287+
if default_run_args then run_args = default_run_args.flutter end
285288
else
286289
ui.notify("Starting dart project...")
290+
if default_run_args then run_args = default_run_args.dart end
291+
end
292+
if run_args then
293+
if type(run_args) == "string" then
294+
vim.list_extend(args, vim.split(run_args, " "))
295+
elseif type(run_args) == "table" then
296+
vim.list_extend(args, run_args)
297+
end
287298
end
288299
runner = use_debugger_runner(opts.force_debug) and debugger_runner or job_runner
289300
runner:run(

lua/flutter-tools/config.lua

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.util
1515
---@field web_port? string
1616
---@field cwd? string full path of current working directory, defaults to LSP root
1717
---@field additional_args? string[] additional arguments to pass to the flutter run command
18+
---
19+
---@class flutter.DevLogOpts
20+
---@field filter? fun(data: string): boolean
21+
---@field enabled? boolean
22+
---@field notify_errors? boolean
23+
---@field focus_on_open? boolean
24+
---@field open_cmd? string
25+
---
26+
---@class flutter.RunArgsOpts
27+
---@field flutter? table|string -- options applied to `flutter run` command
28+
---@field dart? table|string -- options appliert to `dart run` command
29+
---
30+
---@class flutter.Config
31+
---@field flutter_path? string Path to the Flutter SDK
32+
---@field flutter_lookup_cmd? string Command to find Flutter SDK
33+
---@field pre_run_callback? fun(opts: table) Function called before running Flutter
34+
---@field root_patterns? string[] Patterns to find project root
35+
---@field fvm? boolean Whether to use FVM (Flutter Version Manager)
36+
---@field default_run_args? flutter.RunArgsOpts Default options for run command
37+
---@field widget_guides? {enabled: boolean, debug: boolean}
38+
---@field ui? {border: string}
39+
---@field decorations? {statusline: {app_version: boolean, device: boolean, project_config: boolean}}
40+
---@field debugger? {enabled: boolean, exception_breakpoints?: table, evaluate_to_string_in_debug_views?: boolean, register_configurations?: fun(paths: table)}
41+
---@field closing_tags? {highlight: string, prefix: string, priority: number, enabled: boolean}
42+
---@field lsp? {debug?: number, color?: {enabled: boolean, background: boolean, foreground: boolean, virtual_text: boolean, virtual_text_str: string, background_color?: string}, settings?: table}
43+
---@field outline? {auto_open: boolean, open_cmd?: string}
44+
---@field dev_log? flutter.DevLogOpts
45+
---@field dev_tools? {autostart: boolean, auto_open_browser: boolean}
1846

1947
local M = {}
2048

@@ -67,13 +95,13 @@ M.debug_levels = {
6795
DEBUG = 1,
6896
WARN = 2,
6997
}
70-
7198
local config = {
7299
flutter_path = nil,
73100
flutter_lookup_cmd = get_default_lookup(),
74101
pre_run_callback = nil,
75102
root_patterns = { ".git", "pubspec.yaml" },
76103
fvm = false,
104+
default_run_args = nil,
77105
widget_guides = {
78106
enabled = false,
79107
debug = false,

lua/flutter-tools/ui.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ local entry_type = {
1010
---@generic T
1111
---@alias SelectionEntry {text: string, type: EntryType, data: T}
1212

13+
---@class flutter.WindowOpts
14+
---@field open_cmd? string Command to open the window
15+
---@field filename? string Name to give the buffer
16+
---@field filetype string Filetype to set for the buffer
17+
---@field focus_on_open? boolean Whether to focus the window after opening
18+
1319
---@enum
1420
local M = {
1521
ERROR = vim.log.levels.ERROR,
@@ -129,7 +135,7 @@ function M.select(opts)
129135
end
130136

131137
---Create a split window
132-
---@param opts table
138+
---@param opts flutter.WindowOpts
133139
---@param on_open fun(buf: integer, win: integer)
134140
---@return nil
135141
function M.open_win(opts, on_open)

0 commit comments

Comments
 (0)