I am developing a vscode extension that requires custom completion for json files. I would like to know if it is possible to hide the trigger character when using autocompletions.
Let me explain further :
Imagine the trigger character is '.' In your json file, you type '.' and it suggests a list of predefined items. When I press tab or enter, the usual behavior would display .item (where item is the selected item upon pressing enter) Is there a way to only show 'item' and remove the trigger character '.'?
This is the snippet of code I have so far:
context.subscriptions.push(languages.registerCompletionItemProvider (
{ language: 'json', scheme: 'file' },
// 'json',
{
provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext) {
let myitem = (text:string) => {
let item = new CompletionItem(text, CompletionItemKind.Text);
item.range = new Range(position, position);
return item;
};
const linePrefix = document.lineAt(position).text.substring(0, position.character);
if (linePrefix.match(/name/g)) {
return [
myitem('log'),
myitem('warn'),
myitem('error'),
];
} else {
return undefined;
}
}
},
'?' // trigger
));