module CrShader::Docs::C_EDITOR_TOOLING::A_IN_EDITOR_HIGHLIGHTER

Overview

CRShader & Target Syntax Highlighting

CRShader ships a dedicated CrShader::CrShaderSyntaxHighlighter < Godot::EditorSyntaxHighlighter alongside full-palette Godot::CodeHighlighter configurations for both .crshader source files and transpiled .gdshader, .gdshaderinc, and .glsl targets. Every symbol, named argument, punctuation mark, range, and member access receives an explicit high-contrast color so zero tokens ever fall back to black.

Executive Summary & Key Topics

Topic Method / Anchor Description
EditorSyntaxHighlighter & Character-Column Tokenizer .topic_01_highlighter_architecture Extending Godot::EditorSyntaxHighlighter via Lapis C-API span dispatch.
Highlighted Token Categories .topic_02_token_categories Semantic colors across Crystal symbols, named arguments, directives, and GLSL intrinsics.

Related Guides & Source References

Defined in:

docs/c_editor_tooling/a_in_editor_highlighter.cr

Class Method Summary

Class Method Detail

def self.topic_01_highlighter_architecture : Nil #

EditorSyntaxHighlighter & Character-Column Tokenizer: Extending Godot::EditorSyntaxHighlighter via Lapis C-API span dispatch.

In the Godot Editor, CrShader::Highlighter.apply_to_code_edit attaches CrShaderSyntaxHighlighter, which overrides _get_line_syntax_highlighting and streams UTF-32 character-column spans through Godot::Bridge.highlighter_add_span. In standalone runtime viewers where EditorSyntaxHighlighter is unavailable, it automatically falls back to Highlighter.create_code_highlighter with explicit symbol_color, member_variable_color, function_color, and number_color settings.

Working Examples

CrShader::Highlighter.apply_to_code_edit(source_code_edit)
CrShader::Highlighter.apply_target_to_code_edit(preview_code_edit)

def self.topic_02_token_categories : Nil #

Highlighted Token Categories: Semantic colors across Crystal symbols, named arguments, directives, and GLSL intrinsics.

CrShader::Highlighter.highlight_crshader_line distinguishes all Crystal and shader constructs:

  • DSL Directives: emit_target, shader_type, render_mode, feature, when_feature, unless_feature, uniform, varying, flat_varying, buffer, push_constant, require, gd_include.
  • Crystal Symbols & Named Arguments: Full :spatial, :ambient_light_disabled, and :source_color symbols in bright cyan, and default: / range: named-argument keys in sky blue.
  • Preprocessor vs Comments: #include, #define, #ifndef, and #[compute] in coral orange, distinct from # comments.
  • Types, Built-ins & Intrinsics: Float32, Vec3, Color, Sampler2D, ALBEDO, NORMAL, DEPTH, ROUGHNESS, gl_GlobalInvocationID, and GLSL math/texture functions.
  • Punctuation & Ranges: ,, :, .., (, ), =, and ? in cool silver with proper 0..253 range splitting.