---
source: crates/laburnum-syntax-macro/src/tests/ast_tests.rs
expression: "use laburnum_syntax_macro::tests::ast_tests::test_ast_with_semantic_tokens"
snapshot_kind: text
---
Input: >
  #[laburnum_syntax(AST, allow_semantic)]
  pub struct SemanticNode {
      token: NodeId<crate::Token>,
  }

Output: >
  #[derive(Clone, PartialEq)]
  pub struct SemanticNode {
      /// 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 semantic_token_type: Option<laburnum::protocol::lsp::SemanticTokenType>,
      pub semantic_token_modifier: Option<laburnum::protocol::lsp::SemanticTokenModifier>,
      pub(crate) token: crate::NodeId,
  }
  impl SemanticNode {
      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 semantic_node_field {}
  #[allow(unused)]
  impl SemanticNode {
      ///Returns the `token` field
      pub fn get_token<'ast>(&self, ast: &'ast crate::AST) -> Option<&'ast crate::Token> {
          {
              let token = &self.token;
              ast.node(*token).and_then(|node| crate::Token::from_node(node))
          }
      }
      ///Returns the NodeId for the `token` field
      pub fn get_token_id<'ast>(&self, ast: &'ast crate::AST) -> crate::NodeId {
          {
              let token = &self.token;
              *token
          }
      }
  }
  #[allow(unused)]
  impl<'ast> SemanticNode {
      pub fn validate(&self, ast: &'ast crate::AST) -> crate::Result<()> {
          Ok(())
      }
  }
  #[allow(unused)]
  impl std::fmt::Display for SemanticNode {
      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) }, "SemanticNode"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl std::fmt::Debug for SemanticNode {
      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) }, "SemanticNode"
                  ),
              )
              .finish()
      }
  }
  #[allow(unused)]
  impl bluegum::Bluegum for SemanticNode {
      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)
                  },
                  &"SemanticNode",
              ),
          );
      }
  }
  #[allow(unused)]
  impl<'tokens, 'src> bluegum::BluegumWithState<crate::Printer<'tokens>> for SemanticNode {
      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)
                  },
                  &"SemanticNode",
              ),
          );
          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 token = &self.token;
                  b.add_node_with_state(state, stringify!(token), token);
              };
          };
      }
  }
