Skip to content

Support contextual top-level snippets#4910

Open
crtschin wants to merge 21 commits intohaskell:masterfrom
crtschin:crtschin/snippet-completions
Open

Support contextual top-level snippets#4910
crtschin wants to merge 21 commits intohaskell:masterfrom
crtschin:crtschin/snippet-completions

Conversation

@crtschin
Copy link
Copy Markdown
Collaborator

@crtschin crtschin commented Apr 21, 2026

Closes #4905.

Ended up going a bit in the rabbit hole. This adds top-level snippets and includes a bit better nested behavior in deducing the context of completion.

  • It won't suggest snippets that aren't valid in the current context. So no import snippets if declarations started. No declaration snippets prior any import.
  • The context that's returned is the tightest one around the completion requests' range.
  • I tried to minimize the amount of the AST that's traversed with syb.

@crtschin crtschin force-pushed the crtschin/snippet-completions branch from 06595c6 to 4e904c8 Compare April 23, 2026 20:12
@crtschin
Copy link
Copy Markdown
Collaborator Author

So there's this funny thing, if the context ranges are too tight, then when typing it's possible to fall out of the edge of a range as the contexts won't follow invalid parses.

This causes a lot of the existing tests to fail, as they put the cursor beyond the range of text. To partially get around this, I don't compare columns when determining whether a context range applies to the current range. This gets it to at pass the existing tests, without me having to manually correct the positions at each one.

@crtschin crtschin force-pushed the crtschin/snippet-completions branch 2 times, most recently from d8ba345 to ad5fd35 Compare April 24, 2026 22:52
@crtschin crtschin force-pushed the crtschin/snippet-completions branch from ad5fd35 to d9687d2 Compare April 25, 2026 02:24
@crtschin crtschin force-pushed the crtschin/snippet-completions branch from 9b8705f to e1100c4 Compare April 25, 2026 17:29
@crtschin crtschin changed the title WIP: Support contextual top-level snippets Support contextual top-level snippets Apr 25, 2026
@crtschin crtschin marked this pull request as ready for review April 27, 2026 09:30
@crtschin crtschin requested a review from santiweight as a code owner April 27, 2026 09:30
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.

Top-level completions could be better

1 participant