Skip to content

Add railway hover provider - #2235

Open
ssmifi wants to merge 1 commit into
eclipse-langium:mainfrom
ssmifi:ssm/railroad-hover
Open

ssmifi wants to merge 1 commit into
eclipse-langium:mainfrom
ssmifi:ssm/railroad-hover

Conversation

@ssmifi

@ssmifi ssmifi commented Sep 28, 2026

Copy link
Copy Markdown

Suggestion for adding a hover provider that shows railroad diagrams for parser rules in the grammar language, similar to current development inside Fastbelt (TypeFox/fastbelt#152).

  1. Hover provider (packages/langium-railroad/src/railroad-hover-provider.ts)
  • RailroadHoverProvider shows the doc comment, then ---, then the diagram. Terminal rules get no diagram.
  • The diagram is embedded as a base64 data URI of the UTF-8 encoded SVG, so non-ASCII keywords should work.
  • It uses a theme-neutral style (hoverCss) for now.
  • If a diagram can't be built, only the diagram is dropped and the doc comment still shows.
  • Subclasses can override getDiagramMarkdown and getDiagramOptions.
  • Registered in the VS Code extension (packages/langium-vscode/src/language-server/main.ts).
  1. Railroad fixes (packages/langium-railroad/src/grammar-railroad.ts)
  • Fixes a crash: a new toChoice helper never builds an empty choice, which the diagram library throws on. Grammars like {A} | {B} or half-written ones like 'a' | ; now render.
  • Fixes an endless recursion for names that are cross-references themselves (A: name=[A];).
  • Action-only alternatives now draw as an empty path, so 'a' | {B} renders exactly like 'a'?.
  • Incomplete references no longer throw and are drawn as UNKNOWN. Unresolved references keep their text as before.
  • New createRuleDiagramSvg(rule, options), used by createGrammarDiagramSvg. The CLI output is unchanged for valid grammars.
  1. Tests (packages/langium-railroad/test/, new, with tsconfig.test.json added to tsconfig.build.json)
  • 14 tests, 8 for the diagram mapping and 6 for the hover.

From the domain-model.langium:
image

@ssmifi
ssmifi marked this pull request as ready for review September 28, 2026 19:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant