'how to delete auto closed brackets in VSCode extetnsion Completion?

I register [[ as the completion trigger word, VSCode will auto generate ]] for [[,

My completion want to delete the [[]].

For example:

when user type [[,

user may type some filter text,

the final result will be [xxx](/xxx)

I tried additionalTextEdits to delete [[]], but when user type some filter text, the position will be wrong.

item.insertText = `[${title}](/${relativePath})`;

const start = position.character - 2;
item.additionalTextEdits = [
        vscode.TextEdit.delete(
          new vscode.Range(position.line, start, position.line, start + 4)
        ),
];


Solution 1:[1]

Solve this by using command, completion can add a command param, which can do something when completion complete.

vscode.commands.registerCommand(
  'foam-vscode.delete-wiki-link-end-brackets',
  () => {
    const editor = vscode.window.activeTextEditor;
    if (editor) {
      const current = editor.selection.active;
      editor.edit(editBuilder => {
        editBuilder.delete(
          new vscode.Range(
            current.line,
            current.character,
            current.line,
            current.character + 2
          )
        );
      });
      return;
    }
  }
);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Owen Young