visual-studio-code - 在 CompletionItem 中设置光标位置
问题描述
我想在 sass-indentation 扩展中添加数字,我想出了如何做到这一点,如果我可以在触发建议时设置光标位置,就像你可以在制作片段时设置光标位置一样与$1
,这可能吗?
import { CompletionItem, CompletionItemKind } from 'vscode';
const sassSchemaTest = [
{
name: '%',
body: '$1%', // I want the cursor location where the '$' sign is
description: 'test'
}
];
export default sassSchemaTest.map(item => {
const completionItem = new CompletionItem(item.name);
completionItem.insertText = item.body;
completionItem.detail = item.description;
completionItem.kind = CompletionItemKind.Property;
return completionItem;
});
解决方案
是的,完成项支持通常的片段语法。只需使用vscode.SnippetString
forinsertText
而不是 raw string
。
选择此完成时应插入到文档中的字符串或片段。使用标签
falsy
时。
completionItem.insertText = new vscode.SnippetString(item.body);
推荐阅读
- excel - 如何创建 ActiveX 控件命令按钮并将其设置为变量 Excel VBA
- bash - 如何在 bash 的源函数中的 scp 命令中正确转义空格形成多个文件
- javascript - 打字稿:使 tsconfig 发出一个文件夹而不是另一个文件夹
- mysql - 使用具有相同类型数据的任一列的MYSQL唯一索引
- android - 显示键盘时未显示 EditText 下面的 textView
- swift - TvOS 焦点引擎跳过单元
- php - 通过 Woocommerce 上的简码有条件地显示自定义库存数量
- c++ - 定义一个 lambda 并捕获它会导致令人困惑的编译器错误
- web - 错误 Laravel 5.6,Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException"
- android - 为什么大多数人在改造中使用拦截器添加身份验证标头?