Skip to content

Commit 2487351

Browse files
committed
feat(nvim): only present device runners for given platform only
1 parent cc06934 commit 2487351

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

lua/xbase/pickers.lua

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local maker = require("telescope.pickers.entry_display").create
99
local xbase = require "xbase"
1010
local watch = require "xbase.watch"
1111
local themes = require "telescope.themes"
12+
local util = require "xbase.util"
1213

1314
local mappings = function(_, _)
1415
action_set.select:replace(function(bufnr, direction)
@@ -55,40 +56,27 @@ end
5556

5657
local get_selections = function(picker)
5758
local commands = picker == "Watch" and { "Build", "Run" } or { picker }
58-
local root = vim.loop.cwd()
59-
local info = vim.g.xbase.projects[root]
60-
if info == nil then
61-
error "No info available"
62-
end
63-
64-
local targets = {}
59+
local project = vim.g.xbase.projects[vim.loop.cwd()]
6560

66-
-- TOOD(core): Support custom schemes
67-
for name, _ in pairs(info.targets) do
68-
targets[#targets + 1] = name
61+
if project == nil then
62+
error "No project info found"
6963
end
7064

71-
-- TOOD(core): Support custom project configurations
72-
local configurations = { "Debug", "Release" }
73-
74-
local devices = {}
65+
local targets = util.get_targets_runners(project)
7566

76-
if picker == "Run" or picker == "Watch" then
77-
-- TODO(nvim): Only include devices that is actually supported by target
78-
devices = vim.tbl_map(function(device)
79-
return {
80-
name = device.info.name,
81-
udid = device.info.udid,
82-
}
83-
end, vim.g.xbase.devices)
84-
end
67+
-- TOOD(core): Support custom project configurations and schemes
68+
local configurations = { "Debug", "Release" }
8569

8670
local results = {}
8771

8872
for _, command in ipairs(commands) do
89-
for _, target in ipairs(targets) do
73+
for _, target_info in ipairs(targets) do
74+
local target = target_info.name
75+
local devices = target_info.runners
76+
local include_devices = #devices ~= 0 and command == "Run"
77+
9078
for _, configuration in ipairs(configurations) do
91-
if #devices ~= 0 and command == "Run" then
79+
if include_devices then
9280
for _, device in ipairs(devices) do
9381
insert_entry(results, picker, command, target, configuration, device)
9482
end
@@ -129,7 +117,7 @@ local entry_maker = function(entry)
129117
ti(parts, { entry.kind, "TSNone" })
130118
end
131119

132-
ti(items, { width = 9 })
120+
ti(items, { width = 12 })
133121
entry.ordinal = string.format("%s %s", entry.ordinal, target)
134122
ti(parts, { target, "TSCharacter" })
135123

lua/xbase/types.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
---@field group string?
4141

4242
---@class Device
43+
---@field info DeviceInfo
44+
45+
---@class DeviceInfo
4346
---@field availabilityError string?,
4447
---@field dataPath string
4548
---@field deviceTypeIdentifier string

lua/xbase/util.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
local M = {}
2+
---@param platform Platform
3+
local get_runners = function(platform)
4+
local devices = {}
5+
6+
for _, device in ipairs(vim.g.xbase.devices) do
7+
if device.info.runtime_identifier:match(platform) then
8+
table.insert(devices, {
9+
name = device.info.name,
10+
udid = device.info.udid,
11+
})
12+
end
13+
end
14+
15+
return devices
16+
end
17+
18+
---Get Targets from project
19+
---To Support Multi Platform targets
20+
---@param project Project
21+
M.get_targets_runners = function(project)
22+
local targets = {}
23+
24+
for name, target in pairs(project.targets) do
25+
if #target.platform > 1 then
26+
for _, platform in ipairs(target.platform) do
27+
table.insert(targets, {
28+
name = string.format("%s_%s", name, platform),
29+
runners = get_runners(platform),
30+
})
31+
end
32+
else
33+
table.insert(targets, {
34+
name = name,
35+
runners = get_runners(target.platform[1]),
36+
})
37+
end
38+
end
39+
40+
return targets
41+
end
42+
43+
return M

0 commit comments

Comments
 (0)