cursorless-dev / cursorless

Don't let the cursor slow you down
https://www.cursorless.org/
MIT License
1.15k stars 81 forks source link

Handle tagged templates more fluently #641

Open Will-Sommers opened 2 years ago

Will-Sommers commented 2 years ago

Here's an example with the parse:

taggedTemplate`hello ${firstName}`;

> program
>> expression_statement
>>> call_expression
>>>> arguments: template_string
>>>>> template_substitution
>>>>>> identifier
>>>>>> "firstName"

I wonder if the template_string could be referred to as a string, the function identifier as name and then each template_substitution as an argument.

Edit @pokey

We will do the following to handle this issue:

pokey commented 2 years ago

Interesting. A couple thoughts / questions:

Can we not already refer to the template string as string? If not, that strikes me as a bug worth fixing

Using name for the function identifier feels like an abuse of name. name is generally used for the name of something being declared, so I'm not sure this use case is intuitive. I would lean towards using a new scope type called eg "callee", which we'd also use for the function being called in a regular call expression

Interesting idea to have template substitutions be "arguments", though it doesn't feel super intuitive to me. I'd be tempted to just use a new scope type as proposed in https://github.com/cursorless-dev/cursorless/issues/90, tho I do generally advocate for trying to fold scope types together where possible to reduce cognitive load

Will-Sommers commented 2 years ago

Can we not already refer to the template string as string? If not, that strikes me as a bug worth fixing

This is indeed a bug.

Using name for the function identifier feels like an abuse of name.

Agree.

Interesting idea to have template substitutions be "arguments", though it doesn't feel super intuitive to me. I'd be tempted to just use a new scope type as proposed in https://github.com/cursorless-dev/cursorless/issues/90, tho I do generally advocate for trying to fold scope types together where possible to reduce cognitive load

Under the hood, these are arguments for a tagged template. See MDN. There is definitely ambiguity though with regular template literals. Happy to follow your lead on this one.

pokey commented 2 years ago

It's an interesting idea to just use "arg" for any template literal as a solution to this problem as well as #90. wdyt @AndreasArvidsson

AndreasArvidsson commented 2 years ago

Argument sounds good to me

pokey commented 2 years ago

Ok I think we've come to a decision. I've updated the issue description; lmk if that doesn't seem right

Will-Sommers commented 2 years ago

This sounds great to me, thanks!