laburnum-syntax-macro 0.1.0

Proc-macros for defining CST and AST node types in language frontends built with the laburnum LSP framework.
Documentation
---
source: crates/laburnum-syntax-macro/src/tests/mod.rs
expression: "use laburnum_syntax_macro::tests::test_attributes_preserved"
snapshot_kind: text
---
Input: >
  #[derive(Debug, Clone, PartialEq)]
  #[cfg(feature = "serde")]
  #[laburnum_syntax(AST)]
  pub struct PreserveAttributes {
      #[serde(rename = "customName")]
      field: NodeId<crate::Type>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct PreserveAttributes {
      /// The unique identifier for this node.
      pub(crate) id: crate::NodeId,
      /// The syntax node id that this node is based on.
      pub(crate) syntax: crate::SyntaxId,
      /// Any meta information that is associated with this node.
      pub(crate) meta: Option<crate::NodeId>,
      pub(crate) field: crate::NodeId,
  }
  impl PreserveAttributes {
      pub fn get_id(&self) -> crate::NodeId {
          self.id
      }
      pub fn get_syntax(&self) -> crate::SyntaxId {
          self.syntax
      }
      pub fn get_meta(&self) -> Option<crate::NodeId> {
          self.meta
      }
  }
  pub mod preserve_attributes_field {}
  #[allow(unused)]
  impl PreserveAttributes {
      ///Returns the `field` field
      pub fn get_field<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Type> {
          {
              let field = &self.field;
              ast.node(*field).and_then(|node| crate::Type::from_node(node))
          }
      }
      ///Returns the NodeId for the `field` field
      pub fn get_field_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let field = &self.field;
              *field
          }
      }
  }
  #[allow(unused)]
  impl<'ast> PreserveAttributes {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for PreserveAttributes {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "PreserveAttributes"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for PreserveAttributes {
      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
          f.debug_struct(
                  &format!(
                      "{}::{}", { let __mp = module_path!(); __mp.find("::").map(| i | &
                      __mp[i + 2..]).unwrap_or(__mp) }, "PreserveAttributes"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for PreserveAttributes {
      fn node(&self, b: &mut bluegum::Builder) {
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"PreserveAttributes",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>>
  for PreserveAttributes {
      fn node_with_state(
          &self,
          b: &mut bluegum::Builder,
          state: &crate::Printer<'tokens>,
      ) {
          use owo_colors::OwoColorize;
          use unicode_width::UnicodeWidthStr;
          b.name(
              &crate::style_title(
                  {
                      let __mp = module_path!();
                      __mp.find("::").map(|i| &__mp[i + 2..]).unwrap_or(__mp)
                  },
                  &"PreserveAttributes",
              ),
          );
          if let Some(cst_node) = state.get_syntax(self.syntax) {
              let span = cst_node.span();
              if let Some(span_data) = span.data(state.get_span_cache()) {
                  b.debug(
                      "span",
                      format!("{}..{}", span_data.start, span_data.start + span_data.len),
                  );
              }
          }
          if let Some(meta) = self.meta {
              b.add_node_with_state(state, &"meta".blue().italic().to_string(), &meta);
          }
          {
              {
                  let field = &self.field;
                  b.add_node_with_state(state, stringify!(field), field);
              };
          };
      }
  }