Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <workspace>/.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,
},
Expand Down
4 changes: 2 additions & 2 deletions lua/flutter-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions lua/flutter-tools/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 29 additions & 1 deletion lua/flutter-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion lua/flutter-tools/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading