The problem
Consider the following code
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
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)
The problem
Consider the following code
In this case, there is no type. However, we want the following to work:
"change type"from within the statement should insert a:after theaaaand leave your cursor after the:"bring bat to type air"should insert a:after theaaa, followed by "bat"The solution
Query language update
In our query language, support
@myScopeType.destinationCould 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
getDestinationmethod and throws on everything else. Unfortunately the problem is that this would break the following: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 tobbb)