Skip to content

Commit fc1492f

Browse files
committed
enh: build multiple projects at the same time
1 parent 021860c commit fc1492f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1583
-1518
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ install: clean
3131
install_debug: clean
3232
killall xbase xbase-sourcekit-helper || true
3333
mkdir $(XBASE_LOCAL_ROOT)
34-
cargo build -p xbase -p xbase-sourcekit-helper
34+
RUST_LOG=trace cargo build -p xbase -p xbase-sourcekit-helper
3535
ln -sf $(ROOT_DIR)/target/debug/xbase $(XBASE_LOCAL_ROOT)/xbase
3636
ln -sf $(ROOT_DIR)/target/debug/xbase-sourcekit-helper $(XBASE_LOCAL_ROOT)/xbase-sourcekit-helper
3737
echo "DONE"

dev.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ Here's an overview of the project architecture to help you contribute.
2323
- [Build Handler `build.rs`](./src/server/build.rs)
2424
- [Runners Handler `runners.rs`](./src/server/runners.rs)
2525
- [ProjectInfo Handler `project_info.rs`](./src/server/project_info.rs)
26-
- [Project Running Logic `runner/*`](./src/runner/)
27-
- [Project Watching Logic `watcher/*`](./src/wathcer/)
28-
- [Project Handling Logic `project/*`](./src/project/mod.rs)
26+
- [Project Runtime `runtime/*`](./src/runtime/mod.rs)
27+
- [Messages that can be processed by Project Runtime](./src/runtime/message.rs)
28+
- [Project Running `runner/*`](./src/runner/)
29+
- [Project Watching `watcher/*`](./src/watcher/)
30+
- [Project Support`project/*`](./src/project/mod.rs)
2931
- [XCodeGen Project Support `xcodegen.rs`](./src/project/xcodegen.rs)
3032
- [Tuist Project Support `tuist.rs`](./src/project/tuist.rs)
3133
- [Barebone Project Support `barebone.rs`](./src/project/barebone.rs)

lua/xbase/broadcast.lua

+28-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ local msg, tkind, tstatus = types.Message, types.TaskKind, types.TaskStatus
66
local config = require("xbase.config").values
77

88
local M = {}
9+
910
M.expect_second_run = false
11+
1012
local function task_set(args)
1113
M.has_task = true
1214
local running, _ = tkind:prefix(args.kind)
@@ -86,9 +88,15 @@ local function task_finish(args)
8688
end)
8789
end
8890

89-
function M.start(address)
91+
function M.start(root, address)
9092
local socket = socket:connect(address)
9193

94+
socket._socket:write(string.format("%s\n", vim.loop.os_getpid()), function(err)
95+
if err then
96+
print(socket._stream_error or err)
97+
end
98+
end)
99+
92100
socket:read_start(function(chunk)
93101
local chunk = vim.trim(chunk)
94102
for _, chunk in ipairs(vim.split(chunk, "\n")) do
@@ -109,7 +117,15 @@ function M.start(address)
109117
end
110118

111119
if msg.is_notify(type) then
112-
return notify(args.content, args.level)
120+
notify(args.content, args.level)
121+
if string.find(args.content, "Registered") ~= nil then
122+
vim.schedule(function()
123+
vim.defer_fn(function()
124+
print " "
125+
end, 2000)
126+
end)
127+
end
128+
return
113129
end
114130

115131
if msg.is_reload_lsp_server(type) then
@@ -124,6 +140,16 @@ function M.start(address)
124140
return logger.log(args.content, args.level)
125141
end
126142

143+
if msg.is_set_state(type) then
144+
local key, value = args.key, args.value
145+
if key == "runners" then
146+
require("xbase.state").runners = value
147+
elseif key == "projectInfo" then
148+
require("xbase.state").project_info[root] = value
149+
end
150+
return
151+
end
152+
127153
---@diagnostic disable-next-line: empty-block
128154
if msg.is_set_watching(type) then
129155
-- ()

lua/xbase/pickers.lua

+53-67
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ local insert_entry = function(acc, picker, command, target, configuration, watch
6363
acc[#acc + 1] = item
6464
end
6565

66-
local get_selections = function(project_info, picker)
66+
local get_selections = function(root, picker)
67+
local project_info = require("xbase.state").project_info[root]
6768
local commands = picker == C.Watch and { C.Build, C.Run } or { picker }
6869
local targets = project_info.targets
6970
local include_devices = picker == C.Run or picker == C.Watch
@@ -158,26 +159,15 @@ end
158159
local find = function(name, opts)
159160
opts = themes.get_dropdown(opts or {})
160161
opts.root = opts.root or vim.loop.cwd()
161-
local _find = function(opts)
162-
picker(opts, {
163-
prompt_title = opts.name,
164-
sorter = sorter {},
165-
finder = finder {
166-
results = get_selections(opts.project_info, name),
167-
entry_maker = entry_maker,
168-
},
169-
attach_mappings = mappings,
170-
}):find()
171-
end
172-
173-
if opts.project_info then
174-
_find(opts)
175-
else
176-
server.get_project_info(opts.root, function(project_info)
177-
opts.project_info = project_info
178-
_find(opts)
179-
end)
180-
end
162+
picker(opts, {
163+
prompt_title = opts.name,
164+
sorter = sorter {},
165+
finder = finder {
166+
results = get_selections(opts.root, name),
167+
entry_maker = entry_maker,
168+
},
169+
attach_mappings = mappings,
170+
}):find()
181171
end
182172

183173
M.watch = function(opts)
@@ -195,55 +185,51 @@ end
195185
M.actions = function(opts)
196186
opts = require("telescope.themes").get_dropdown(opts or {})
197187
opts.root = opts.root or vim.loop.cwd()
198-
server.get_project_info(opts.root, function(project_info)
199-
opts.project_info = project_info
200-
201-
picker(opts, {
202-
sorter = sorter {},
203-
prompt_title = "Pick Xbase Action Category",
204-
finder = finder {
205-
results = {
206-
{ value = C.Build },
207-
{ value = C.Watch },
208-
{ value = C.Run },
209-
},
210-
entry_maker = function(entry)
211-
entry.ordinal = entry.value
212-
entry.display = function(e)
213-
local opts = {}
214-
215-
opts.separator = " "
216-
opts.hl_chars = { ["|"] = "TelescopeResultsNumber" }
217-
opts.items = { { width = 40 } }
218-
219-
return maker(opts) { { e.value, "TelescopeResultsMethod" } }
220-
end
221-
222-
return entry
223-
end,
188+
picker(opts, {
189+
sorter = sorter {},
190+
prompt_title = "Pick Xbase Action Category",
191+
finder = finder {
192+
results = {
193+
{ value = C.Build },
194+
{ value = C.Watch },
195+
{ value = C.Run },
224196
},
225-
attach_mappings = function(_, _)
226-
a.select_default:replace(function(bufnr)
227-
local selected = s.get_selected_entry()
228-
229-
a.close(bufnr)
230-
if not selected then
231-
print "No selection"
232-
return
233-
end
197+
entry_maker = function(entry)
198+
entry.ordinal = entry.value
199+
entry.display = function(e)
200+
local opts = {}
234201

235-
if selected.value == C.Watch then
236-
M.watch(opts)
237-
elseif selected.value == C.Build then
238-
M.build(opts)
239-
elseif selected.value == C.Run then
240-
M.run(opts)
241-
end
242-
end)
243-
return true
202+
opts.separator = " "
203+
opts.hl_chars = { ["|"] = "TelescopeResultsNumber" }
204+
opts.items = { { width = 40 } }
205+
206+
return maker(opts) { { e.value, "TelescopeResultsMethod" } }
207+
end
208+
209+
return entry
244210
end,
245-
}):find()
246-
end)
211+
},
212+
attach_mappings = function(_, _)
213+
a.select_default:replace(function(bufnr)
214+
local selected = s.get_selected_entry()
215+
216+
a.close(bufnr)
217+
if not selected then
218+
print "No selection"
219+
return
220+
end
221+
222+
if selected.value == C.Watch then
223+
M.watch(opts)
224+
elseif selected.value == C.Build then
225+
M.build(opts)
226+
elseif selected.value == C.Run then
227+
M.run(opts)
228+
end
229+
end)
230+
return true
231+
end,
232+
}):find()
247233
end
248234

249235
return M

lua/xbase/server.lua

+7-34
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local notify = require "xbase.notify"
55
local broadcast = require "xbase.broadcast"
66
local constants = require "xbase.constants"
77
local uv = vim.loop
8+
local id = vim.loop.os_getpid()
89

910
---@class XBase
1011
local M = {
@@ -87,47 +88,19 @@ end
8788
---@return boolean
8889
function M.register(root)
8990
validate { root = { root, "string", false } }
91+
if M.roots[root] then
92+
return
93+
end
9094

9195
require("xbase.logger").setup()
92-
local req = {
93-
method = "register",
94-
args = {
95-
root = root,
96-
},
97-
}
9896

97+
local req = { method = "register", args = { id = id, root = root } }
9998
M.request(req, function(broadcast_address)
100-
notify.info(("[%s] Connected "):format(util.project_name(root)))
101-
vim.schedule(function()
102-
--- Clear statusline
103-
vim.defer_fn(function()
104-
print " "
105-
end, 2000)
106-
end)
107-
108-
broadcast.start(broadcast_address)
109-
110-
M.roots[#M.roots + 1] = root
111-
112-
-- Fill state with available runners
113-
if not require("xbase.state").runners then
114-
M.request({ method = "get_runners" }, function(runners)
115-
require("xbase.state").runners = runners
116-
end)
117-
end
99+
broadcast.start(root, broadcast_address)
100+
M.roots[root] = true
118101
end)
119102
end
120103

121-
---Get Project information
122-
function M.get_project_info(root, on_response)
123-
M.request({
124-
method = "get_project_info",
125-
args = {
126-
root = root,
127-
},
128-
}, on_response)
129-
end
130-
131104
---Drop a given root or drop all tracked roots if root is nil
132105
---@param root string
133106
function M.drop(root)

lua/xbase/state.lua

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ local M = {
22
--- Devices index by platform
33
---@type table<string, string>
44
runners = nil,
5+
---@type table<string, table>
6+
project_info = {},
57
}
68

79
return M

lua/xbase/types.lua

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ M.Message = {
6363
is_set_watching = function(ty)
6464
return ty == "SetWatching"
6565
end,
66+
is_set_state = function(ty)
67+
return ty == "SetState"
68+
end,
6669
}
6770

6871
return M

src/bin/gen_bindings.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ fn gen_ts_types_file(path: PathBuf) {
3030
options.root_namespace = None;
3131
options.header = None;
3232

33-
type Requests = (
34-
Request,
35-
RunRequest,
36-
RegisterRequest,
37-
DropRequest,
38-
GetProjectInfoRequest,
39-
);
33+
type Requests = (Request, RunRequest, RegisterRequest, DropRequest);
4034
type Responses = (Response, ServerError);
4135
type Transports = (
4236
ProjectInfo,
@@ -45,6 +39,7 @@ fn gen_ts_types_file(path: PathBuf) {
4539
Operation,
4640
BuildSettings,
4741
DeviceLookup,
42+
State,
4843
);
4944
type Messages = (Message, ContentLevel, TaskKind, TaskStatus);
5045
type API = (Messages, Transports, Responses, Requests);

0 commit comments

Comments
 (0)