Skip to content

Support contextual top-level snippets#4910

Closed
crtschin wants to merge 20 commits into
haskell:masterfrom
crtschin:crtschin/snippet-completions
Closed

Support contextual top-level snippets#4910
crtschin wants to merge 20 commits into
haskell:masterfrom
crtschin:crtschin/snippet-completions

Conversation

@crtschin

@crtschin crtschin commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

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 4 times, most recently 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
@fendor fendor added the status: needs review This PR is ready for review label Apr 30, 2026
@crtschin crtschin force-pushed the crtschin/snippet-completions branch from ae24477 to 56f6a5e Compare June 9, 2026 21:03
@crtschin

crtschin commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

This PR is a bit much and does multiple things at the same time. If anyone is looking at this, I'm going to split it up so it's easier to review.

@crtschin crtschin marked this pull request as draft June 9, 2026 21:17
@fendor

fendor commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

@crtschin I asked @VeryMilkyJoe to review this PR, please ping them once you've split it up :) Otherwise, they'll look at this PR in the future.

@crtschin

Copy link
Copy Markdown
Collaborator Author

I've split this into #4969, which contains the nested context fixes, and a TBD follow-up that'll add the actual snippets.

Please review that PR instead @VeryMilkyJoe whenever you have some time!

@crtschin crtschin closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs review This PR is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top-level completions could be better

3 participants