Full-featured language support for the Rhai scripting language in JetBrains IDEs (IntelliJ IDEA, CLion, RustRover, etc.).
- Full syntax highlighting for Rhai scripts
- Customizable colors via Settings > Editor > Color Scheme > Rhai
- Semantic highlighting for functions, variables, parameters, and more
- Support for all Rhai constructs: functions, variables, strings, numbers, operators, etc.
- Code completion for:
- Keywords with smart insertion (automatic spaces after modifiers)
- 40+ built-in functions with documentation
- Array methods (push, pop, map, filter, reduce, etc.)
- String methods (trim, split, to_upper, etc.)
- User-defined functions and variables
- Cross-file symbols with automatic import generation
- Registered functions from Rust (via registry system)
- Go to definition (Ctrl+Click or Ctrl+B)
- Find usages (Alt+F7)
- Parameter info for function calls
- Documentation on hover for built-in and user-defined symbols
- Rename refactoring (Shift+F6) for:
- Variables and constants
- Functions
- Function parameters
- Closure parameters
- For loop variables
- Smart scope detection (local vs global)
- Automatic update of all usages
- Structure view with filtering (Alt+7)
- Functions (public/private/test indicators)
- Constants
- Variables
- Modules
- Breadcrumb navigation
- Go to Symbol (Ctrl+Alt+Shift+N)
- Line markers for function definitions and usages
- Code folding for functions, blocks, comments, and imports
- Brace matching and auto-closing
- Smart Enter completion
- Comment/uncomment (Ctrl+/)
- Surround with templates (Ctrl+Alt+T):
- if, if-else, while, for, loop
- try-catch, block
- Parentheses
- Live templates for common patterns
- Reformat code (Ctrl+Alt+L)
- Configurable spacing rules for:
- Assignment, logical, equality, relational operators
- Additive and multiplicative operators
- Range and arrow operators
- Commas, colons, semicolons
- Braces, parentheses, brackets
- Closure pipes
- Automatic indentation for blocks
- Alignment of multiline parameters and arguments
- Inspections:
- Unused variable detection
- Unresolved reference detection
- Duplicate function definition detection
- Quick fixes (Alt+Enter):
- Create function - creates a new function stub for unresolved function calls
- Create variable - creates a variable declaration for unresolved references
- Auto-import symbols from other files
- Import and prefix with module name (e.g.,
module::symbol) - Rename to
_name- marks unused variable as intentionally unused - Remove unused declaration - deletes unused variable
- Delete duplicate function - removes duplicate function definition
- Rename duplicate function - renames to
funcName_2
- Spell checking in comments and strings
- Run Rhai scripts directly from the IDE
- Right-click to run any
.rhaifile - Run gutter icon for quick execution
- Configurable interpreter path and arguments
- Auto-detect Rhai registrations from Rust source files
- Support for
register_fn,register_type,register_get/set, and module functions - Separate global and project-specific registries
- Right-click action to manually add registrations from Rust code
- Open Settings/Preferences > Plugins
- Search for "Rhai Language Support"
- Click Install
- Restart the IDE
- Download the plugin
.zipfrom Releases - Open Settings/Preferences > Plugins
- Click the gear icon and select Install Plugin from Disk...
- Select the downloaded
.zipfile - Restart the IDE
Install a Rhai interpreter:
# Install rhai-repl (recommended)
cargo install rhai-repl
# Or use a custom Rust binary with embedded Rhai engine- Right-click on any
.rhaifile in the Project view - Select Run 'filename'
- The script output appears in the Run tool window
To customize the run configuration:
- Go to Run > Edit Configurations...
- Click + and select Rhai Script
- Configure:
- Script: Path to the
.rhaifile - Interpreter: Path to
rhai-replor custom interpreter - Arguments: Script arguments
- Working directory: Execution directory
- Script: Path to the
The plugin automatically detects Rhai function registrations in Rust source files and provides code completion and reference resolution for them.
The plugin parses Rust files for these registration patterns:
// Function registrations
engine.register_fn("my_function", my_rust_fn);
engine.register_fn(CONST_NAME, my_rust_fn); // Constant-based names
// Type registrations
engine.register_type::<MyType>();
engine.register_type_with_name::<MyType>("CustomName");
// Property getters/setters
engine.register_get("prop", getter_fn);
engine.register_set("prop", setter_fn);
engine.register_get_set("prop", getter_fn, setter_fn);
// Module registrations
module.set_fn("function_name", func);
module.set_var("variable_name", value);Configure the registry at Settings > Languages & Frameworks > Rhai Custom Registry:
- Add project-specific functions, variables, and types manually
- These are only available in the current project
- Add functions, variables, and types available in ALL projects
- Useful for common Rhai engine extensions you use everywhere
- Enable/disable automatic Rust file scanning
- Destination setting: Choose where to save auto-detected registrations:
- Project registry - Only available in the current project (default)
- Global registry - Available across all projects
- Configure include/exclude patterns for file scanning
- View statistics of auto-detected registrations
- Click "Rescan Now" to refresh the registry
- Open a Rust file with Rhai registrations
- Right-click on a line with a registration (e.g.,
engine.register_fn(...)) - Select Add to Rhai Registry
- Choose scope: Global (all projects) or Project (current project only)
Type the following abbreviations and press Tab to expand:
| Abbreviation | Expands to |
|---|---|
fn |
Function definition |
pubfn |
Public function definition |
let |
Variable declaration |
const |
Constant declaration |
pubconst |
Public constant declaration |
if |
If statement |
ife |
If-else statement |
for |
For loop |
fori |
For loop with index (0..n) |
forr |
For loop with range |
while |
While loop |
loop |
Infinite loop |
match |
Switch expression |
trye |
Try-catch block |
closure |
Closure expression |
mape |
Map expression |
filtere |
Filter expression |
reducee |
Reduce expression |
guard |
Guard clause (if-return pattern) |
doc |
Documentation comment |
Create new Rhai files with predefined templates:
- Right-click on a folder in Project view
- Select New > Rhai Script
Configure Rhai code style settings: Settings > Editor > Code Style > Rhai
- Spaces around operators (assignment, logical, equality, relational, etc.)
- Spaces around range and arrow operators
- Spaces after/before commas, colons, semicolons
- Spaces within parentheses, brackets, braces
- Spaces within closure pipes
- Space before function/if/loop/switch left brace
- Align multiline parameters and arguments
- Align multiline array elements and object fields
- Keep trailing commas
- Indent size (default: 4)
- Tab size (default: 4)
- Continuation indent size (default: 4)
- Use tabs or spaces
- Blank lines after imports
- Blank lines around functions
- Blank lines around modules
- IntelliJ IDEA 2023.1+ (or compatible JetBrains IDE)
- Java 17+
- For running scripts: Rhai interpreter (
cargo install rhai-repl)
# Clone the repository
git clone https://github.com/GlebMikhailov/rhai-jetbrains-plugin.git
cd rhai-highlight-plugin
# Build the plugin
./gradlew buildPlugin
# The plugin ZIP will be in build/distributions/# Run the IDE with the plugin installed
./gradlew runIde
# Run tests
./gradlew test
# Run linter
./gradlew detekt
# Verify plugin compatibility
./gradlew verifyPluginsrc/
├── main/
│ ├── grammars/ # BNF grammar and JFlex lexer
│ ├── kotlin/org/rhai/
│ │ ├── features/ # Completion, folding, structure view, etc.
│ │ ├── highlighting/ # Syntax highlighter
│ │ ├── inspections/ # Code inspections and quick fixes
│ │ ├── intentions/ # Intention actions
│ │ ├── lang/ # Language and file type definitions
│ │ ├── navigation/ # Go to declaration
│ │ ├── parser/ # Parser definition
│ │ ├── refactoring/ # Rename refactoring
│ │ ├── registry/ # Rust integration registry
│ │ ├── run/ # Run configuration
│ │ ├── settings/ # Settings pages
│ │ └── util/ # Utility classes
│ └── resources/
│ ├── META-INF/ # Plugin descriptor
│ ├── icons/ # Plugin icons
│ └── liveTemplates/ # Live template definitions
└── test/
└── kotlin/org/rhai/ # Unit tests
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run
./gradlew testto ensure tests pass - Run
./gradlew detektto check code style - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Rhai - The embedded scripting language for Rust
- JetBrains Platform SDK - Plugin development documentation