Skip to content

Commit ccada27

Browse files
committed
ref(build): include watch option instead of special request
1 parent c3df803 commit ccada27

File tree

9 files changed

+184
-255
lines changed

9 files changed

+184
-255
lines changed

lua/xbase/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ fn libxbase(l: &Lua) -> LuaResult<LuaTable> {
1818
("ensure", l.create_function(ensure)?),
1919
("register", fun!(Register, l)),
2020
("drop", fun!(Drop, l)),
21-
("build", fun!(Build, l)),
21+
("build", fun!(BuildRequest, l)),
2222
("run", fun!(RunRequest, l)),
23-
("watch_target", fun!(WatchTarget, l)),
2423
])
2524
}
2625

lua/xbase/pickers.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ local picker = require("telescope.pickers").new
77
local sorter = require("telescope.config").values.generic_sorter
88
local maker = require("telescope.pickers.entry_display").create
99
local xbase = require "xbase"
10-
local watch = require "xbase.watch"
1110
local themes = require "telescope.themes"
1211
local util = require "xbase.util"
1312

@@ -19,8 +18,6 @@ local mappings = function(_, _)
1918

2019
if entry.command == "Build" then
2120
xbase.build(entry)
22-
elseif entry.command == "Watch" then
23-
xbase.watch(entry)
2421
elseif entry.command == "Run" then
2522
xbase.run(entry)
2623
end
@@ -40,13 +37,11 @@ local insert_entry = function(acc, picker, command, target, configuration, devic
4037
end
4138

4239
if picker == "Watch" then
43-
item.command = "Watch"
44-
45-
if watch.is_watching(item.config, command) then
40+
if util.is_watching(item.config, command) then
4641
item.ops = "Stop"
4742
item.kind = command
4843
else
49-
item.ops = "Start"
44+
item.ops = "Watch"
5045
item.kind = command
5146
end
5247
end

lua/xbase/util.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local config = require("xbase.config").values
12
local M = {}
23
---@param platform Platform
34
local get_runners = function(platform)
@@ -43,4 +44,55 @@ M.get_targets_runners = function(project)
4344
return targets
4445
end
4546

47+
M.is_watching = function(config, command)
48+
local root = vim.loop.cwd()
49+
local watching = vim.g.xbase.watcher[root]
50+
local key = string.format("%s:%s:xcodebuild -configuration %s", root, command, config.configuration)
51+
52+
if config.sysroot then
53+
key = key .. " -sysroot " .. config.sysroot
54+
end
55+
56+
if config.scheme then
57+
key = key .. " -scheme " .. config.scheme
58+
end
59+
60+
key = key .. " -target " .. config.target
61+
62+
return watching[key] ~= nil
63+
end
64+
65+
M.feline_provider = function()
66+
return {
67+
provider = function(_)
68+
icon = {}
69+
--- TODO(nvim): only show build status in xcode supported files?
70+
local config = config.statusline
71+
local status = vim.g.xbase_watch_build_status
72+
73+
if status == "running" then
74+
icon.str = config.running.icon
75+
icon.hl = { fg = config.running.color }
76+
elseif status == "success" then
77+
icon.str = config.success.icon
78+
icon.hl = { fg = config.success.color }
79+
elseif status == "failure" then
80+
icon.str = config.failure.icon
81+
icon.hl = { fg = config.failure.color }
82+
else
83+
icon.str = " "
84+
end
85+
86+
if icon.str == " " then
87+
return " ", icon
88+
else
89+
icon.str = " [" .. icon.str .. " xcode]"
90+
return " ", icon
91+
end
92+
end,
93+
94+
hl = {},
95+
}
96+
end
97+
4698
return M

lua/xbase/watch.lua

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/daemon/message.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,22 @@ impl Request {
2020
/// Daemon Message
2121
#[derive(Debug, Serialize, Deserialize)]
2222
pub enum Message {
23-
Build(Build),
23+
BuildRequest(BuildRequest),
2424
RunRequest(RunRequest),
2525
Register(Register),
2626
Drop(Drop),
2727
RenameFile(RenameFile),
28-
WatchTarget(WatchTarget),
2928
}
3029

3130
#[cfg(feature = "daemon")]
3231
impl Message {
3332
pub async fn handle(self) -> crate::Result<()> {
3433
match self {
35-
Self::Build(c) => Handler::handle(c).await,
34+
Self::BuildRequest(c) => Handler::handle(c).await,
3635
Self::RunRequest(c) => Handler::handle(c).await,
3736
Self::RenameFile(c) => Handler::handle(c).await,
3837
Self::Register(c) => Handler::handle(c).await,
3938
Self::Drop(c) => Handler::handle(c).await,
40-
Self::WatchTarget(c) => Handler::handle(c).await,
4139
}
4240
}
4341
}

src/daemon/requests.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ mod drop;
33
mod register;
44
mod rename_file;
55
mod run;
6-
mod watch_target;
76

87
pub use build::*;
98
pub use drop::*;
109
pub use register::*;
1110
pub use rename_file::*;
1211
pub use run::*;
13-
pub use watch_target::*;
1412

1513
#[cfg(feature = "mlua")]
1614
use crate::util::mlua::LuaExtension;
@@ -44,9 +42,58 @@ macro_rules! convertable {
4442
}
4543
};
4644
}
47-
convertable!(Build);
45+
convertable!(BuildRequest);
4846
convertable!(RunRequest);
4947
convertable!(Register);
5048
convertable!(RenameFile);
5149
convertable!(Drop);
52-
convertable!(WatchTarget);
50+
51+
#[derive(
52+
Default, Clone, Debug, serde::Serialize, serde::Deserialize, strum::Display, strum::EnumString,
53+
)]
54+
55+
pub enum RequestOps {
56+
Watch,
57+
Stop,
58+
#[default]
59+
Once,
60+
}
61+
62+
impl RequestOps {
63+
/// Returns `true` if the request kind is [`Watch`].
64+
///
65+
/// [`Watch`]: RequestKind::Watch
66+
#[must_use]
67+
pub fn is_watch(&self) -> bool {
68+
matches!(self, Self::Watch)
69+
}
70+
71+
/// Returns `true` if the request kind is [`WatchStop`].
72+
///
73+
/// [`WatchStop`]: RequestKind::WatchStop
74+
#[must_use]
75+
pub fn is_stop(&self) -> bool {
76+
matches!(self, Self::Stop)
77+
}
78+
79+
/// Returns `true` if the request kind is [`Once`].
80+
///
81+
/// [`Once`]: RequestKind::Once
82+
#[must_use]
83+
pub fn is_once(&self) -> bool {
84+
matches!(self, Self::Once)
85+
}
86+
}
87+
88+
#[cfg(feature = "lua")]
89+
impl<'a> FromLua<'a> for RequestOps {
90+
fn from_lua(lua_value: LuaValue<'a>, _lua: &'a Lua) -> LuaResult<Self> {
91+
use std::str::FromStr;
92+
if let LuaValue::String(value) = lua_value {
93+
let value = value.to_string_lossy();
94+
Self::from_str(&*value).to_lua_err()
95+
} else {
96+
Ok(Self::default())
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)