Skip to content

Support completion LSP feature#79

Merged
msujew merged 3 commits into
mainfrom
msujew/completion
May 28, 2026
Merged

Support completion LSP feature#79
msujew merged 3 commits into
mainfrom
msujew/completion

Conversation

@msujew

@msujew msujew commented May 26, 2026

Copy link
Copy Markdown
Member

Adds support for Langium-style code completion - it's a bit more structurally sound compared to Langium:

  1. Since we cannot purely rely on runtime reflection for certain features (such as synthetic AST nodes, if a reference appears as its first feature), this change adds a completion_gen file that helps us with some of the reflection handling. In Langium, we were able to do this inline.
  2. Implements ATN simulation for the completion use case. This is a sounder approach than what we did in Langium, where we had to interpret the current grammar at runtime.
  3. Generates a new completion parser as well. We need to track a lot of ATN intermediate information for the completion. While we theoretically could track this during the normal parse as well, this would slow down the normal parser, which is undesirable.
  4. Based on top of the error recovery work, otherwise most of these features wouldn't work at all (since completion operates on incomplete input).
  5. Adds 2 ways to extend the functionality of the completion provider:
  6. A CompletionContributor works similar to the common override of the CompletionProvider in Langium - specify exactly how a completion item is generated from a specific source token type and ATN state. This also works for cross references and snippets/templates.
  7. A CompletionFilter that allows more fine-grained control over which SymbolDescription elements are returned as part of the cross-reference completion logic. Acts similar to the existing LanguageScopeProvider.

This is quite an extensive change, but it's also extensively tested. Also fixes a bunch of bugs in the error recovery, mostly related to nil handling at EOF.

@msujew
msujew requested a review from spoenemann May 26, 2026 11:07
@msujew
msujew force-pushed the msujew/completion branch 2 times, most recently from 12ea928 to 429b398 Compare May 27, 2026 10:35

@spoenemann spoenemann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Works great!

Comment thread cmd/fastbelt/main.go
@msujew
msujew force-pushed the msujew/completion branch from 600429b to 5ee3f7a Compare May 27, 2026 13:25
@msujew
msujew force-pushed the msujew/completion branch from 5ee3f7a to b256bf8 Compare May 27, 2026 14:35

@spoenemann spoenemann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a great starting point. We can refine it over time where needed.

@msujew
msujew merged commit 29689cc into main May 28, 2026
4 checks passed
@msujew
msujew deleted the msujew/completion branch May 28, 2026 11:07
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.

2 participants