gpt4 book ai didi

python - VS 代码 : how to make a python snippet that after string or expression hitting tab will transform it

转载 作者:太空宇宙 更新时间:2023-11-04 04:18:30 25 4
gpt4 key购买 nike

是否有可能制作一个 python 片段来转换代码,就像我在示例中解释的那样?

"Hello world".print - 点击 Tab 将其转换为

print("Hello world")

如果自动理解它是字符串还是表达式会很好所以如果我创建一个变量例如“a”并且我在末尾写“.print”并点击选项卡它不会添加“”或''所以在这样它就不会把它转换成别的东西。

a = 10    
a.print - hitting tab

将其转化为:

print(a)

不属于:

print("a")

进步(如果可以这样说的话)

所以

TM_CURRENT_LINE

工作不正常(可能是)。

所以 "${TM_CURRENT_LINE/[0-9a-z.]//g}"它应该删除每个数字、小写字符和 "."从线。这段正则表达式代码(片段)有效但实际上无效。

当我写作时

mytext.py - hit tab/enter

它删除前缀点之间的所有内容

enter image description here

图片中使用的代码片段。

"Print to console - test": {
"scope": "python",
"prefix": ".print",
"body": [
"${TM_CURRENT_LINE/[0-9a-z.]//g}"
],
"description": "Log output to console"
}

我错了还是这位配偶删除了该行中的所有内容?

最佳答案

我认为这不可能完全符合您的需要。比如:

"Print": {
"prefix": ".print",
"body": [
"print(${TM_CURRENT_LINE/(.*)\\..+$/$1/})$0"
],
"description": "Print"
}

如果我写 a.print 并点击 ENTER 这将是输出:

aprint(a)

如果我写“a”.print 这将是输出:

"a"print("a")

然后您应该删除第一部分。这是基于我所知道的,到目前为止,进行一些搜索并没有找到更好的解决方案。

如果你在包含其他语句的行上使用它会出现一些问题,因为它会占用 TM_CURRENT_LINE。参见 Variables .

关于python - VS 代码 : how to make a python snippet that after string or expression hitting tab will transform it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54985908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com