Skip to content

Support destination pseudo-scopes #1631

@pokey

Description

@pokey

The problem

Consider the following code

const aaa = 0;

In this case, there is no type. However, we want the following to work:

  • "change type" from within the statement should insert a : after the aaa and leave your cursor after the :
  • "bring bat to type air" should insert a : after the aaa, followed by "bat"

The solution

Query language update

  • In our query language, support @myScopeType.destination

  • Could be used as follows:

    (
      (lexical_declaration
         (variable_declarator
            name: (_) @type.destination.endOf
            !type
         )
      )
      (#leading-insertion-delimiter! @type.destination ": ")
    )

How to handle these queries

The naive approach is to create a stub target that only has a getDestination method and throws on everything else. Unfortunately the problem is that this would break the following:

function aaa(): void {
    const bbb = 0;
}

If you say "copy type bat", you'll get an error, because it will get trapped in the pseudo-scope. Maybe that's fine because it could be confusing to have "copy type bat" and "change type bat" refer to different scopes (the latter is legitimately a destination pseudo-scope that allows adding a type to bbb)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions