Skip to content

MichalBPL/zed-mql5

Repository files navigation

MQL5 for Zed

Full MQL5 (MetaQuotes Language 5) language support for the Zed code editor — syntax highlighting, native language server, and smart editing features.

Features

Syntax Highlighting

  • Custom tree-sitter grammar extending C++ with MQL5 keywords (input, sinput, datetime, color, uchar, ushort, uint, ulong)
  • 400+ built-in functions highlighted by category (Trading, Indicators, Array, Chart, Object, String, Math, File, etc.)
  • MQL5 constants (PERIOD_H1, OBJ_LABEL, clrRed, etc.), built-in variables (_Symbol, _Point, _Digits), types (MqlTick, ENUM_*), and event handlers (OnInit, OnTick, OnChartEvent)
  • #property and #import directives, SQL injection highlighting in DatabasePrepare() calls

Code Intelligence (mql5-lsp)

  • Autocomplete — context-aware: after . shows class members, after :: shows enum values/static members, general shows all builtins + workspace symbols
  • Go-to-definition — cross-file navigation for functions, classes, enums, variables, macros, and #include paths
  • Find all references (Shift+F12) — scope-aware usage search across the workspace
  • Rename (F2) — scope-aware cross-file rename (prevents renaming builtins)
  • Hover info — type signatures, documentation, field lists for structs
  • Signature help — parameter hints while typing function arguments
  • Diagnostics — unresolved includes, duplicate definitions, undeclared function calls, wrong argument count
  • Color swatches — inline color preview for C'r,g,b' literals, named colors (clrRed, clrBlue, etc.), and 0xRRGGBB hex colors
  • Auto-import#include added automatically when completing symbols from other files
  • Code formattingShift+Alt+F to format MQL5 code
  • Inlay hints — parameter names shown inline at function call sites
  • Semantic highlighting — builtins visually distinct from user-defined symbols
  • Document outline — symbol navigation in sidebar
  • Workspace symbols — fuzzy search across all indexed files
  • Include resolution — handles MQL5 backslash paths (Trade\Trade.mqh), transitive include scanning
  • MQL5 stdlib indexed on startup — scans MQL5/Include/ for standard library symbols

Smart Editing

  • Auto-indentation, code folding, bracket matching
  • Vim text objects (vaf select function, vac select class, vib select in braces)
  • Comment toggling (// and /* */)

Installation

From Zed Extensions (recommended)

  1. Open Zed
  2. Cmd+Shift+P -> "zed: extensions"
  3. Search for "MQL5"
  4. Click Install

Development install

git clone https://github.com/MichalBPL/zed-mql5.git
cd zed-mql5
# In Zed: Cmd+Shift+P -> "zed: install dev extension" -> select this directory

Language Server

The extension uses mql5-language-server, a native MQL5 language server built in Rust with tower-lsp and tree-sitter.

Automatic: The extension downloads the binary automatically on first use.

Manual: Build from source:

git clone https://github.com/MichalBPL/mql5-language-server.git
cd mql5-language-server
cargo build --release

Then configure in Zed settings (Cmd+,):

{
  "lsp": {
    "mql5-lsp": {
      "binary": {
        "path": "/path/to/mql5-language-server/target/release/mql5-lsp"
      }
    }
  }
}

LSP coverage

  • 397+ built-in functions with signatures and documentation
  • 72 enum types with all values
  • 9 struct types with fields (MqlTick, MqlRates, MqlTradeRequest, etc.)
  • 172 named constants
  • 12 predefined global variables
  • 140+ named color constants

Grammar

Custom tree-sitter grammar extending tree-sitter-cpp with:

  • input and sinput as storage_class_specifier nodes
  • datetime, color, string, uchar, ushort, uint, ulong as primitive_type nodes

Project Structure

zed-mql5/
├── extension.toml           # Extension metadata, grammar + LSP config
├── Cargo.toml               # Rust extension build config
├── src/
│   └── mql5.rs              # Extension entry point (LSP launcher)
├── languages/mql5/
│   ├── config.toml          # Language config (brackets, comments, file types)
│   ├── highlights.scm       # Syntax highlighting queries
│   ├── indents.scm          # Auto-indentation rules
│   ├── folds.scm            # Code folding regions
│   ├── textobjects.scm      # Vim text objects
│   ├── outline.scm          # Symbol outline for navigation
│   ├── injections.scm       # SQL injection in DatabasePrepare()
│   └── redactions.scm       # Content redaction
├── stubs/                   # MQL5 header stubs (for clangd users)
└── grammars/mql5/           # Tree-sitter grammar source

Recommended Zed Settings

Add these to your ~/.config/zed/settings.json for the best experience:

{
  "languages": {
    "MQL5": {
      "inlay_hints": {
        "enabled": true,
        "show_parameter_hints": true,
        "show_type_hints": true
      }
    }
  },
  "show_signature_help_after_edits": true,
  "experimental.theme_overrides": {
    "syntax": {
      "function.special": {
        "color": "#eed49f"
      }
    }
  }
}
Setting What it does
inlay_hints.enabled Shows parameter names inline at function call sites
show_signature_help_after_edits Auto-shows function signature when you type (
function.special theme override Gives MQL5 builtin functions (e.g. OrderSend, iRSI) a distinct warm color vs. user-defined functions

Optional: clangd integration

For users who prefer clangd, the stubs/ directory provides C++ header stubs for MQL5 built-in APIs. See clangd-config-template.yaml for configuration. Note that clangd cannot fully parse MQL5 and many diagnostics must be suppressed.

Known Limitations

  • Tree-sitter syntax errors: The grammar is C++-based, so some valid MQL5 constructs (color literals C'r,g,b', type& arr[] reference arrays, dot on pointers) produce parse errors. These are suppressed by the LSP.
  • Type resolution: Dot-completion type resolution uses AST analysis but complex expression chains may not resolve.
  • Scope-aware rename: Works for most cases but cannot distinguish same-named variables in different unrelated scopes.

Contributing

  1. Fork the repository
  2. Make changes
  3. Test with MQL5 code samples (see example.mq5)
  4. Submit a pull request

License

MIT

About

MQL5 language support for Zed editor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors