首页 > 解决方案 > 在 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;
});

标签: visual-studio-codevscode-extensions

解决方案


是的,完成项支持通常的片段语法。只需使用vscode.SnippetStringforinsertText而不是 raw string

选择此完成时应插入到文档中的字符串或片段。使用标签falsy时。

completionItem.insertText = new vscode.SnippetString(item.body);

推荐阅读