Skip to content

Commit

Permalink
Making a Symbols register with full paths
Browse files Browse the repository at this point in the history
  • Loading branch information
notdanilo committed Oct 25, 2023
1 parent 5b0318b commit 6a6ed3a
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
.idea
.gradle

# Space for testing things
workbench

# Rust files
/target
**/*.rs.bk
Expand Down
4 changes: 3 additions & 1 deletion ligen/ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ pub mod path;
pub mod mutability;
pub mod source;
pub mod project;
pub mod conventions;
pub mod conventions;

pub mod symbols;
46 changes: 46 additions & 0 deletions ligen/ir/src/symbols/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::{Project, Path, Module, interface};

#[derive(Default)]
pub struct Symbols {
pub symbols: Vec<Path>,
}

impl Symbols {
pub fn new(project: &Project) -> Self {
let symbols = Self::from_module(&project.root_module, &Default::default());
Symbols { symbols }
}

fn from_module(module: &Module, path: &Path) -> Vec<Path> {
let path = path.clone().join(module.identifier.clone());
let mut symbols = Vec::default();
module.objects.iter().for_each(|object| {
symbols.push(path.clone().join(object.identifier.clone()));
});
for type_ in module.types.iter() {
symbols.push(path.clone().join(type_.identifier().clone()));
}
for module in module.modules.iter() {
symbols.append(&mut Self::from_module(module, &path));
}
for interface in module.interfaces.iter() {
symbols.extend(Self::from_interface(interface, &path));
}
symbols
}

fn from_interface(interface: &interface::Interface, path: &Path) -> Vec<Path> {
let path = path.clone().join(interface.identifier.clone());
let mut symbols = Vec::default();
interface.objects.iter().for_each(|object| {
symbols.push(path.clone().join(object.identifier.clone()));
});
interface.methods.iter().for_each(|method| {
symbols.push(path.clone().join(method.identifier.clone()));
});
interface.functions.iter().for_each(|function| {
symbols.push(path.clone().join(function.identifier.clone()));
});
symbols
}
}
7 changes: 7 additions & 0 deletions ligen/ir/src/types/type_definition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ pub enum TypeDefinition {
}

impl TypeDefinition {
pub fn identifier(&self) -> &Identifier {
match self {
Self::Structure(structure) => &structure.identifier,
Self::Enumeration(enumeration) => &enumeration.identifier
}
}

pub fn identifier_mut(&mut self) -> &mut Identifier {
match self {
Self::Structure(structure) => &mut structure.identifier,
Expand Down
6 changes: 4 additions & 2 deletions tools/editor/src/gui/ui/layout/editor/symbols/menu_button.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ligen_ir::Project;
use ligen_parsing::parser::Parser;
use ligen_python_parser::module::ModuleParser;
use ligen_python_parser::parser::PythonParser;
Expand All @@ -18,8 +19,9 @@ impl MenuButton for EditorMenuButton {

if let Some(entry) = entry {
stacker::grow(1024 * 1024 * 10, || {
let module = PythonParser::symbol().parse(entry.as_path()).unwrap();
panes.new_pane(Box::new(Editor::new(module)));
let root_module = PythonParser::symbol().parse(entry.as_path()).unwrap();
let project = Project { root_module, ..Default::default() };
panes.new_pane(Box::new(Editor::new(project)));
});
}

Expand Down
22 changes: 16 additions & 6 deletions tools/editor/src/gui/ui/layout/editor/symbols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@ pub mod project;
pub mod menu_button;

use egui_tiles::UiResponse;
use ligen_ir::symbols::Symbols;
use crate::gui::ui::{EditableList, List};
use crate::gui::ui::editor::symbols::project::Project;
use crate::prelude::*;
use crate::gui::ui::panes::Pane;

#[derive(Default)]
pub struct Editor {
module: ligen_ir::Module
project: ligen_ir::Project,
symbols: Symbols,
filter: String
}

impl Editor {
pub fn new(module: ligen_ir::Module) -> Self {
Self { module }
pub fn new(project: ligen_ir::Project) -> Self {
let mut symbols = Symbols::new(&project);
let filter = String::new();
Self { project, symbols, filter }
}
}

impl Pane for Editor {
fn title(&self) -> String {
self.module.identifier.to_string()
self.project.root_module.identifier.to_string()
}

fn show(&mut self, ui: &mut egui::Ui) -> UiResponse {
Project::new().show(ui, &mut self.module);
Project::new().show(ui, &mut self.project.root_module);
ui.text_edit_singleline(&mut self.filter);
List::new("Symbols").show(ui, &mut self.symbols.symbols.iter_mut().filter(|symbol| symbol.to_string().contains(self.filter.as_str())), |ui, symbol| {
ui.label(symbol.to_string());
});
UiResponse::None
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub use crate::prelude::*;

use egui::containers::CollapsingHeader;

// TODO: Implement this with List.

pub struct EditableList {
editable: bool,
name: String,
Expand Down
37 changes: 37 additions & 0 deletions tools/editor/src/gui/ui/utils/list/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
mod editable_list;

pub use editable_list::*;

pub use crate::prelude::*;

use egui::containers::CollapsingHeader;

pub struct List {
name: String,
id_source: String
}

impl List {
pub fn new(name: impl AsRef<str>) -> Self {
let name = name.as_ref().to_string();
let id_source = name.clone();
Self { name, id_source }
}

pub fn show<'a, T: 'a>(&mut self, ui: &mut egui::Ui, list: impl IntoIterator<Item = &'a mut T>, mut show_item: impl FnMut(&mut egui::Ui, &mut T))
where T: Default
{
let list = list.into_iter();
CollapsingHeader::new(&self.name)
.id_source(&self.id_source)
.show(ui, |ui| {
for (index, item) in list.enumerate() {
ui.horizontal_top(|ui| {
ui.push_id(index, |ui| {
show_item(ui, item);
});
});
}
});
}
}
4 changes: 2 additions & 2 deletions tools/editor/src/gui/ui/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod string_editable_field;
mod enum_editable_field;
mod optional_field;
mod editable_list;
mod list;

pub use list::*;
pub use string_editable_field::*;
pub use enum_editable_field::*;
pub use optional_field::*;
pub use editable_list::*;

0 comments on commit 6a6ed3a

Please sign in to comment.