Skip to content

feat: VRL Monaco editor intelligence — autocomplete, hover docs, signature help#99

Merged
TerrifiedBug merged 11 commits intomainfrom
feat/vrl-monaco-intelligence
Mar 11, 2026
Merged

feat: VRL Monaco editor intelligence — autocomplete, hover docs, signature help#99
TerrifiedBug merged 11 commits intomainfrom
feat/vrl-monaco-intelligence

Conversation

@TerrifiedBug
Copy link
Owner

Summary

  • Add a unified VRL function registry (src/lib/vrl/function-registry.ts) with 141 functions as the single source of truth for editor intelligence and AI prompt context
  • Add Monarch tokenizer for VRL syntax highlighting — keywords, functions, fields, strings, comments, regex, timestamps all get distinct colors
  • Add function autocomplete with category badges, fallible markers, and parameter snippet insertion
  • Add hover documentation showing function signatures, descriptions, and examples with custom word boundary handling for underscore-separated names
  • Add signature help with parameter hints on ( and ,, supporting nested function calls via parenthesis depth tracking
  • Replace static vrl-reference.ts with buildVrlReferenceFromRegistry() — AI and editor now share the same function data

Test plan

  • Open VRL editor, verify syntax highlighting: keywords blue, functions yellow, fields light blue, strings orange, comments green
  • Type parse — verify autocomplete shows all parse functions with descriptions and category badges
  • Type . — verify field completion still works from source schemas
  • Select a function from autocomplete — verify snippet insertion with parameter placeholders
  • Hover over parse_json — verify signature, description, and example popup
  • Hover over parse_key_value — verify all 3 parameters shown with defaults
  • Type parse_key_value( — verify signature help shows parameter hints
  • Type value and comma — verify active parameter advances
  • Type to_string(parse_json( — verify shows parse_json signature (innermost)
  • Open/close VRL editor multiple times — verify no duplicate providers
  • Open AI panel, ask a VRL question — verify AI still gets function reference context
  • Run VRL code — verify testing still works

@github-actions github-actions bot added dependencies Pull requests that update a dependency file feature labels Mar 11, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR introduces a unified VRL function registry as the single source of truth for both Monaco editor intelligence and AI prompt context, replacing a hand-maintained static string. It adds a Monarch tokenizer, function autocomplete with snippet insertion, hover documentation, and signature help to the VRL Monaco editor.

Key changes:

  • src/lib/vrl/function-registry.ts — 141 typed VrlFunction entries with searchVrlFunctions, getVrlFunction, and buildVrlReferenceFromRegistry exports
  • src/lib/vrl/vrl-language.ts — Monarch tokenizer for VRL keywords, functions, fields, strings, regexes, and timestamps
  • src/components/vrl-editor/vrl-editor.tsx — Three new Monaco provider useEffect hooks (function completion, hover docs, signature help) following the same dispose-on-cleanup pattern as the pre-existing snippet and field providers; language registration moved to beforeMount to avoid a race condition
  • src/lib/ai/prompts.ts — Both AI prompt builders now call buildVrlReferenceFromRegistry() so editor and AI always share the same function data
  • src/lib/ai/vrl-reference.ts / vrl-reference.txt — Deleted; superseded by the registry
  • Two minor style issues noted inline: a dead !afterMatch guard in the hover provider, and signature help that only inspects the current line (multi-line calls won't show hints for arguments on subsequent lines)

Confidence Score: 4/5

  • Safe to merge — changes are purely frontend editor intelligence with no impact on data pipeline, auth, or server-side logic.
  • The implementation is well-structured and follows existing patterns in the codebase. Providers are properly disposed on cleanup, the language registration guard prevents duplicates, and the registry correctly replaces the static reference. The two flagged items are both minor style issues (a dead null-check guard and a known single-line limitation of the signature help provider) that don't affect correctness or safety.
  • No files require special attention.

Important Files Changed

Filename Overview
src/components/vrl-editor/vrl-editor.tsx Adds three new Monaco intelligence providers (function completion, hover docs, signature help) using the same dispose-on-cleanup pattern as the pre-existing snippet/field providers. Two minor style issues: dead !afterMatch guard in the hover provider, and signature help only inspects the current line so multi-line call sites won't show parameter hints.
src/lib/vrl/function-registry.ts New unified registry of 141 VRL functions with typed interfaces. Clean structure with getVrlFunction, searchVrlFunctions, getVrlCategories, and buildVrlReferenceFromRegistry exports. buildVrlReferenceFromRegistry is now called on every AI prompt build (was previously a static constant), but the cost is negligible in the context of LLM calls.
src/lib/vrl/vrl-language.ts New Monarch tokenizer definition for the VRL language. Well-structured with rules for comments, timestamps, raw strings, regex literals, string interpolation, field paths, function identifiers, keywords, numbers, and operators. Minor inherent limitation: the regex literal rule (/…/) may greedily match division operators, but this is a common Monarch trade-off.
src/lib/ai/prompts.ts Swaps static VRL_REFERENCE constant for buildVrlReferenceFromRegistry() call. Both buildVrlSystemPrompt and buildVrlChatSystemPrompt now use the shared registry, ensuring AI context and editor intelligence stay in sync.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Registry["src/lib/vrl/function-registry.ts\n(141 VrlFunction entries)"]

    Registry -->|"getVrlFunction(name)"| Hover["Hover Provider\nprovideHover()"]
    Registry -->|"searchVrlFunctions(prefix)"| Complete["Function Completion Provider\nprovideCompletionItems()"]
    Registry -->|"getVrlFunction(name)"| SigHelp["Signature Help Provider\nprovideSignatureHelp()"]
    Registry -->|"buildVrlReferenceFromRegistry()"| AI["AI Prompts\nbuildVrlSystemPrompt()\nbuildVrlChatSystemPrompt()"]

    LangDef["src/lib/vrl/vrl-language.ts\n(Monarch tokenizer)"] -->|"beforeMount"| Monaco["Monaco Editor\n(language: 'vrl')"]

    Complete --> Monaco
    Hover --> Monaco
    SigHelp --> Monaco

    Fields["VrlFieldsPanel\n(source schema fields)"] -->|"registerCompletionItemProvider('.') "| Monaco
    Snippets["VRL_SNIPPETS"] -->|"registerCompletionItemProvider"| Monaco
Loading

Comments Outside Diff (1)

  1. src/components/vrl-editor/vrl-editor.tsx, line 161 (link)

    Dead !afterMatch guard — always false

    after.match(/^[a-zA-Z0-9_]*/) uses a * (zero-or-more) quantifier, so it always returns an array — never null. That makes !afterMatch permanently false, and this early-return can never fire. The intent (bail out when neither side of the cursor has alphanumeric content) is already caught on line 164 by if (!word || ...), so there's no functional impact — but the condition is misleading.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/components/vrl-editor/vrl-editor.tsx
    Line: 161
    
    Comment:
    **Dead `!afterMatch` guard — always false**
    
    `after.match(/^[a-zA-Z0-9_]*/)` uses a `*` (zero-or-more) quantifier, so it **always** returns an array — never `null`. That makes `!afterMatch` permanently `false`, and this early-return can never fire. The intent (bail out when neither side of the cursor has alphanumeric content) is already caught on line 164 by `if (!word || ...)`, so there's no functional impact — but the condition is misleading.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 599c85b

Comment on lines +218 to +220
// Define theme here too (before mount ensures it's available)
monaco.editor.defineTheme("vrl-theme", vrlTheme);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature help limited to single-line function calls

provideSignatureHelp only inspects the content of the cursor's current line:

const line = model.getLineContent(position.lineNumber);
const textBefore = line.substring(0, position.column - 1);

When a VRL function call spans multiple lines — e.g. the opening ( is on a previous line — textBefore on the argument line will never contain an unclosed (, so funcEnd stays -1 and the provider returns null. Signature hints won't appear for arguments typed on any line after the one containing the opening parenthesis.

For a v1 this is acceptable, but worth noting for a follow-up. A fix would walk backwards through previous lines when no unclosed ( is found on the current line.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/vrl-editor/vrl-editor.tsx
Line: 218-220

Comment:
**Signature help limited to single-line function calls**

`provideSignatureHelp` only inspects the content of the cursor's current line:

```typescript
const line = model.getLineContent(position.lineNumber);
const textBefore = line.substring(0, position.column - 1);
```

When a VRL function call spans multiple lines — e.g. the opening `(` is on a previous line — `textBefore` on the argument line will never contain an unclosed `(`, so `funcEnd` stays `-1` and the provider returns `null`. Signature hints won't appear for arguments typed on any line after the one containing the opening parenthesis.

For a v1 this is acceptable, but worth noting for a follow-up. A fix would walk backwards through previous lines when no unclosed `(` is found on the current line.

How can I resolve this? If you propose a fix, please make it concise.

@TerrifiedBug TerrifiedBug merged commit 0e0a2d7 into main Mar 11, 2026
12 checks passed
@TerrifiedBug TerrifiedBug deleted the feat/vrl-monaco-intelligence branch March 11, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant