Skip to content

Conversation

@DropDemBits
Copy link
Contributor

Fixes #11638 (including moving the cursor before the generated type parameter)

Adds add_tabstop_{before,after} for inserting tabstop snippets before & after nodes, and add_placeholder_snippet for wrapping nodes inside placeholder nodes.

Currently, the snippets are inserted into the syntax tree in SourceChange::commit so that snippet bits won't interfere with syntax lookups before completing a SourceChange.

It would be preferable if snippet rendering was deferred to after so that rendering can work directly with text ranges, but have left that for a future PR (it would also make it easier to finely specify which text edits have snippets in them).

Another possible snippet variation to support would be a group of placeholders (i.e. placeholders with the same tabstop number) so that a generated item and its uses can be renamed right as it's generated, which is something that is technically supported by the current snippet hack in VSCode, though it's not clear if that's a thing that is officially supported.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 30, 2023
@Veykril
Copy link
Member

Veykril commented Mar 30, 2023

Another possible snippet variation to support would be a group of placeholders (i.e. placeholders with the same tabstop number) so that a generated item and its uses can be renamed right as it's generated, which is something that is technically supported by the current snippet hack in VSCode, though it's not clear if that's a thing that is officially supported.

The spec does say equal tabstops are linked

  /**
   * Client supports snippets as insert text.
   *
   * A snippet can define tab stops and placeholders with `$1`, `$2`
   * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
   * the end of the snippet. Placeholders with equal identifiers are
   * linked, that is typing in one will update others too.
   */
  snippetSupport?: boolean;

So that would be fine to do

@Veykril
Copy link
Member

Veykril commented Apr 5, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Apr 5, 2023

📌 Commit 369f477 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Apr 5, 2023

⌛ Testing commit 369f477 with merge da9c0bd...

@bors
Copy link
Contributor

bors commented Apr 5, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing da9c0bd to master...

@bors bors merged commit da9c0bd into rust-lang:master Apr 5, 2023
@DropDemBits DropDemBits deleted the structured-snippet-api branch April 5, 2023 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add structured editing API to insert snipperts

4 participants