This guide explains how to set up and customize syntax highlighting for T-Ruby in various editors.
T-Ruby syntax highlighting provides visual distinction for:
- Keywords:
type,interface,def,end - Types:
String,Integer,Boolean,Array,Hash, etc. - Type Annotations: Parameter and return type declarations
- Type Operators:
|(union),&(intersection),<>(generics) - Comments:
#single-line comments - Strings: Both single and double-quoted
- Numbers: Integers and floats
- Symbols:
:symbol_name
type UserId = String # 'type' keyword, 'UserId' as type name
type Age = Integer # '=' operator, built-in type
type UserMap = Hash<UserId, User> # Generic type
interface Printable # 'interface' keyword, interface name
to_string: String # Member name, type annotation
print: void
end # 'end' keyword
def greet(name: String): String # Function name, param with type, return type
"Hello, #{name}!"
end
def process(items: Array<String>, count: Integer): Hash<String, Integer>
# Generic types are highlighted
end
type StringOrInt = String | Integer # Union type with '|'
type ReadWrite = Readable & Writable # Intersection type with '&'
type MaybeString = String | nil # Nullable type
The VS Code extension automatically provides syntax highlighting. Install it from:
- VS Code Marketplace: Search "T-Ruby"
- Or manually from the
editors/vscodedirectory
Theme Customization:
Add to your settings.json:
{
"editor.tokenColorCustomizations": {
"[Your Theme]": {
"textMateRules": [
{
"scope": "keyword.declaration.type.t-ruby",
"settings": {
"foreground": "#C678DD"
}
},
{
"scope": "entity.name.type.t-ruby",
"settings": {
"foreground": "#E5C07B"
}
},
{
"scope": "support.type.builtin.t-ruby",
"settings": {
"foreground": "#56B6C2"
}
}
]
}
}
}Copy syntax files to your configuration:
# Vim
cp editors/vim/syntax/truby.vim ~/.vim/syntax/
cp editors/vim/ftdetect/truby.vim ~/.vim/ftdetect/
# Neovim
cp editors/vim/syntax/truby.vim ~/.config/nvim/syntax/
cp editors/vim/ftdetect/truby.vim ~/.config/nvim/ftdetect/Color Customization:
Add to your ~/.vimrc or init.vim:
" Custom T-Ruby highlighting colors
augroup truby_colors
autocmd!
autocmd ColorScheme * highlight tRubyKeyword ctermfg=176 guifg=#C678DD
autocmd ColorScheme * highlight tRubyTypeName ctermfg=180 guifg=#E5C07B
autocmd ColorScheme * highlight tRubyBuiltinType ctermfg=73 guifg=#56B6C2
autocmd ColorScheme * highlight tRubyInterface ctermfg=114 guifg=#98C379
augroup ENDFor Neovim with Lua:
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
vim.api.nvim_set_hl(0, "tRubyKeyword", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "tRubyTypeName", { fg = "#E5C07B" })
vim.api.nvim_set_hl(0, "tRubyBuiltinType", { fg = "#56B6C2" })
end,
})| Element | Scope |
|---|---|
type, interface keywords |
keyword.declaration.type.t-ruby |
| Type names | entity.name.type.t-ruby |
| Built-in types | support.type.builtin.t-ruby |
| Function names | entity.name.function.t-ruby |
| Parameters | variable.parameter.t-ruby |
Type operators (|, &) |
keyword.operator.type.t-ruby |
| Generic brackets | punctuation.definition.generic.t-ruby |
| Element | Group |
|---|---|
| Keywords | tRubyKeyword |
| Type names | tRubyTypeName |
| Built-in types | tRubyBuiltinType |
| Interfaces | tRubyInterface |
| Interface members | tRubyInterfaceMember |
| Type annotations | tRubyTypeAnnotation |
| Return types | tRubyReturnType |
| Type operators | tRubyTypeOperator |
# simple.trb - Basic T-Ruby syntax
type UserId = String
type Score = Integer
def get_score(user_id: UserId): Score
100
end
# complex.trb - Advanced T-Ruby syntax
type UserId = String
type Email = String
type Timestamp = Integer
interface Identifiable
id: UserId
end
interface Timestamped
created_at: Timestamp
updated_at: Timestamp
end
interface User
id: UserId
name: String
email: Email
age: Integer | nil
roles: Array<String>
metadata: Hash<String, String>
end
type UserWithTimestamp = User & Timestamped
def create_user(name: String, email: Email): User
# Implementation
end
def find_user(id: UserId): User | nil
# Implementation
end
def get_users_by_role(role: String): Array<User>
# Implementation
end
- Check file extension: Must be
.trbor.d.trb - Verify filetype detection:
- VS Code: Check bottom-right status bar
- Vim: Run
:set filetype?
- Check syntax file is loaded:
- Vim:
:echo exists("g:truby_syntax_loaded")
- Vim:
- Check color scheme compatibility
- Verify highlight group links:
- Vim:
:highlight tRubyKeyword
- Vim:
- Override with custom colors (see above)
- Complex nested types may require syntax reload:
- Vim:
:syntax sync fromstart
- Vim:
- Check for syntax errors that break parsing
The T-Ruby syntax is designed to work well with One Dark and similar themes:
| Element | One Dark Color |
|---|---|
| Keywords | #C678DD (purple) |
| Types | #E5C07B (yellow) |
| Built-in types | #56B6C2 (cyan) |
| Functions | #61AFEF (blue) |
| Strings | #98C379 (green) |
| Element | Dracula Color |
|---|---|
| Keywords | #FF79C6 (pink) |
| Types | #8BE9FD (cyan) |
| Functions | #50FA7B (green) |
| Strings | #F1FA8C (yellow) |
For syntax highlighting issues:
- GitHub Issues: https://github.com/type-ruby/t-ruby/issues
- Include your editor version and theme name when reporting