Skip to content

Commit fcc7b5b

Browse files
authored
Merge branch 'akinsho:main' into main
2 parents 561bf0e + 271eec9 commit fcc7b5b

10 files changed

+296
-52
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## [1.7.0](https://github.com/akinsho/flutter-tools.nvim/compare/v1.6.0...v1.7.0) (2024-01-03)
4+
5+
6+
### Features
7+
8+
* add option to configure flutter mode via config ([#314](https://github.com/akinsho/flutter-tools.nvim/issues/314)) ([69466cc](https://github.com/akinsho/flutter-tools.nvim/commit/69466cc5ce3743bfb08ae07b0c415d7e549437d4))
9+
* add performance_overlay, repaint_rainbow and slow_animations commands ([deb4fa8](https://github.com/akinsho/flutter-tools.nvim/commit/deb4fa80812157e6c6dadaa25dfe0cfa42950e5c))
10+
* add web port param to config ([#320](https://github.com/akinsho/flutter-tools.nvim/issues/320)) ([b13d46b](https://github.com/akinsho/flutter-tools.nvim/commit/b13d46b3a06a9e2c414d0020c0cb7cf0dd51d426))
11+
12+
## [1.6.0](https://github.com/akinsho/flutter-tools.nvim/compare/v1.5.1...v1.6.0) (2023-12-18)
13+
14+
15+
### Features
16+
17+
* **commands:** add install/uninstall commands to menu ([#315](https://github.com/akinsho/flutter-tools.nvim/issues/315)) ([cd73844](https://github.com/akinsho/flutter-tools.nvim/commit/cd738444c27d3a34f03b6d43df08c814e8232fb7))
18+
19+
20+
### Bug Fixes
21+
22+
* **commands:** set current device while running project ([045fa0f](https://github.com/akinsho/flutter-tools.nvim/commit/045fa0f56234943464a06666183cd1a3089aeca2))
23+
324
## [1.5.1](https://github.com/akinsho/flutter-tools.nvim/compare/v1.5.0...v1.5.1) (2023-10-04)
425

526

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,12 @@ require('flutter-tools').setup_project({
319319
{
320320
name = 'Web',
321321
device = 'chrome',
322-
flavor = 'WebApp'
322+
flavor = 'WebApp',
323+
web_port = 4000
324+
},
325+
{
326+
name = 'Profile',
327+
flutter_mode = 'profile', -- possible values: `debug`, `profile` or `release`, defaults to `debug`
323328
}
324329
})
325330
```

doc/flutter-tools.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*flutter-tools.txt* For Neovim >= 0.8.0 Last change: 2023 October 04
1+
*flutter-tools.txt* For Neovim >= 0.8.0 Last change: 2024 January 22
22

33
==============================================================================
44
Table of Contents *flutter-tools-table-of-contents*
@@ -358,7 +358,12 @@ _conceptually_ to vscode’s `launch.json` file.
358358
{
359359
name = 'Web',
360360
device = 'chrome',
361-
flavor = 'WebApp'
361+
flavor = 'WebApp',
362+
web_port = 4000
363+
},
364+
{
365+
name = 'Profile',
366+
flutter_mode = 'profile', -- possible values: `debug`, `profile` or `release`, defaults to `debug`
362367
}
363368
})
364369
<

lua/flutter-tools/commands.lua

+102-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local lazy = require("flutter-tools.lazy")
2-
local Job = require("plenary.job")
2+
local Job = require("plenary.job") ---@module "plenary.job"
33
local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
44
local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.utils"
55
local devices = lazy.require("flutter-tools.devices") ---@module "flutter-tools.devices"
@@ -133,10 +133,13 @@ local function get_run_args(opts, conf)
133133
local target = conf and conf.target
134134
local dart_defines = conf and conf.dart_define
135135
local dart_define_from_file = conf and conf.dart_define_from_file
136+
local flutter_mode = conf and conf.flutter_mode
137+
local web_port = conf and conf.web_port
136138
local dev_url = dev_tools.get_url()
137139

138140
if not use_debugger_runner() then vim.list_extend(args, { "run" }) end
139141
if not cmd_args and device then vim.list_extend(args, { "-d", device }) end
142+
if web_port then vim.list_extend(args, { "--web-port", web_port }) end
140143
if cmd_args then vim.list_extend(args, cmd_args) end
141144
if flavor then vim.list_extend(args, { "--flavor", flavor }) end
142145
if target then vim.list_extend(args, { "--target", target }) end
@@ -148,16 +151,33 @@ local function get_run_args(opts, conf)
148151
vim.list_extend(args, { "--dart-define", ("%s=%s"):format(key, value) })
149152
end
150153
end
154+
if flutter_mode then
155+
if flutter_mode == "profile" then
156+
vim.list_extend(args, { "--profile" })
157+
elseif flutter_mode == "release" then
158+
vim.list_extend(args, { "--release" })
159+
end -- else default to debug
160+
end
151161
if dev_url then vim.list_extend(args, { "--devtools-server-address", dev_url }) end
152162
return args
153163
end
154164

165+
--- @param args string[]
166+
--- @return Device?
167+
local function get_device_from_args(args)
168+
for i = 1, #args - 1 do
169+
if args[i] == "-d" then return { id = args[i + 1] } end
170+
end
171+
end
172+
155173
---@param opts RunOpts
156174
---@param project_conf flutter.ProjectConfig?
157175
local function run(opts, project_conf)
158176
opts = opts or {}
159177
executable.get(function(paths)
160178
local args = opts.cli_args or get_run_args(opts, project_conf)
179+
180+
current_device = opts.device or get_device_from_args(args)
161181
ui.notify("Starting flutter project...")
162182
runner = use_debugger_runner() and debugger_runner or job_runner
163183
runner:run(paths, args, lsp.get_lsp_root_dir(), on_run_data, on_run_exit)
@@ -206,6 +226,15 @@ end
206226
---@param quiet boolean?
207227
function M.visual_debug(quiet) send("visual_debug", quiet) end
208228

229+
---@param quiet boolean?
230+
function M.performance_overlay(quiet) send("performance_overlay", quiet) end
231+
232+
---@param quiet boolean?
233+
function M.repaint_rainbow(quiet) send("repaint_rainbow", quiet) end
234+
235+
---@param quiet boolean?
236+
function M.slow_animations(quiet) send("slow_animations", quiet) end
237+
209238
---@param quiet boolean?
210239
function M.detach(quiet) send("detach", quiet) end
211240

@@ -379,6 +408,78 @@ function M.fvm_use(sdk_name)
379408
end
380409
end
381410

411+
---@param args string[]
412+
---@param project_conf flutter.ProjectConfig?
413+
---@return string[]
414+
local function set_args_from_project_config(args, project_conf)
415+
local flavor = project_conf and project_conf.flavor
416+
local device = project_conf and project_conf.device
417+
if flavor then vim.list_extend(args, { "--flavor", flavor }) end
418+
if device then vim.list_extend(args, { "-d", device }) end
419+
end
420+
421+
---@type Job?
422+
local install_job = nil
423+
424+
function M.install()
425+
if not install_job then
426+
select_project_config(function(project_conf)
427+
local args = { "install" }
428+
set_args_from_project_config(args, project_conf)
429+
ui.notify("Installing the app...")
430+
executable.flutter(function(cmd)
431+
local notify_timeout = 10000
432+
install_job = Job:new({
433+
command = cmd,
434+
args = args,
435+
-- stylua: ignore
436+
cwd = lsp.get_lsp_root_dir() --[[@as string]],
437+
})
438+
install_job:after_success(vim.schedule_wrap(function(j)
439+
ui.notify(utils.join(j:result()), nil, { timeout = notify_timeout })
440+
install_job = nil
441+
end))
442+
install_job:after_failure(vim.schedule_wrap(function(j)
443+
ui.notify(utils.join(j:result()), nil, { timeout = notify_timeout })
444+
install_job = nil
445+
end))
446+
install_job:start()
447+
end)
448+
end)
449+
end
450+
end
451+
452+
---@type Job?
453+
local uninstall_job = nil
454+
455+
function M.uninstall()
456+
if not uninstall_job then
457+
select_project_config(function(project_conf)
458+
local args = { "install", "--uninstall-only" }
459+
set_args_from_project_config(args, project_conf)
460+
ui.notify("Uninstalling the app...")
461+
executable.flutter(function(cmd)
462+
local notify_timeout = 10000
463+
uninstall_job = Job:new({
464+
command = cmd,
465+
args = args,
466+
-- stylua: ignore
467+
cwd = lsp.get_lsp_root_dir() --[[@as string]],
468+
})
469+
uninstall_job:after_success(vim.schedule_wrap(function(j)
470+
ui.notify(utils.join(j:result()), nil, { timeout = notify_timeout })
471+
uninstall_job = nil
472+
end))
473+
uninstall_job:after_failure(vim.schedule_wrap(function(j)
474+
ui.notify(utils.join(j:result()), nil, { timeout = notify_timeout })
475+
uninstall_job = nil
476+
end))
477+
uninstall_job:start()
478+
end)
479+
end)
480+
end
481+
end
482+
382483
if __TEST then
383484
M.__run = run
384485
M.__get_run_args = get_run_args

lua/flutter-tools/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
99
---@field target string
1010
---@field dart_define {[string]: string}
1111
---@field dart_define_from_file string
12+
---@field flutter_mode string
13+
---@field web_port number
1214

1315
local M = {}
1416

lua/flutter-tools/dap.lua

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ end
1111

1212
local M = {}
1313

14+
local function has_flutter_dependency_in_pubspec()
15+
local pubspec = vim.fn.glob("pubspec.yaml")
16+
if pubspec == "" then return false end
17+
local pubspec_content = vim.fn.readfile(pubspec)
18+
local joined_content = table.concat(pubspec_content, "\n")
19+
20+
local flutter_dependency = string.match(joined_content, "flutter:\n[%s\t]*sdk:[%s\t]*flutter")
21+
return flutter_dependency ~= nil
22+
end
23+
1424
function M.setup(config)
1525
local opts = config.debugger
1626
require("flutter-tools.executable").get(function(paths)
17-
local root_patterns = { ".git", "pubspec.yaml" }
18-
local current_dir = vim.fn.expand("%:p:h")
19-
local root_dir = path.find_root(root_patterns, current_dir) or current_dir
20-
local is_flutter_project = vim.loop.fs_stat(path.join(root_dir, ".metadata"))
27+
local is_flutter_project = has_flutter_dependency_in_pubspec()
2128

2229
if is_flutter_project then
2330
dap.adapters.dart = {

0 commit comments

Comments
 (0)