Skip to content

Commit 0e41b62

Browse files
committed
feat(nvim): log buffer auto-scroll and keep focus
1 parent 652ef19 commit 0e41b62

File tree

4 files changed

+51
-55
lines changed

4 files changed

+51
-55
lines changed

lua/xcodebase/init.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ M.build = function(opts)
4444
}))
4545
end
4646

47-
M.projects = {}
48-
4947
M.project_info = function(root)
5048
M.projects[root] = nil
5149
lib.project_info(pid, root)
@@ -67,4 +65,18 @@ M.setup = function(opts)
6765
M.try_register(root, opts)
6866
end
6967

68+
---@class XcodeTarget
69+
---@field type string
70+
---@field platform string
71+
---@field sources string[]
72+
73+
---@class XcodeProject
74+
---@field name string @Project name
75+
---@field targets string @Project name
76+
---@field root string @Project root
77+
78+
---Holds project informations
79+
---@type table<string, XcodeProject>
80+
M.projects = {}
81+
7082
return M

lua/xcodebase/state.lua

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

src/daemon/nvim.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,18 @@ pub struct Nvim {
1616
pub log_bufnr: i64,
1717
}
1818

19-
#[derive(strum::EnumString)]
20-
#[strum(ascii_case_insensitive)]
21-
pub enum WindowType {
22-
Float,
23-
Vertical,
24-
Horizontal,
25-
}
26-
27-
impl WindowType {
28-
fn to_nvim_command(&self, bufnr: i64) -> String {
29-
match self {
30-
// TOOD: support build log float
31-
WindowType::Float => format!("sbuffer {bufnr}"),
32-
WindowType::Vertical => format!("vert sbuffer {bufnr}"),
33-
WindowType::Horizontal => format!("sbuffer {bufnr}"),
34-
}
35-
}
36-
}
37-
3819
impl Nvim {
3920
pub async fn new<P: AsRef<Path> + Clone>(address: P) -> Result<Self> {
4021
let (neovim, handler) = create::tokio::new_path(address, Dummy::new()).await?;
41-
let buffer = neovim.create_buf(false, true).await?;
22+
let buf = neovim.create_buf(false, true).await?;
4223

43-
buffer.set_name("[Xcodebase Logs]").await?;
44-
buffer
45-
.set_option("filetype", "xcodebuildlog".into())
46-
.await?;
24+
buf.set_name("[Xcodebase Logs]").await?;
25+
buf.set_option("filetype", "xcodebuildlog".into()).await?;
4726

4827
Ok(Self {
4928
nvim: neovim,
5029
handler,
51-
log_bufnr: buffer.get_number().await?,
30+
log_bufnr: buf.get_number().await?,
5231
})
5332
}
5433

@@ -72,19 +51,18 @@ impl Nvim {
7251
clear: bool,
7352
) -> Result<()> {
7453
let title = format!("[{title}] ------------------------------------------------------");
75-
let buffer = Buffer::new(self.log_bufnr.into(), self.nvim.clone());
54+
let buf = Buffer::new(self.log_bufnr.into(), self.nvim.clone());
7655

7756
if clear {
78-
buffer.set_lines(0, -1, false, vec![]).await?;
57+
buf.set_lines(0, -1, false, vec![]).await?;
7958
}
8059

81-
let mut c = match buffer.line_count().await? {
60+
let mut c = match buf.line_count().await? {
8261
1 => 0,
8362
count => count,
8463
};
8564

86-
// TODO(nvim): build log correct width
87-
// TODO(nvim): build log auto scroll
65+
// TODO(nvim): build log correct height
8866
let command = match self.get_window_direction(direction).await {
8967
Ok(open_command) => open_command,
9068
Err(e) => {
@@ -94,15 +72,19 @@ impl Nvim {
9472
};
9573

9674
self.exec(&command, false).await?;
97-
self.exec("setlocal nonumber norelativenumber", false)
98-
.await?;
75+
self.exec("setl nu nornu so=9", false).await?;
76+
77+
let win = self.get_current_win().await?;
9978

100-
buffer.set_lines(c, c + 1, false, vec![title]).await?;
79+
self.exec("wincmd w", false).await?;
80+
81+
buf.set_lines(c, c + 1, false, vec![title]).await?;
10182
c += 1;
10283

10384
while let Some(line) = stream.next().await {
104-
buffer.set_lines(c, c + 1, false, vec![line]).await?;
105-
c += 1
85+
buf.set_lines(c, c + 1, false, vec![line]).await?;
86+
c += 1;
87+
win.set_cursor((c, 0)).await?;
10688
}
10789

10890
Ok(())
@@ -140,6 +122,25 @@ impl Nvim {
140122
}
141123
}
142124

125+
#[derive(strum::EnumString)]
126+
#[strum(ascii_case_insensitive)]
127+
pub enum WindowType {
128+
Float,
129+
Vertical,
130+
Horizontal,
131+
}
132+
133+
impl WindowType {
134+
fn to_nvim_command(&self, bufnr: i64) -> String {
135+
match self {
136+
// TOOD: support build log float
137+
WindowType::Float => format!("sbuffer {bufnr}"),
138+
WindowType::Vertical => format!("vert sbuffer {bufnr}"),
139+
WindowType::Horizontal => format!("sbuffer {bufnr}"),
140+
}
141+
}
142+
}
143+
143144
impl std::fmt::Debug for Nvim {
144145
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
145146
f.debug_tuple("Nvim").finish()

src/daemon/state/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Project {
122122
#[cfg(feature = "daemon")]
123123
pub fn nvim_update_state_script(&self) -> anyhow::Result<String> {
124124
Ok(format!(
125-
"require'xcodebase.state'.projects['{}'] = vim.json.decode([[{}]])",
125+
"require'xcodebase'.projects['{}'] = vim.json.decode([[{}]])",
126126
self.root.display(),
127127
serde_json::to_string(&self)?
128128
))

0 commit comments

Comments
 (0)