Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions core/gui/src/editor/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ impl Element for CanvasElement {
let inner = self.inner.read(cx);
let solved_cell = &inner.state.read(cx).solved_cell.read(cx);
let selected_rect = solved_cell.as_ref().and_then(|cell| cell.selected_rect);
let layers = &inner.state.read(cx).layers.read(cx);
let state = inner.state.read(cx);
let layers = state.layers.read(cx);

let mut rects = Vec::new();
let mut scope_rects = Vec::new();
Expand All @@ -180,14 +181,15 @@ impl Element for CanvasElement {
solved_cell.selected_scope,
TransformationMatrix::identity(),
(0., 0.),
0,
)]);
while let Some((curr_address @ ScopeAddress { scope, cell }, mat, ofs)) =
while let Some((curr_address @ ScopeAddress { scope, cell }, mat, ofs, depth)) =
queue.pop_front()
{
let cell_info = &solved_cell.output.cells[&cell];
let scope_info = &cell_info.scopes[&scope];
let scope_state = &solved_cell.state[&curr_address];
if !scope_state.visible {
if depth >= state.hierarchy_depth || !scope_state.visible {
if let Some(bbox) = &scope_state.bbox {
let p0p = ifmatvec(mat, (bbox.x0, bbox.y0));
let p1p = ifmatvec(mat, (bbox.x1, bbox.y1));
Expand Down Expand Up @@ -260,7 +262,7 @@ impl Element for CanvasElement {
}
continue;
}
queue.push_back((inst_address, new_mat, new_ofs));
queue.push_back((inst_address, new_mat, new_ofs, depth + 1));
}
_ => {}
}
Expand All @@ -270,7 +272,7 @@ impl Element for CanvasElement {
scope: *child,
cell,
};
queue.push_back((scope_address, mat, ofs));
queue.push_back((scope_address, mat, ofs, depth + 1));
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/gui/src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct CompileOutputState {
}

pub struct EditorState {
pub hierarchy_depth: usize,
pub solved_cell: Entity<Option<CompileOutputState>>,
pub layers: Entity<IndexMap<SharedString, LayerState>>,
pub lsp_client: SyncGuiToLspClient,
Expand Down Expand Up @@ -212,6 +213,7 @@ impl Editor {
cx.observe(&layers, |_, _, cx| cx.notify()),
];
EditorState {
hierarchy_depth: usize::MAX,
solved_cell,
layers,
subscriptions,
Expand Down
17 changes: 17 additions & 0 deletions core/gui/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,21 @@ impl LspToGui for GuiServer {
.await
.unwrap();
}
async fn set(mut self, _: tarpc::context::Context, key: String, value: String) -> () {
match key.as_str() {
"hierarchyDepth" => {
self.to_exec
.send(Box::new(move |state, cx| {
// TODO: Need better way to specify infinite hierarchy depth.
state.hierarchy_depth = value.parse().unwrap_or(usize::MAX);
cx.notify();
}))
.await
.unwrap();
}
_ => {
// TODO: handle errors.
}
}
}
}
19 changes: 19 additions & 0 deletions core/lsp-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ struct OpenCellParams {
cell: String,
}

#[derive(Serialize, Deserialize)]
struct SetParams {
kv: String,
}

impl Backend {
async fn start_gui(&self) -> Result<()> {
self.state
Expand Down Expand Up @@ -137,6 +142,19 @@ impl Backend {
});
Ok(())
}

async fn set(&self, params: SetParams) -> Result<()> {
let state = self.state.clone();
// TODO: Error handling.
let (k, v) = params.kv.split_once(" ").unwrap();
let (k, v) = (k.to_string(), v.to_string());
tokio::spawn(async move {
if let Some(client) = state.gui_client.lock().await.as_mut() {
client.set(context::current(), k, v).await.unwrap();
}
});
Ok(())
}
}

async fn spawn(fut: impl Future<Output = ()> + Send + 'static) {
Expand Down Expand Up @@ -173,6 +191,7 @@ pub async fn main() {
})
.custom_method("custom/startGui", Backend::start_gui)
.custom_method("custom/openCell", Backend::open_cell)
.custom_method("custom/set", Backend::set)
.finish();
let state = ext_state.unwrap();

Expand Down
1 change: 1 addition & 0 deletions core/lsp-server/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub trait GuiToLsp {
#[tarpc::service]
pub trait LspToGui {
async fn open_cell(file: PathBuf, cell: CompileOutput);
async fn set(key: String, value: String);
}

#[derive(Clone)]
Expand Down
6 changes: 6 additions & 0 deletions plugins/nvim/lua/argon_lsp/commands/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ function M.open_cell(cell)
}, client.print_error)
end

function M.set(kv)
client.buf_request(0, "custom/set", {
kv = kv
}, client.print_error)
end

return M
10 changes: 8 additions & 2 deletions plugins/nvim/lua/argon_lsp/commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
local M = {}

local argon_lsp_cmd_name = 'ArgonLsp'
local gui = require('argon_lsp.commands.gui')

---@class argon_lsp.command_tbl
---@field impl fun(args: string[], opts: vim.api.keyset.user_command) The command implementation
Expand All @@ -14,12 +15,17 @@ local argon_lsp_cmd_name = 'ArgonLsp'
local argon_lsp_command_tbl = {
startGui = {
impl = function(_, opts)
require('argon_lsp.commands.gui').start_gui()
gui.start_gui()
end,
},
openCell = {
impl = function(args, opts)
require('argon_lsp.commands.gui').open_cell(table.concat(args, " "))
gui.open_cell(table.concat(args, " "))
end,
},
set = {
impl = function(args, opts)
gui.set(table.concat(args, " "))
end,
},
}
Expand Down