在 WebStorm 中,有没有办法将语言自动注入特定函数的参数中? [英] In WebStorm, is there a way to automatically inject a language into an argument of a particular function?

查看:29
本文介绍了在 WebStorm 中,有没有办法将语言自动注入特定函数的参数中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码的样子.

/**
 * @param {string} css
 * @param {string} [otherParam]
 */
const addStyle = (css, otherParam) => {
  // Do stuff...
};

addStyle('#element{font-weight:bold;}', 'Some string of text');

以下是我目前知道的实现此目的的手册和理论方法.

Here are the current manual and theoretical ways I know to accomplish this.

这很好用,但我希望它是自动的.

This works great, but I'd like it to be automatic.

第 1 步:

第 2 步:

结果:

这行不通,因为它将 CSS 注入到函数的所有参数中.

This won't work because it injects CSS into all arguments of the function.

让它工作的唯一方法是将每个参数放在这样的单独行上,但我再次希望它是自动的,而无需每次都插入注释行.这是我目前使用的方法.

The only way to get it to work is by putting each argument on a separate line like this, but again I'd like it to be automatic without the need to insert the comment line each time. This is the method I currently use.

我尝试了一段时间来解决这个问题,但我似乎无法弄清楚.

I tried messing around with this for a while, but I can't seem to figure it out.

+ jsLiteralExpression().withSuperParent(2, jsLiteralExpression().withText(string().startsWith("addStyle(")))

推荐答案

Custom Language Injection 规则在这里似乎适用于您的测试代码.在 Windows 10 上使用 PhpStorm 2020.1.2 在纯 JavaScript 文件中进行测试:

Custom Language Injection rule seems to work just fine here for your test code. Tested in a plain JavaScript file using PhpStorm 2020.1.2 on Windows 10:

实际规则:

+ jsArgument(jsReferenceExpression().withQualifiedName("addStyle"), 0)

这篇关于在 WebStorm 中,有没有办法将语言自动注入特定函数的参数中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆